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