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