Home | History | Annotate | Line # | Download | only in upgr
upgrade.sh revision 1.2.6.1
      1 #!/bin/sh
      2 #
      3 # Copyright (c) 1994 Christopher G. Demetriou
      4 # All rights reserved.
      5 #
      6 # Redistribution and use in source and binary forms, with or without
      7 # modification, are permitted provided that the following conditions
      8 # are met:
      9 # 1. Redistributions of source code must retain the above copyright
     10 #    notice, this list of conditions and the following disclaimer.
     11 # 2. Redistributions in binary form must reproduce the above copyright
     12 #    notice, this list of conditions and the following disclaimer in the
     13 #    documentation and/or other materials provided with the distribution.
     14 # 3. All advertising materials mentioning features or use of this software
     15 #    must display the following acknowledgement:
     16 #	This product includes software developed by Christopher G. Demetriou.
     17 # 4. The name of the author may not be used to endorse or promote products
     18 #    derived from this software without specific prior written permission
     19 #
     20 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30 #
     31 #	$Id: upgrade.sh,v 1.2.6.1 1996/07/14 19:44:09 is Exp $
     32 
     33 #	NetBSD upgrade script.
     34 #	In a perfect world, this would be a nice C program, with a reasonable
     35 #	user interface.
     36 
     37 #DONTDOIT=echo
     38 
     39 VERSION=1.2
     40 
     41 getresp() {
     42 	read resp
     43 	if [ "X$resp" = "X" ]; then
     44 		resp=$1
     45 	fi
     46 }
     47 
     48 getvar() {
     49 	echo $(eval $(echo "echo \$$1"))
     50 }
     51 
     52 shiftvar() {
     53 	local - var
     54 	var="$1"
     55 	list="$(getvar $var)"
     56 	set -- $list
     57 	shift
     58 	setvar $var "$*"
     59 }
     60 
     61 getparts() {
     62 	disklabel $1 2>/dev/null | sed -e '/^[ ][ ][ad-p]/!d' |
     63 	sed -e 's,^[ ]*\([a-p]\):[ ]*[0-9]*[ ]*[0-9]*[ ][ ]*\([a-zA-Z0-9.]*\).*,\1 \2,' |
     64 	sed -e ':a
     65 		N;${s/\n/ /g;p;d;}
     66 		ba'
     67 }
     68 
     69 getdrives() {
     70 	local du thispart
     71 	for du in /dev/rsd?a; do
     72 		dd if=$du of=/dev/null bs=1b count=1 >/dev/null 2>&1
     73 		if [ $? -eq 0 ]; then
     74 			thisunit=`echo $du | sed -e 's,/dev/r\(...\)a,\1,g'`
     75 			driveunits="$driveunits $thisunit"
     76 		else
     77 			continue;
     78 		fi
     79 		setvar $thisunit "$(getparts $thisunit)"
     80 		export $thisunit
     81 	done
     82 	export drivenunits
     83 }
     84 
     85 Convert_fstab() {
     86 	if [ ! -e /mnt/etc/fstab.ufs ]; then
     87 		mv /mnt/etc/fstab /mnt/etc/fstab.ufs
     88 	fi
     89 	sed "s/ufs/ffs/" /mnt/etc/fstab.ufs >/mnt/etc/fstab
     90 }
     91 
     92 echo	"Welcome to the NetBSD ${VERSION} upgrade program."
     93 echo	""
     94 echo	"This program is designed to help you put the new version of NetBSD"
     95 echo	"on your hard disk, in a simple and rational way.  To upgrade, you"
     96 echo	"must have plenty of free space on all partitions which will be"
     97 echo	"upgraded.  If you have at least 1MB free on your root partition,"
     98 echo	"and several free on your /usr patition, you should be fine."
     99 echo	""
    100 echo	"As with anything which modifies your hard drive's contents, this"
    101 echo	"program can cause SIGNIFICANT data loss, and you are advised"
    102 echo	"to make sure your hard drive is backed up before beginning the"
    103 echo	"upgrade process."
    104 echo	""
    105 echo	"Default answers are displayed in brackets after the questions."
    106 echo	"You can hit Control-C at any time to quit, but if you do so at a"
    107 echo	"prompt, you may have to hit return.  Also, quitting in the middle of"
    108 echo	"the upgrade may leave your system in an inconsistent (and unusable)"
    109 echo	"state."
    110 echo	""
    111 echo -n "Proceed with upgrade? [n] "
    112 getresp "n"
    113 case "$resp" in
    114 	y*|Y*)
    115 		echo	"Cool!  Let's get to it..."
    116 		;;
    117 	*)
    118 		echo	""
    119 		echo	"OK, then.  Enter 'halt' at the prompt to halt the"
    120 		echo	"machine.  Once the machine has halted, remove the"
    121 		echo	"floppy and press any key to reboot."
    122 		exit
    123 		;;
    124 esac
    125 
    126 # find out what units are possible, and query the user.
    127 
    128 getdrives
    129 
    130 if [ "X${driveunits}" = "X" ]; then
    131 	echo	"FATAL ERROR:"
    132 	echo	"No disk devices."
    133 	echo	"This is probably a bug in the install disks."
    134 	echo	"Exiting install program."
    135 	exit
    136 fi
    137 
    138 echo	""
    139 echo	"The following disks are supported by this upgrade procedure:"
    140 echo	"	"${driveunits}
    141 echo	""
    142 echo	"If your system was previously completely contained within the"
    143 echo	"disks listed above (i.e. if your system didn't occupy any space"
    144 echo	"on disks NOT listed above), this upgrade disk can upgrade your"
    145 echo	"system.  If it cannot, hit Control-C at the prompt."
    146 echo	""
    147 while [ "X${drivename}" = "X" ]; do
    148 	echo -n	"Which disk contains your root partion? "
    149 	getresp
    150 	otherdrives=`echo "${driveunits}" | sed -e s,${resp},,`
    151 	if [ "X${driveunits}" = "X${otherdrives}" ]; then
    152 		echo	""
    153 		echo	"\"${resp}\" is an invalid drive name.  Valid choices"
    154 		echo	"are: "${driveunits}
    155 		echo	""
    156 	else
    157 		drivename=${resp}
    158 	fi
    159 done
    160 
    161 echo	""
    162 echo	"Root partition is on ${drivename}a."
    163 
    164 echo	""
    165 echo	"Would you like to upgrade your file systems to the new file system"
    166 echo -n	"format? [y] "
    167 getresp "y"
    168 case "$resp" in
    169 	n*|N*)
    170 		echo	""
    171 		echo	"You should upgrade your file systems with 'fsck -c 2'"
    172 		echo	"as soon as is feasible, because the new file system"
    173 		echo	"code is better-tested and more performant."
    174 		upgradefs=NO
    175 		;;
    176 	*)
    177 		upgradefs=YES
    178 		;;
    179 esac
    180 
    181 if [ $upgradefs = YES ]; then
    182 	echo	""
    183 	echo	"Upgrading the file system on ${drivename}a..."
    184 	
    185 	$DONTDOIT fsck -p -c 2 /dev/r${drivename}a
    186 	if [ $? != 0 ]; then
    187 		echo	"FATAL ERROR: FILE SYSTEM UPGRADE FAILED."
    188 		echo	"You should probably reboot the machine, fsck your"
    189 		echo	"disk(s), and try the upgrade procedure again."
    190 		exit 1
    191 	fi
    192 	echo	"Done."
    193 fi
    194 
    195 echo	""
    196 echo	"Mounting root partition on /mnt..."
    197 $DONTDOIT mount /dev/${drivename}a /mnt
    198 if [ $? != 0 ]; then
    199 	echo	"FATAL ERROR: MOUNT FAILED."
    200 	echo	"You should verify that your system is set up as you"
    201 	echo	"described, and re-attempt the upgrade procedure."
    202 	exit 1
    203 fi
    204 echo	"Done."
    205 
    206 #<<<<<<<<<<<<<<<<<<<<<<<< update etc/fstab to ffs? >>>>>>>>>>>>>>>>>>>>>>>>
    207 echo	""
    208 echo -n	"Converting ufs entries in fstab to ffs..."
    209 $DONTDOIT Convert_fstab
    210 echo	"Done."
    211 
    212 if [ $upgradefs = YES ]; then
    213 	echo	""
    214 	echo -n	"Copying new fsck binary to your hard disk..."
    215 	if [ ! -d /mnt/sbin ]; then
    216 		$DONTDOIT mkdir /mnt/sbin
    217 	fi
    218 	$DONTDOIT cp /sbin/fsck /mnt/sbin/fsck
    219 	if [ $? != 0 ]; then
    220 		echo	"FATAL ERROR: COPY FAILED."
    221 		echo	"It in unclear why this error would occur.  It looks"
    222 		echo	"like you may end up having to upgrade by hand."
    223 		exit 1
    224 	fi
    225 	$DONTDOIT sync
    226 	echo	" Done."
    227 
    228 	echo	""
    229 	echo    "Re-mounting root partition read-only..."
    230 	$DONTDOIT mount -u -o ro /dev/${drivename}a /mnt
    231 	if [ $? != 0 ]; then
    232 		echo	"FATAL ERROR: RE-MOUNT FAILED."
    233 		echo	"It in unclear why this error would occur.  It looks"
    234 		echo	"like you may end up having to upgrade by hand."
    235 		exit 1
    236 	fi
    237 	echo	"Done."
    238 
    239 	echo	""
    240 	echo	"Upgrading the rest of your file systems..."
    241 	$DONTDOIT chroot /mnt fsck -p -c 2
    242 	if [ $? != 0 ]; then
    243 		echo	"FATAL ERROR: FILE SYSTEM UPGRADE(S) FAILED."
    244 		echo	"You should probably reboot the machine, fsck your"
    245 		echo	"file system(s), and try the upgrade procedure"
    246 		echo	"again."
    247 		exit 1
    248 	fi
    249 	echo	"Done."
    250 
    251 	echo	""
    252 	echo    "Re-mounting root partition read-write..."
    253 	$DONTDOIT mount -u -o rw /dev/${drivename}a /mnt
    254 	if [ $? != 0 ]; then
    255 		echo	"FATAL ERROR: RE-MOUNT FAILED."
    256 		echo	"It in unclear why this error would occur.  It looks"
    257 		echo	"like you may end up having to upgrade by hand."
    258 		exit 1
    259 	fi
    260 	echo	"Done."
    261 fi
    262 
    263 echo	""
    264 echo	"Copying bootstrapping binaries and config files to the hard drive..."
    265 $DONTDOIT tar -cf - sbin/mount_ffs | (cd /mnt ; tar --unlink -xpf - )
    266 
    267 echo	""
    268 echo	"Mounting remaining partitions..."
    269 $DONTDOIT chroot /mnt mount -at ffs > /dev/null 2>&1
    270 echo	"Done."
    271 
    272 echo    ""
    273 echo    ""
    274 echo	"OK!  The preliminary work of setting up your disk is now complete,"
    275 echo	"and you can now upgrade the actual NetBSD software."
    276 echo	""
    277 echo	"Right now, your hard disk is mounted on /mnt.  You should consult"
    278 echo	"the installation notes to determine how to load and install the new"
    279 echo	"NetBSD distribution sets, and how to clean up after the upgrade"
    280 echo	"software, when you are done."
    281 echo	""
    282 echo	"GOOD LUCK!"
    283 echo	""
    284