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