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