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