Home | History | Annotate | Line # | Download | only in miniroot
upgrade.sh revision 1.4
      1 #!/bin/sh
      2 #	$NetBSD: upgrade.sh,v 1.4 1996/05/27 13:32:01 pk 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 # include version number
     72 . VERSION
     73 
     74 get_reldir() {
     75 	while : ; do
     76 	    echo -n "Enter the pathname where the sets are stored [$RELDIR] "
     77 	    getresp "$RELDIR"
     78 	    RELDIR=$resp
     79 
     80 	    # Allow break-out with empty response
     81 	    if [ -z "$RELDIR" ]; then
     82 		echo -n "Are you sure you don't want to set the pathname? [n] "
     83 		getresp "n"
     84 		case "$resp" in
     85 			y*|Y*)
     86 				break
     87 				;;
     88 			*)
     89 				continue
     90 				;;
     91 		esac
     92 	    fi
     93 	    if [ -f "/mnt/$RELDIR/base.tar.gz" ]; then
     94 		break
     95 	    else
     96 		echo -n "The directory $RELDIR does not exist, retry? [y] "
     97 		getresp "y"
     98 		case "$resp" in
     99 			y*|Y*)
    100 				;;
    101 			*)
    102 				break
    103 				;;
    104 		esac
    105 	    fi
    106 	done
    107 }
    108 
    109 # Good {morning,afternoon,evening,night}.
    110 md_welcome_banner
    111 echo -n "Proceed with upgrade? [n] "
    112 getresp "n"
    113 case "$resp" in
    114 	y*|Y*)
    115 		echo	"Cool!  Let's get to it..."
    116 		;;
    117 	*)
    118 		md_not_going_to_install
    119 		exit
    120 		;;
    121 esac
    122 
    123 # Deal with terminal issues
    124 md_set_term
    125 
    126 # XXX Work around vnode aliasing bug (thanks for the tip, Chris...)
    127 ls -l /dev > /dev/null 2>&1
    128 
    129 # We don't like it, but it sure makes a few things a lot easier.
    130 do_mfs_mount "/tmp" "2048"
    131 
    132 while [ "X${ROOTDISK}" = "X" ]; do
    133 	getrootdisk
    134 done
    135 
    136 # Make sure there's a disklabel there.  If there isn't, puke after
    137 # disklabel prints the error message.
    138 md_checkfordisklabel ${ROOTDISK}
    139 case $rval in
    140 	1)
    141 		cat << \__disklabel_not_present_1
    142 
    143 FATAL ERROR: There is no disklabel present on the root disk!  You must
    144 label the disk with SYS_INST before continuing.
    145 
    146 __disklabel_not_present_1
    147 		exit
    148 		;;
    149 
    150 	2)
    151 		cat << \__disklabel_corrupted_1
    152 
    153 FATAL ERROR: The disklabel on the root disk is corrupted!  You must
    154 re-label the disk with SYS_INST before continuing.
    155 
    156 __disklabel_corrupted_1
    157 		exit
    158 		;;
    159 
    160 	*)
    161 		;;
    162 esac
    163 
    164 # Assume partition 'a' of $ROOTDISK is for the root filesystem.  Confirm
    165 # this with the user.  Check and mount the root filesystem.
    166 resp=""			# force one iteration
    167 while [ "X${resp}" = "X" ]; do
    168 	echo -n	"Root filesystem? [${ROOTDISK}a] "
    169 	getresp "${ROOTDISK}a"
    170 	_root_filesystem="/dev/`basename $resp`"
    171 	if [ ! -b ${_root_filesystem} ]; then
    172 		echo "Sorry, ${resp} is not a block device."
    173 		resp=""	# force loop to repeat
    174 	fi
    175 done
    176 
    177 echo	"Checking root filesystem..."
    178 if ! fsck -pf ${_root_filesystem}; then
    179 	echo	"ERROR: can't check root filesystem!"
    180 	exit 1
    181 fi
    182 
    183 echo	"Mounting root filesystem..."
    184 if ! mount -o ro ${_root_filesystem} /mnt; then
    185 	echo	"ERROR: can't mount root filesystem!"
    186 	exit 1
    187 fi
    188 
    189 # Grab the fstab so we can munge it for our own use.
    190 if [ ! -f /mnt/etc/fstab ]; then
    191 	echo	"ERROR: no /etc/fstab!"
    192 	exit 1
    193 fi
    194 cp /mnt/etc/fstab /tmp/fstab
    195 
    196 # Grab the hosts table so we can use it.
    197 if [ ! -f /mnt/etc/hosts ]; then
    198 	echo	"ERROR: no /etc/hosts!"
    199 	exit 1
    200 fi
    201 cp /mnt/etc/hosts /tmp/hosts
    202 
    203 # Start up the network in same/similar configuration as the installed system
    204 # uses.
    205 cat << \__network_config_1
    206 
    207 The upgrade program would now like to enable the network.  It will use the
    208 configuration already stored on the root filesystem.  This is required
    209 if you wish to use the network installation capabilities of this program.
    210 
    211 __network_config_1
    212 echo -n	"Enable network? [y] "
    213 getresp "y"
    214 case "$resp" in
    215 	y*|Y*)
    216 		if ! enable_network; then
    217 			echo "ERROR: can't enable network!"
    218 			exit 1
    219 		fi
    220 
    221 		cat << \__network_config_2
    222 
    223 You will now be given the opportunity to escape to the command shell to
    224 do any additional network configuration you may need.  This may include
    225 adding additional routes, if needed.  In addition, you might take this
    226 opportunity to redo the default route in the event that it failed above.
    227 
    228 __network_config_2
    229 		echo -n "Escape to shell? [n] "
    230 		getresp "n"
    231 		case "$resp" in
    232 			y*|Y*)
    233 				echo "Type 'exit' to return to upgrade."
    234 				sh
    235 				;;
    236 
    237 			*)
    238 				;;
    239 		esac
    240 		;;
    241 	*)
    242 		;;
    243 esac
    244 
    245 # Now that the network has been configured, it is safe to configure the
    246 # fstab.  We remove all but ufs/ffs/nfs.
    247 (
    248 	> /tmp/fstab.new
    249 	while read _dev _mp _fstype _rest ; do
    250 		if [ "X${_fstype}" = X"ufs" -o \
    251 		    "X${_fstype}" = X"ffs" -o \
    252 		    "X${_fstype}" = X"nfs" ]; then
    253 			if [ "X${_fstype}" = X"ufs" ]; then
    254 				# Convert ufs to ffs.
    255 				_fstype=ffs
    256 			fi
    257 			echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab.new
    258 		fi
    259 	done
    260 ) < /tmp/fstab
    261 
    262 if [ ! -f /tmp/fstab.new ]; then
    263 	echo	"ERROR: strange fstab!"
    264 	exit 1
    265 fi
    266 
    267 rm -f /tmp/fstab.new
    268 
    269 echo	"The fstab is configured as follows:"
    270 echo	""
    271 cat /tmp/fstab
    272 cat << \__fstab_config_1
    273 
    274 You may wish to edit the fstab.  For example, you may need to resolve
    275 dependencies in the order which the filesystems are mounted.  Note that
    276 this fstab is only for installation purposes, and will not be copied into
    277 the root filesystem.
    278 
    279 __fstab_config_1
    280 echo -n	"Edit the fstab? [n] "
    281 getresp "n"
    282 case "$resp" in
    283 	y*|Y*)
    284 		${EDITOR} /tmp/fstab
    285 		;;
    286 
    287 	*)
    288 		;;
    289 esac
    290 
    291 echo	""
    292 munge_fstab /tmp/fstab /tmp/fstab.shadow
    293 
    294 if ! umount /mnt; then
    295 	echo	"ERROR: can't unmount previously mounted root!"
    296 	exit 1
    297 fi
    298 
    299 # Check all of the filesystems.
    300 check_fs /tmp/fstab.shadow
    301 
    302 # Mount filesystems.
    303 mount_fs /tmp/fstab.shadow
    304 
    305 
    306 echo -n	"Are the upgrade sets on one of your normally mounted filesystems? [y] "
    307 getresp "y"
    308 case "$resp" in
    309 	y*|Y*)
    310 		get_reldir
    311 		;;
    312 	*)
    313 		;;
    314 esac
    315 
    316 # Install sets.
    317 install_sets $UPGRSETS
    318 
    319 # Get timezone info
    320 get_timezone
    321 
    322 # Fix up the fstab.
    323 echo -n	"Converting ufs to ffs in /etc/fstab..."
    324 (
    325 	> /tmp/fstab
    326 	while read _dev _mp _fstype _rest ; do
    327 		if [ "X${_fstype}" = X"ufs" -o \
    328 		    "X${_fstype}" = X"ffs" -o \
    329 		    "X${_fstype}" = X"nfs" ]; then
    330 			if [ "X${_fstype}" = X"ufs" ]; then
    331 				# Convert ufs to ffs.
    332 				_fstype=ffs
    333 			fi
    334 			echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab
    335 		fi
    336 	done
    337 ) < /mnt/etc/fstab
    338 echo	"done."
    339 echo -n	"Would you like to edit the resulting fstab? [y] "
    340 getresp "y"
    341 case "$resp" in
    342 	y*|Y*)
    343 		${EDITOR} /tmp/fstab
    344 		;;
    345 
    346 	*)
    347 		;;
    348 esac
    349 
    350 # Copy in configuration information and make devices in target root.
    351 (
    352 	cd /tmp
    353 	for file in fstab; do
    354 		if [ -f $file ]; then
    355 			echo -n "Copying $file..."
    356 			cp $file /mnt/etc/$file
    357 			echo "done."
    358 		fi
    359 	done
    360 
    361 	echo -n "Installing timezone link..."
    362 	rm -f /mnt/etc/localtime
    363 	ln -s /usr/share/zoneinfo/$TZ /mnt/etc/localtime
    364 	echo "done."
    365 
    366 	echo -n "Making devices..."
    367 	pid=`twiddle`
    368 	cd /mnt/dev
    369 	sh MAKEDEV all
    370 	kill $pid
    371 	echo "done."
    372 
    373 	md_copy_kernel
    374 
    375 	md_installboot ${ROOTDISK}
    376 )
    377 
    378 unmount_fs /tmp/fstab.shadow
    379 
    380 # Pat on the back.
    381 md_congrats
    382 
    383 # ALL DONE!
    384 exit 0
    385