functions-upgrade.sh revision 209513
1209513Simp#!/bin/sh 2209513Simp#- 3209513Simp# Copyright (c) 2010 iX Systems, Inc. All rights reserved. 4209513Simp# 5209513Simp# Redistribution and use in source and binary forms, with or without 6209513Simp# modification, are permitted provided that the following conditions 7209513Simp# are met: 8209513Simp# 1. Redistributions of source code must retain the above copyright 9209513Simp# notice, this list of conditions and the following disclaimer. 10209513Simp# 2. Redistributions in binary form must reproduce the above copyright 11209513Simp# notice, this list of conditions and the following disclaimer in the 12209513Simp# documentation and/or other materials provided with the distribution. 13209513Simp# 14209513Simp# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15209513Simp# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16209513Simp# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17209513Simp# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18209513Simp# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19209513Simp# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20209513Simp# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21209513Simp# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22209513Simp# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23209513Simp# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24209513Simp# SUCH DAMAGE. 25209513Simp# 26209513Simp# $FreeBSD: head/usr.sbin/pc-sysinstall/backend/functions-upgrade.sh 209513 2010-06-24 22:21:47Z imp $ 27209513Simp 28209513Simp# Functions which perform the mounting / unmount for upgrades 29209513Simp 30209513Simp. ${PROGDIR}/backend/functions-unmount.sh 31209513Simp 32209513Simpmount_target_slice() 33209513Simp{ 34209513Simp MPART="${1}" 35209513Simp 36209513Simp # Import any zpools 37209513Simp zpool import -o altroot=${FSMNT} -a 38209513Simp umount_all_dir "${FSMNT}" 39209513Simp 40209513Simp # Set a variable of files we want to make backups of before doing upgrade 41209513Simp BKFILES="/etc/rc.conf /boot/loader.conf" 42209513Simp 43209513Simp if [ -e "/dev/${MPART}" ] ; then 44209513Simp rc_nohalt "mount /dev/${MPART} ${FSMNT}" 45209513Simp if [ "$?" != "0" ] ; then 46209513Simp # Check if we have ZFS tank name 47209513Simp rc_halt "mount -t zfs ${MPART} ${FSMNT}" 48209513Simp fi 49209513Simp else 50209513Simp # Check if we have ZFS tank name 51209513Simp rc_halt "mount -t zfs ${MPART} ${FSMNT}" 52209513Simp fi 53209513Simp 54209513Simp # Mount devfs in chroot 55209513Simp mount -t devfs devfs ${FSMNT}/dev 56209513Simp 57209513Simp # Check if we have any ZFS partitions to mount 58209513Simp zfs mount -a 59209513Simp 60209513Simp # Mount all the fstab goodies on disk 61209513Simp chroot ${FSMNT} /sbin/mount -a >>${LOGOUT} 2>>${LOGOUT} 62209513Simp chroot ${FSMNT} umount /proc >/dev/null 2>/dev/null 63209513Simp chroot ${FSMNT} umount /compat/linux/proc >/dev/null 2>/dev/null 64209513Simp 65209513Simp # Now before we start the upgrade, make sure we set our noschg flags 66209513Simp echo_log "Cleaning up old filesystem... Please wait..." 67209513Simp rc_halt "chflags -R noschg ${FSMNT}" 68209513Simp 69209513Simp # Make backup copies of some files 70209513Simp for i in ${BKFILES} 71209513Simp do 72209513Simp cp ${FSMNT}${i} ${FSMNT}${i}.preUpgrade >/dev/null 2>/dev/null 73209513Simp done 74209513Simp 75209513Simp # Remove some old dirs 76209513Simp rm -rf ${FSMNT}/etc/rc.d >/dev/null 2>/dev/null 77209513Simp 78209513Simp # If we are doing PC-BSD install, lets cleanup old pkgs on disk 79209513Simp if [ "$INSTALLTYPE" != "FreeBSD" ] 80209513Simp then 81209513Simp echo_log "Removing old packages, this may take a while... Please wait..." 82209513Simp echo '#/bin/sh 83209513Simpfor i in `pkg_info -E \*` 84209513Simpdo 85209513Simp echo "Uninstalling package: ${i}" 86209513Simp pkg_delete -f ${i} >/dev/null 2>/dev/null 87209513Simpdone 88209513Simp' >${FSMNT}/.cleanPkgs.sh 89209513Simp chmod 755 ${FSMNT}/.cleanPkgs.sh 90209513Simp chroot ${FSMNT} /.cleanPkgs.sh 91209513Simp rm ${FSMNT}/.cleanPkgs.sh 92209513Simp run_chroot_cmd "pkg_delete -f \*" >/dev/null 2>/dev/null 93209513Simp run_chroot_cmd "rm -rf /usr/PCBSD" >/dev/null 2>/dev/null 94209513Simp run_chroot_cmd "rm -rf /PCBSD" >/dev/null 2>/dev/null 95209513Simp run_chroot_cmd "rm -rf /var/db/pkgs" >/dev/null 2>/dev/null 96209513Simp run_chroot_cmd "rm -rf /usr/local32" >/dev/null 2>/dev/null 97209513Simp run_chroot_cmd "rm -rf /usr/sbin" >/dev/null 2>/dev/null 98209513Simp run_chroot_cmd "rm -rf /usr/lib" >/dev/null 2>/dev/null 99209513Simp run_chroot_cmd "rm -rf /usr/bin" >/dev/null 2>/dev/null 100209513Simp run_chroot_cmd "rm -rf /boot/kernel" >/dev/null 2>/dev/null 101209513Simp run_chroot_cmd "rm -rf /sbin" >/dev/null 2>/dev/null 102209513Simp run_chroot_cmd "rm -rf /bin" >/dev/null 2>/dev/null 103209513Simp run_chroot_cmd "rm -rf /lib" >/dev/null 2>/dev/null 104209513Simp run_chroot_cmd "rm -rf /libexec" >/dev/null 2>/dev/null 105209513Simp fi 106209513Simp 107209513Simp} 108209513Simp 109209513Simp# Mount the target upgrade partitions 110209513Simpmount_upgrade() 111209513Simp{ 112209513Simp 113209513Simp # Make sure we remove the old upgrade-mount script 114209513Simp rm -rf ${TMPDIR}/.upgrade-unmount >/dev/null 2>/dev/null 115209513Simp 116209513Simp # We are ready to start mounting, lets read the config and do it 117209513Simp while read line 118209513Simp do 119209513Simp echo $line | grep "^disk0=" >/dev/null 2>/dev/null 120209513Simp if [ "$?" = "0" ] 121209513Simp then 122209513Simp 123209513Simp # Found a disk= entry, lets get the disk we are working on 124209513Simp get_value_from_string "${line}" 125209513Simp strip_white_space "$VAL" 126209513Simp DISK="$VAL" 127209513Simp fi 128209513Simp 129209513Simp echo $line | grep "^commitDiskPart" >/dev/null 2>/dev/null 130209513Simp if [ "$?" = "0" ] 131209513Simp then 132209513Simp # Found our flag to commit this disk setup / lets do sanity check and do it 133209513Simp if [ ! -z "${DISK}" ] 134209513Simp then 135209513Simp 136209513Simp # Start mounting this slice 137209513Simp mount_target_slice "${DISK}" 138209513Simp 139209513Simp # Increment our disk counter to look for next disk and unset 140209513Simp unset DISK 141209513Simp break 142209513Simp else 143209513Simp exit_err "ERROR: commitDiskPart was called without procceding disk<num>= and partition= entries!!!" 144209513Simp fi 145209513Simp fi 146209513Simp 147209513Simp done <${CFGF} 148209513Simp 149209513Simp}; 150209513Simp 151209513Simpcopy_skel_files_upgrade() 152209513Simp{ 153209513Simp 154209513Simp # Now make sure we fix any user profile scripts, which cause problems from 7.x->8.x 155209513Simp echo '#!/bin/sh 156209513Simp 157209513Simpcd /home 158209513Simpfor i in `ls` 159209513Simpdo 160209513Simp 161209513Simp # Backup the old profile dirs 162209513Simp if [ -d "${i}" ] 163209513Simp then 164209513Simp mv /home/${i}/.kde4 /home/${i}/.kde4.preUpgrade >/dev/null 2>/dev/null 165209513Simp mv /home/${i}/.kde /home/${i}/.kde.preUpgrade >/dev/null 2>/dev/null 166209513Simp mv /home/${i}/.fluxbox /home/${i}/.fluxbox.preUpgrade >/dev/null 2>/dev/null 167209513Simp 168209513Simp # Copy over the skel directories 169209513Simp tar cv --exclude "./dot.*" -f - -C /usr/share/skel . 2>/dev/null | tar xvf - -C /home/${i} 2>/dev/null 170209513Simp 171209513Simp for j in `ls /usr/share/skel/dot*` 172209513Simp do 173209513Simp dname=`echo ${j} | sed s/dot//` 174209513Simp cp /usr/share/skel/${j} /home/${i}/${dname} 175209513Simp done 176209513Simp 177209513Simp chown -R ${i}:${i} /home/${i} 178209513Simp fi 179209513Simp 180209513Simpdone 181209513Simp' >${FSMNT}/.fixUserProfile.sh 182209513Simp chmod 755 ${FSMNT}/.fixUserProfile.sh 183209513Simp chroot ${FSMNT} /.fixUserProfile.sh >/dev/null 2>/dev/null 184209513Simp rm ${FSMNT}/.fixUserProfile.sh 185209513Simp 186209513Simp 187209513Simp 188209513Simp # if the user wants to keep their original .kde4 profile 189209513Simp ########################################################################### 190209513Simp get_value_from_cfg "upgradeKeepDesktopProfile" 191209513Simp if [ "$VAL" = "YES" -o "$VAL" = "yes" ] ; then 192209513Simp echo '#!/bin/sh 193209513Simp cd /home 194209513Simpfor i in `ls` 195209513Simpdo 196209513Simp # Import the old config again 197209513Simp if [ -d "${i}/.kde4.preUpgrade" ] 198209513Simp then 199209513Simp # Copy over the skel directories 200209513Simp tar cv -f - -C /home/${i}/.kde4.preUpgrade . 2>/dev/null | tar xvf - -C /home/${i}/.kde4 2>/dev/null 201209513Simp chown -R ${i}:${i} /home/${i}/.kde4 202209513Simp fi 203209513Simpdone 204209513Simp' >${FSMNT}/.fixUserProfile.sh 205209513Simp chmod 755 ${FSMNT}/.fixUserProfile.sh 206209513Simp chroot ${FSMNT} /.fixUserProfile.sh >/dev/null 2>/dev/null 207209513Simp rm ${FSMNT}/.fixUserProfile.sh 208209513Simp 209209513Simp fi 210209513Simp 211209513Simp}; 212209513Simp 213209513Simp# Function which merges some configuration files with the new defaults 214209513Simpmerge_old_configs() 215209513Simp{ 216209513Simp 217209513Simp # Merge the loader.conf with old 218209513Simp cp ${FSMNT}/boot/loader.conf ${FSMNT}/boot/loader.conf.new 219209513Simp merge_config "${FSMNT}/boot/loader.conf.preUpgrade" "${FSMNT}/boot/loader.conf.new" "${FSMNT}/boot/loader.conf" 220209513Simp rm ${FSMNT}/boot/loader.conf.new 221209513Simp 222209513Simp # Merge the rc.conf with old 223209513Simp cp ${FSMNT}/etc/rc.conf ${FSMNT}/etc/rc.conf.new 224209513Simp merge_config "${FSMNT}/etc/rc.conf.preUpgrade" "${FSMNT}/etc/rc.conf.new" "${FSMNT}/etc/rc.conf" 225209513Simp rm ${FSMNT}/etc/rc.conf.new 226209513Simp 227209513Simp}; 228209513Simp 229209513Simp# Function which unmounts all the mounted file-systems 230209513Simpunmount_upgrade() 231209513Simp{ 232209513Simp 233209513Simp # If on PC-BSD, make sure we copy any fixed skel files 234209513Simp if [ "$INSTALLTYPE" != "FreeBSD" ] ; then 235209513Simp copy_skel_files_upgrade 236209513Simp fi 237209513Simp 238209513Simp cd / 239209513Simp 240209513Simp # Unmount FS 241209513Simp umount_all_dir "${FSMNT}" 242209513Simp 243209513Simp # Run our saved unmount script for these file-systems 244209513Simp rc_nohalt "umount -f ${FSMNT}" 245209513Simp 246209513Simp umount ${CDMNT} 247209513Simp}; 248