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