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