3 # Copyright (c) 2010 iXsystems, Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 # Functions which perform the mounting / unmount for upgrades
30 . ${PROGDIR}/backend/functions-unmount.sh
37 zpool import -o altroot=${FSMNT} -a
38 umount_all_dir "${FSMNT}"
40 # Set a variable of files we want to make backups of before doing upgrade
41 BKFILES="/etc/rc.conf /boot/loader.conf"
43 if [ -e "/dev/${MPART}" ] ; then
44 rc_nohalt "mount /dev/${MPART} ${FSMNT}"
45 if [ $? -ne 0 ] ; then
46 # Check if we have ZFS tank name
47 rc_halt "mount -t zfs ${MPART} ${FSMNT}"
50 # Check if we have ZFS tank name
51 rc_halt "mount -t zfs ${MPART} ${FSMNT}"
54 # Mount devfs in chroot
55 mount -t devfs devfs ${FSMNT}/dev
57 # Check if we have any ZFS partitions to mount
60 # Mount all the fstab goodies on disk
61 chroot ${FSMNT} /sbin/mount -a -t nolinprocfs >>${LOGOUT} 2>>${LOGOUT}
62 chroot ${FSMNT} umount /proc >/dev/null 2>/dev/null
63 chroot ${FSMNT} umount /compat/linux/proc >/dev/null 2>/dev/null
65 # Now before we start the upgrade, make sure we set our noschg flags
66 echo_log "Cleaning up old filesystem... Please wait..."
67 rc_halt "chflags -R noschg ${FSMNT}"
69 # Make backup copies of some files
72 cp ${FSMNT}${i} ${FSMNT}${i}.preUpgrade >/dev/null 2>/dev/null
75 # Remove some old dirs
76 rm -rf ${FSMNT}/etc/rc.d >/dev/null 2>/dev/null
78 # If we are doing PC-BSD install, lets cleanup old pkgs on disk
79 if [ "$INSTALLTYPE" != "FreeBSD" ]
81 echo_log "Removing old packages, this may take a while... Please wait..."
83 for i in `pkg_info -aE`
85 echo "Uninstalling package: ${i}"
86 pkg_delete -f ${i} >/dev/null 2>/dev/null
88 ' >${FSMNT}/.cleanPkgs.sh
89 chmod 755 ${FSMNT}/.cleanPkgs.sh
90 chroot ${FSMNT} /.cleanPkgs.sh
91 rm ${FSMNT}/.cleanPkgs.sh
92 run_chroot_cmd "pkg_delete -f \*" >/dev/null 2>/dev/null
93 run_chroot_cmd "rm -rf /usr/PCBSD" >/dev/null 2>/dev/null
94 run_chroot_cmd "rm -rf /PCBSD" >/dev/null 2>/dev/null
95 run_chroot_cmd "rm -rf /var/db/pkgs" >/dev/null 2>/dev/null
96 run_chroot_cmd "rm -rf /usr/local32" >/dev/null 2>/dev/null
97 run_chroot_cmd "rm -rf /usr/sbin" >/dev/null 2>/dev/null
98 run_chroot_cmd "rm -rf /usr/lib" >/dev/null 2>/dev/null
99 run_chroot_cmd "rm -rf /usr/bin" >/dev/null 2>/dev/null
100 run_chroot_cmd "rm -rf /boot/kernel" >/dev/null 2>/dev/null
101 run_chroot_cmd "rm -rf /sbin" >/dev/null 2>/dev/null
102 run_chroot_cmd "rm -rf /bin" >/dev/null 2>/dev/null
103 run_chroot_cmd "rm -rf /lib" >/dev/null 2>/dev/null
104 run_chroot_cmd "rm -rf /libexec" >/dev/null 2>/dev/null
109 # Mount the target upgrade partitions
113 # Make sure we remove the old upgrade-mount script
114 rm -rf ${TMPDIR}/.upgrade-unmount >/dev/null 2>/dev/null
116 # We are ready to start mounting, lets read the config and do it
119 echo $line | grep -q "^disk0=" 2>/dev/null
123 # Found a disk= entry, lets get the disk we are working on
124 get_value_from_string "${line}"
125 strip_white_space "$VAL"
129 echo $line | grep -q "^commitDiskPart" 2>/dev/null
132 # Found our flag to commit this disk setup / lets do sanity check and do it
136 # Start mounting this slice
137 mount_target_slice "${DISK}"
139 # Increment our disk counter to look for next disk and unset
143 exit_err "ERROR: commitDiskPart was called without procceding disk<num>= and partition= entries!!!"
151 copy_skel_files_upgrade()
154 # Now make sure we fix any user profile scripts, which cause problems from 7.x->8.x
161 # Backup the old profile dirs
164 mv /home/${i}/.kde4 /home/${i}/.kde4.preUpgrade >/dev/null 2>/dev/null
165 mv /home/${i}/.kde /home/${i}/.kde.preUpgrade >/dev/null 2>/dev/null
166 mv /home/${i}/.fluxbox /home/${i}/.fluxbox.preUpgrade >/dev/null 2>/dev/null
168 # Copy over the skel directories
169 tar cv --exclude "./dot.*" -f - -C /usr/share/skel . 2>/dev/null | tar xvf - -C /home/${i} 2>/dev/null
171 for j in `ls /usr/share/skel/dot*`
173 dname=`echo ${j} | sed s/dot//`
174 cp /usr/share/skel/${j} /home/${i}/${dname}
177 chown -R ${i}:${i} /home/${i}
181 ' >${FSMNT}/.fixUserProfile.sh
182 chmod 755 ${FSMNT}/.fixUserProfile.sh
183 chroot ${FSMNT} /.fixUserProfile.sh >/dev/null 2>/dev/null
184 rm ${FSMNT}/.fixUserProfile.sh
188 # if the user wants to keep their original .kde4 profile
189 ###########################################################################
190 get_value_from_cfg "upgradeKeepDesktopProfile"
191 if [ "$VAL" = "YES" -o "$VAL" = "yes" ] ; then
196 # Import the old config again
197 if [ -d "${i}/.kde4.preUpgrade" ]
199 # Copy over the skel directories
200 tar cv -f - -C /home/${i}/.kde4.preUpgrade . 2>/dev/null | tar xvf - -C /home/${i}/.kde4 2>/dev/null
201 chown -R ${i}:${i} /home/${i}/.kde4
204 ' >${FSMNT}/.fixUserProfile.sh
205 chmod 755 ${FSMNT}/.fixUserProfile.sh
206 chroot ${FSMNT} /.fixUserProfile.sh >/dev/null 2>/dev/null
207 rm ${FSMNT}/.fixUserProfile.sh
213 # Function which merges some configuration files with the new defaults
217 # Merge the loader.conf with old
218 cp ${FSMNT}/boot/loader.conf ${FSMNT}/boot/loader.conf.new
219 merge_config "${FSMNT}/boot/loader.conf.preUpgrade" "${FSMNT}/boot/loader.conf.new" "${FSMNT}/boot/loader.conf"
220 rm ${FSMNT}/boot/loader.conf.new
222 # Merge the rc.conf with old
223 cp ${FSMNT}/etc/rc.conf ${FSMNT}/etc/rc.conf.new
224 merge_config "${FSMNT}/etc/rc.conf.preUpgrade" "${FSMNT}/etc/rc.conf.new" "${FSMNT}/etc/rc.conf"
225 rm ${FSMNT}/etc/rc.conf.new
229 # Function which unmounts all the mounted file-systems
233 # If on PC-BSD, make sure we copy any fixed skel files
234 if [ "$INSTALLTYPE" != "FreeBSD" ] ; then
235 copy_skel_files_upgrade
241 umount_all_dir "${FSMNT}"
243 # Run our saved unmount script for these file-systems
244 rc_nohalt "umount -f ${FSMNT}"