Home | History | Annotate | Line # | Download | only in miniroot
upgrade.sh revision 1.3
      1 #!/bin/sh
      2 #	$NetBSD: upgrade.sh,v 1.3 1996/05/27 12:39:06 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 # 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 	rm -f /tmp/fstab.new
    249 	while read line; do
    250 		_fstype=`echo $line | cutword 3`
    251 		if [ "X${_fstype}" = X"ufs" -o \
    252 		    "X${_fstype}" = X"ffs" -o \
    253 		    "X${_fstype}" = X"nfs" ]; then
    254 			echo $line >> /tmp/fstab.new
    255 		fi
    256 	done
    257 ) < /tmp/fstab
    258 
    259 if [ ! -f /tmp/fstab.new ]; then
    260 	echo	"ERROR: strange fstab!"
    261 	exit 1
    262 fi
    263 
    264 # Convert ufs to ffs.
    265 sed -e 's/ufs/ffs/' < /tmp/fstab.new > /tmp/fstab
    266 rm -f /tmp/fstab.new
    267 
    268 echo	"The fstab is configured as follows:"
    269 echo	""
    270 cat /tmp/fstab
    271 cat << \__fstab_config_1
    272 
    273 You may wish to edit the fstab.  For example, you may need to resolve
    274 dependencies in the order which the filesystems are mounted.  Note that
    275 this fstab is only for installation purposes, and will not be copied into
    276 the root filesystem.
    277 
    278 __fstab_config_1
    279 echo -n	"Edit the fstab? [n] "
    280 getresp "n"
    281 case "$resp" in
    282 	y*|Y*)
    283 		${EDITOR} /tmp/fstab
    284 		;;
    285 
    286 	*)
    287 		;;
    288 esac
    289 
    290 echo	""
    291 munge_fstab /tmp/fstab /tmp/fstab.shadow
    292 
    293 if ! umount /mnt; then
    294 	echo	"ERROR: can't unmount previously mounted root!"
    295 	exit 1
    296 fi
    297 
    298 # Check all of the filesystems.
    299 check_fs /tmp/fstab.shadow
    300 
    301 # Mount filesystems.
    302 mount_fs /tmp/fstab.shadow
    303 
    304 
    305 echo -n	"Are the upgrade sets on one of your normally mounted filesystems? [y] "
    306 getresp "y"
    307 case "$resp" in
    308 	y*|Y*)
    309 		get_reldir
    310 		;;
    311 	*)
    312 		;;
    313 esac
    314 
    315 # Install sets.
    316 install_sets $UPGRSETS
    317 
    318 # Get timezone info
    319 get_timezone
    320 
    321 # Fix up the fstab.
    322 echo -n	"Converting ufs to ffs in /etc/fstab..."
    323 sed -e 's/ufs/ffs/' < /mnt/etc/fstab > /tmp/fstab
    324 echo	"done."
    325 echo -n	"Would you like to edit the resulting fstab? [y] "
    326 getresp "y"
    327 case "$resp" in
    328 	y*|Y*)
    329 		${EDITOR} /tmp/fstab
    330 		;;
    331 
    332 	*)
    333 		;;
    334 esac
    335 
    336 # Copy in configuration information and make devices in target root.
    337 (
    338 	cd /tmp
    339 	for file in fstab; do
    340 		if [ -f $file ]; then
    341 			echo -n "Copying $file..."
    342 			cp $file /mnt/etc/$file
    343 			echo "done."
    344 		fi
    345 	done
    346 
    347 	echo -n "Installing timezone link..."
    348 	rm -f /mnt/etc/localtime
    349 	ln -s /usr/share/zoneinfo/$TZ /mnt/etc/localtime
    350 	echo "done."
    351 
    352 	echo -n "Making devices..."
    353 	pid=`twiddle`
    354 	cd /mnt/dev
    355 	sh MAKEDEV all
    356 	kill $pid
    357 	echo "done."
    358 
    359 	md_copy_kernel
    360 
    361 	md_installboot ${ROOTDISK}
    362 )
    363 
    364 unmount_fs /tmp/fstab.shadow
    365 
    366 # Pat on the back.
    367 md_congrats
    368 
    369 # ALL DONE!
    370 exit 0
    371