Home | History | Annotate | Line # | Download | only in upgr
upgrade.sh revision 1.2.6.2
      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.2 1996/07/22 13:42:57 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	"If you've still installed 0.9 or earlier on your machine or you"
    166 echo	"haven't upgraded your pre-1.0 filesystems, then you might want to"
    167 echo	"upgrade the filesystem to the version introduced with 1.0."
    168 echo	""
    169 echo	"Would you like to upgrade your file systems to the new file system"
    170 echo -n	"format? [y] "
    171 getresp "y"
    172 case "$resp" in
    173 	n*|N*)
    174 		echo	""
    175 		echo	"You should upgrade your file systems with 'fsck -c 2'"
    176 		echo	"as soon as is feasible, because the new file system"
    177 		echo	"code is better-tested and more performant."
    178 		upgradefs=NO
    179 		;;
    180 	*)
    181 		upgradefs=YES
    182 		;;
    183 esac
    184 
    185 if [ $upgradefs = YES ]; then
    186 	echo	""
    187 	echo	"Upgrading the file system on ${drivename}a..."
    188 	
    189 	$DONTDOIT fsck -p -c 2 /dev/r${drivename}a
    190 	if [ $? != 0 ]; then
    191 		echo	"FATAL ERROR: FILE SYSTEM UPGRADE FAILED."
    192 		echo	"You should probably reboot the machine, fsck your"
    193 		echo	"disk(s), and try the upgrade procedure again."
    194 		exit 1
    195 	fi
    196 	echo	"Done."
    197 fi
    198 
    199 echo	""
    200 echo	"Mounting root partition on /mnt..."
    201 $DONTDOIT mount /dev/${drivename}a /mnt
    202 if [ $? != 0 ]; then
    203 	echo	"FATAL ERROR: MOUNT FAILED."
    204 	echo	"You should verify that your system is set up as you"
    205 	echo	"described, and re-attempt the upgrade procedure."
    206 	exit 1
    207 fi
    208 echo	"Done."
    209 
    210 #<<<<<<<<<<<<<<<<<<<<<<<< update etc/fstab to ffs? >>>>>>>>>>>>>>>>>>>>>>>>
    211 echo	""
    212 echo -n	"Converting ufs entries in fstab to ffs..."
    213 $DONTDOIT Convert_fstab
    214 echo	"Done."
    215 
    216 if [ $upgradefs = YES ]; then
    217 	echo	""
    218 	echo -n	"Copying new fsck binary to your hard disk..."
    219 	if [ ! -d /mnt/sbin ]; then
    220 		$DONTDOIT mkdir /mnt/sbin
    221 	fi
    222 	$DONTDOIT cp /sbin/fsck /mnt/sbin/fsck
    223 	if [ $? != 0 ]; then
    224 		echo	"FATAL ERROR: COPY FAILED."
    225 		echo	"It in unclear why this error would occur.  It looks"
    226 		echo	"like you may end up having to upgrade by hand."
    227 		exit 1
    228 	fi
    229 	$DONTDOIT sync
    230 	echo	" Done."
    231 
    232 	echo	""
    233 	echo    "Re-mounting root partition read-only..."
    234 	$DONTDOIT mount -u -o ro /dev/${drivename}a /mnt
    235 	if [ $? != 0 ]; then
    236 		echo	"FATAL ERROR: RE-MOUNT FAILED."
    237 		echo	"It in unclear why this error would occur.  It looks"
    238 		echo	"like you may end up having to upgrade by hand."
    239 		exit 1
    240 	fi
    241 	echo	"Done."
    242 
    243 	echo	""
    244 	echo	"Upgrading the rest of your file systems..."
    245 	$DONTDOIT chroot /mnt fsck -p -c 2
    246 	if [ $? != 0 ]; then
    247 		echo	"FATAL ERROR: FILE SYSTEM UPGRADE(S) FAILED."
    248 		echo	"You should probably reboot the machine, fsck your"
    249 		echo	"file system(s), and try the upgrade procedure"
    250 		echo	"again."
    251 		exit 1
    252 	fi
    253 	echo	"Done."
    254 
    255 	echo	""
    256 	echo    "Re-mounting root partition read-write..."
    257 	$DONTDOIT mount -u -o rw /dev/${drivename}a /mnt
    258 	if [ $? != 0 ]; then
    259 		echo	"FATAL ERROR: RE-MOUNT FAILED."
    260 		echo	"It in unclear why this error would occur.  It looks"
    261 		echo	"like you may end up having to upgrade by hand."
    262 		exit 1
    263 	fi
    264 	echo	"Done."
    265 fi
    266 
    267 echo	""
    268 echo	"Copying bootstrapping binaries and config files to the hard drive..."
    269 $DONTDOIT tar -cf - sbin/mount_ffs | (cd /mnt ; tar --unlink -xpf - )
    270 
    271 echo	""
    272 echo	"Mounting remaining partitions..."
    273 $DONTDOIT chroot /mnt mount -at ffs > /dev/null 2>&1
    274 echo	"Done."
    275 
    276 echo    ""
    277 echo    ""
    278 echo	"OK!  The preliminary work of setting up your disk is now complete,"
    279 echo	"and you can now upgrade the actual NetBSD software."
    280 echo	""
    281 echo	"Right now, your hard disk is mounted on /mnt.  You should consult"
    282 echo	"the installation notes to determine how to load and install the new"
    283 echo	"NetBSD distribution sets, and how to clean up after the upgrade"
    284 echo	"software, when you are done."
    285 echo	""
    286 echo	"GOOD LUCK!"
    287 echo	""
    288