Home | History | Annotate | Line # | Download | only in miniroot
upgrade.sh revision 1.1
      1 #!/bin/sh
      2 #	$NetBSD: upgrade.sh,v 1.1 1996/01/06 22:45:15 pk Exp $
      3 #
      4 # Copyright (c) 1995 Jason R. Thorpe.
      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 NetBSD Project
     18 #	by Jason R. Thorpe.
     19 # 4. The name of the author may not be used to endorse or promote products
     20 #    derived from this software without specific prior written permission
     21 #
     22 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32 #
     33 
     34 #	NetBSD installation script.
     35 #	In a perfect world, this would be a nice C program, with a reasonable
     36 #	user interface.
     37 
     38 VERSION=1.1
     39 export VERSION				# XXX needed in subshell
     40 ROOTDISK=""				# filled in below
     41 
     42 trap "umount /tmp > /dev/null 2>&1" 0
     43 
     44 MODE="upgrade"
     45 
     46 # include machine-dependent functions
     47 # The following functions must be provided:
     48 #	md_get_diskdevs()	- return available disk devices
     49 #	md_get_cddevs()		- return available CD-ROM devices
     50 #	md_get_ifdevs()		- return available network interfaces
     51 #	md_installboot()	- install boot-blocks on disk
     52 #	md_checkfordisklabel()	- check for valid disklabel
     53 #	md_labeldisk()		- put label on a disk
     54 #	md_welcome_banner()	- display friendly message
     55 #	md_not_going_to_install() - display friendly message
     56 #	md_congrats()		- display friendly message
     57 . install.md
     58 
     59 # include common subroutines
     60 . install.sub
     61 
     62 # Good {morning,afternoon,evening,night}.
     63 md_welcome_banner
     64 echo -n "Proceed with upgrade? [n] "
     65 getresp "n"
     66 case "$resp" in
     67 	y*|Y*)
     68 		echo	"Cool!  Let's get to it..."
     69 		;;
     70 	*)
     71 		md_not_going_to_install
     72 		exit
     73 		;;
     74 esac
     75 
     76 # Deal with terminal issues
     77 md_set_term
     78 
     79 # XXX Work around vnode aliasing bug (thanks for the tip, Chris...)
     80 ls -l /dev > /dev/null 2>&1
     81 
     82 # We don't like it, but it sure makes a few things a lot easier.
     83 do_mfs_mount "/tmp" "2048"
     84 
     85 while [ "X${ROOTDISK}" = "X" ]; do
     86 	getrootdisk
     87 done
     88 
     89 # Make sure there's a disklabel there.  If there isn't, puke after
     90 # disklabel prints the error message.
     91 md_checkfordisklabel ${ROOTDISK}
     92 case $rval in
     93 	1)
     94 		cat << \__disklabel_not_present_1
     95 
     96 FATAL ERROR: There is no disklabel present on the root disk!  You must
     97 label the disk with SYS_INST before continuing.
     98 
     99 __disklabel_not_present_1
    100 		exit
    101 		;;
    102 
    103 	2)
    104 		cat << \__disklabel_corrupted_1
    105 
    106 FATAL ERROR: The disklabel on the root disk is corrupted!  You must
    107 re-label the disk with SYS_INST before continuing.
    108 
    109 __disklabel_corrupted_1
    110 		exit
    111 		;;
    112 
    113 	*)
    114 		;;
    115 esac
    116 
    117 # Assume partition 'a' of $ROOTDISK is for the root filesystem.  Confirm
    118 # this with the user.  Check and mount the root filesystem.
    119 resp=""			# force one iteration
    120 while [ "X${resp}" = "X" ]; do
    121 	echo -n	"Root filesystem? [${ROOTDISK}a] "
    122 	getresp "${ROOTDISK}a"
    123 	_root_filesystem="/dev/`basename $resp`"
    124 	if [ ! -b ${_root_filesystem} ]; then
    125 		echo "Sorry, ${resp} is not a block device."
    126 		resp=""	# force loop to repeat
    127 	fi
    128 done
    129 
    130 echo	"Checking root filesystem..."
    131 if ! fsck -pf ${_root_filesystem}; then
    132 	echo	"ERROR: can't check root filesystem!"
    133 	exit 1
    134 fi
    135 
    136 echo	"Mounting root filesystem..."
    137 if ! mount -o ro ${_root_filesystem} /mnt; then
    138 	echo	"ERROR: can't mount root filesystem!"
    139 	exit 1
    140 fi
    141 
    142 # Grab the fstab so we can munge it for our own use.
    143 if [ ! -f /mnt/etc/fstab ]; then
    144 	echo	"ERROR: no /etc/fstab!"
    145 	exit 1
    146 fi
    147 cp /mnt/etc/fstab /tmp/fstab
    148 
    149 # Grab the hosts table so we can use it.
    150 if [ ! -f /mnt/etc/hosts ]; then
    151 	echo	"ERROR: no /etc/hosts!"
    152 	exit 1
    153 fi
    154 cp /mnt/etc/hosts /tmp/hosts
    155 
    156 # Start up the network in same/similar configuration as the installed system
    157 # uses.
    158 cat << \__network_config_1
    159 
    160 The upgrade program would now like to enable the network.  It will use the
    161 configuration already stored on the root filesystem.  This is required
    162 if you wish to use the network installation capabilities of this program.
    163 
    164 __network_config_1
    165 echo -n	"Enable network? [y] "
    166 getresp "y"
    167 case "$resp" in
    168 	y*|Y*)
    169 		if ! enable_network; then
    170 			echo "ERROR: can't enable network!"
    171 			exit 1
    172 		fi
    173 
    174 		cat << \__network_config_2
    175 
    176 You will now be given the opportunity to escape to the command shell to
    177 do any additional network configuration you may need.  This may include
    178 adding additional routes, if needed.  In addition, you might take this
    179 opportunity to redo the default route in the event that it failed above.
    180 
    181 __network_config_2
    182 		echo -n "Escape to shell? [n] "
    183 		getresp "n"
    184 		case "$resp" in
    185 			y*|Y*)
    186 				echo "Type 'exit' to return to upgrade."
    187 				sh
    188 				;;
    189 
    190 			*)
    191 				;;
    192 		esac
    193 		;;
    194 	*)
    195 		;;
    196 esac
    197 
    198 # Now that the network has been configured, it is safe to configure the
    199 # fstab.  We remove all but ufs/ffs/nfs.
    200 (
    201 	rm -f /tmp/fstab.new
    202 	while read line; do
    203 		_fstype=`echo $line | awk '{print $3}'`
    204 		if [ "X${_fstype}" = X"ufs" -o \
    205 		    "X${_fstype}" = X"ffs" -o \
    206 		    "X${_fstype}" = X"nfs" ]; then
    207 			echo $line >> /tmp/fstab.new
    208 		fi
    209 	done
    210 ) < /tmp/fstab
    211 
    212 if [ ! -f /tmp/fstab.new ]; then
    213 	echo	"ERROR: strange fstab!"
    214 	exit 1
    215 fi
    216 
    217 # Convert ufs to ffs.
    218 sed -e 's/ufs/ffs/' < /tmp/fstab.new > /tmp/fstab
    219 rm -f /tmp/fstab.new
    220 
    221 echo	"The fstab is configured as follows:"
    222 echo	""
    223 cat /tmp/fstab
    224 cat << \__fstab_config_1
    225 
    226 You may wish to edit the fstab.  For example, you may need to resolve
    227 dependencies in the order which the filesystems are mounted.  Note that
    228 this fstab is only for installation purposes, and will not be copied into
    229 the root filesystem.
    230 
    231 __fstab_config_1
    232 echo -n	"Edit the fstab? [n] "
    233 getresp "n"
    234 case "$resp" in
    235 	y*|Y*)
    236 		vi /tmp/fstab
    237 		;;
    238 
    239 	*)
    240 		;;
    241 esac
    242 
    243 echo	""
    244 munge_fstab /tmp/fstab /tmp/fstab.shadow
    245 
    246 if ! umount /mnt; then
    247 	echo	"ERROR: can't unmount previously mounted root!"
    248 	exit 1
    249 fi
    250 
    251 # Check all of the filesystems.
    252 check_fs /tmp/fstab.shadow
    253 
    254 # Mount filesystems.
    255 mount_fs /tmp/fstab.shadow
    256 
    257 # Install sets.
    258 install_sets $UPGRSETS
    259 
    260 # Get timezone info
    261 get_timezone
    262 
    263 # Fix up the fstab.
    264 echo -n	"Converting ufs to ffs in /etc/fstab..."
    265 sed -e 's/ufs/ffs/' < /mnt/etc/fstab > /tmp/fstab
    266 echo	"done."
    267 echo -n	"Would you like to edit the resulting fstab? [y] "
    268 getresp "y"
    269 case "$resp" in
    270 	y*|Y*)
    271 		vi /tmp/fstab
    272 		;;
    273 
    274 	*)
    275 		;;
    276 esac
    277 
    278 # Copy in configuration information and make devices in target root.
    279 (
    280 	cd /tmp
    281 	for file in fstab; do
    282 		if [ -f $file ]; then
    283 			echo -n "Copying $file..."
    284 			cp $file /mnt/etc/$file
    285 			echo "done."
    286 		fi
    287 	done
    288 
    289 	echo -n "Installing timezone link..."
    290 	rm -f /mnt/etc/localtime
    291 	ln -s /usr/share/zoneinfo/$TZ /mnt/etc/localtime
    292 	echo "done."
    293 
    294 	echo -n "Making devices..."
    295 	pid=`twiddle`
    296 	cd /mnt/dev
    297 	sh MAKEDEV all
    298 	kill $pid
    299 	echo "done."
    300 
    301 	echo -n "Copying kernel..."
    302 	cp -p /netbsd /mnt/netbsd
    303 	echo "done."
    304 
    305 	md_installboot ${ROOTDISK}
    306 )
    307 
    308 unmount_fs /tmp/fstab.shadow
    309 
    310 # Pat on the back.
    311 md_congrats
    312 
    313 # ALL DONE!
    314 exit 0
    315