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