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