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