Home | History | Annotate | Line # | Download | only in miniroot
upgrade.sh revision 1.13
      1   1.1       pk #!/bin/sh
      2  1.13       pk #	$NetBSD: upgrade.sh,v 1.13 1997/11/03 10:15:23 pk Exp $
      3   1.1       pk #
      4   1.2  thorpej # Copyright (c) 1996 The NetBSD Foundation, Inc.
      5   1.1       pk # All rights reserved.
      6   1.1       pk #
      7   1.2  thorpej # This code is derived from software contributed to The NetBSD Foundation
      8   1.2  thorpej # by Jason R. Thorpe.
      9   1.2  thorpej #
     10   1.1       pk # Redistribution and use in source and binary forms, with or without
     11   1.1       pk # modification, are permitted provided that the following conditions
     12   1.1       pk # are met:
     13   1.1       pk # 1. Redistributions of source code must retain the above copyright
     14   1.1       pk #    notice, this list of conditions and the following disclaimer.
     15   1.1       pk # 2. Redistributions in binary form must reproduce the above copyright
     16   1.1       pk #    notice, this list of conditions and the following disclaimer in the
     17   1.1       pk #    documentation and/or other materials provided with the distribution.
     18   1.1       pk # 3. All advertising materials mentioning features or use of this software
     19   1.1       pk #    must display the following acknowledgement:
     20   1.2  thorpej #        This product includes software developed by the NetBSD
     21   1.2  thorpej #        Foundation, Inc. and its contributors.
     22   1.2  thorpej # 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.2  thorpej #    contributors may be used to endorse or promote products derived
     24   1.2  thorpej #    from this software without specific prior written permission.
     25   1.1       pk #
     26   1.2  thorpej # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.2  thorpej # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.2  thorpej # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.12      jtc # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.12      jtc # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.2  thorpej # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.2  thorpej # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.2  thorpej # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.2  thorpej # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.2  thorpej # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.2  thorpej # POSSIBILITY OF SUCH DAMAGE.
     37   1.1       pk #
     38   1.1       pk 
     39   1.1       pk #	NetBSD installation script.
     40   1.1       pk #	In a perfect world, this would be a nice C program, with a reasonable
     41   1.1       pk #	user interface.
     42   1.1       pk 
     43   1.1       pk ROOTDISK=""				# filled in below
     44   1.1       pk 
     45   1.6       pk trap "unmount_fs -fast /tmp/fstab.shadow > /dev/null 2>&1; rm -f /tmp/fstab.shadow" 0
     46   1.1       pk 
     47   1.1       pk MODE="upgrade"
     48   1.1       pk 
     49   1.1       pk # include machine-dependent functions
     50   1.1       pk # The following functions must be provided:
     51   1.3      leo #	md_copy_kernel()	- copy a kernel to the installed disk
     52   1.1       pk #	md_get_diskdevs()	- return available disk devices
     53   1.1       pk #	md_get_cddevs()		- return available CD-ROM devices
     54   1.1       pk #	md_get_ifdevs()		- return available network interfaces
     55   1.3      leo #	md_get_partition_range() - return range of valid partition letters
     56   1.1       pk #	md_installboot()	- install boot-blocks on disk
     57   1.1       pk #	md_labeldisk()		- put label on a disk
     58   1.1       pk #	md_welcome_banner()	- display friendly message
     59   1.1       pk #	md_not_going_to_install() - display friendly message
     60   1.1       pk #	md_congrats()		- display friendly message
     61   1.3      leo 
     62   1.3      leo # include machine dependent subroutines
     63   1.1       pk . install.md
     64   1.1       pk 
     65   1.1       pk # include common subroutines
     66   1.1       pk . install.sub
     67   1.1       pk 
     68   1.8      jtc # which sets?
     69   1.8      jtc THESETS="$UPGRSETS"
     70   1.8      jtc 
     71   1.9       pk # Files that moved between 1.2 and 1.3
     72  1.13       pk RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/dumpfs /usr/sbin/dumpfs"
     73  1.13       pk RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/dumplfs /usr/sbin/dumplfs"
     74  1.13       pk RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/nfsd /usr/sbin/nfsd"
     75  1.13       pk RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/nfsiod /usr/sbin/nfsiod"
     76  1.11       pk RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/mountd /usr/sbin/mountd"
     77  1.13       pk RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/quotacheck /usr/sbin/quotacheck"
     78   1.9       pk RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/rtquey /usr/sbin/rtquery"
     79   1.9       pk 
     80   1.9       pk rm_relocated_files()
     81   1.9       pk {
     82   1.9       pk 	# ($n, $(n+1)): pairs of (old,new) locations of relocated files
     83   1.9       pk 	while [ $# -ge 2 ]; do
     84   1.9       pk 		if [ -f "$2" ]; then
     85   1.9       pk 			echo Removing "$1";
     86   1.9       pk 			rm -f "$1"
     87   1.9       pk 		fi
     88   1.9       pk 		shift 2
     89   1.9       pk 	done
     90   1.9       pk }
     91   1.9       pk 
     92   1.1       pk # Good {morning,afternoon,evening,night}.
     93   1.1       pk md_welcome_banner
     94   1.1       pk echo -n "Proceed with upgrade? [n] "
     95   1.1       pk getresp "n"
     96   1.1       pk case "$resp" in
     97   1.1       pk 	y*|Y*)
     98   1.1       pk 		echo	"Cool!  Let's get to it..."
     99   1.1       pk 		;;
    100   1.1       pk 	*)
    101   1.1       pk 		md_not_going_to_install
    102   1.1       pk 		exit
    103   1.1       pk 		;;
    104   1.1       pk esac
    105   1.1       pk 
    106   1.1       pk # Deal with terminal issues
    107   1.1       pk md_set_term
    108   1.1       pk 
    109   1.1       pk # XXX Work around vnode aliasing bug (thanks for the tip, Chris...)
    110   1.1       pk ls -l /dev > /dev/null 2>&1
    111   1.1       pk 
    112   1.8      jtc # Make sure we can write files (at least in /tmp)
    113   1.8      jtc # This might make an MFS mount on /tmp, or it may
    114   1.8      jtc # just re-mount the root with read-write enabled.
    115   1.8      jtc md_makerootwritable
    116   1.1       pk 
    117   1.1       pk while [ "X${ROOTDISK}" = "X" ]; do
    118   1.1       pk 	getrootdisk
    119   1.1       pk done
    120   1.1       pk 
    121   1.1       pk # Assume partition 'a' of $ROOTDISK is for the root filesystem.  Confirm
    122   1.1       pk # this with the user.  Check and mount the root filesystem.
    123   1.1       pk resp=""			# force one iteration
    124   1.1       pk while [ "X${resp}" = "X" ]; do
    125   1.1       pk 	echo -n	"Root filesystem? [${ROOTDISK}a] "
    126   1.1       pk 	getresp "${ROOTDISK}a"
    127   1.1       pk 	_root_filesystem="/dev/`basename $resp`"
    128   1.1       pk 	if [ ! -b ${_root_filesystem} ]; then
    129   1.1       pk 		echo "Sorry, ${resp} is not a block device."
    130   1.1       pk 		resp=""	# force loop to repeat
    131   1.1       pk 	fi
    132   1.1       pk done
    133   1.1       pk 
    134   1.1       pk echo	"Checking root filesystem..."
    135   1.1       pk if ! fsck -pf ${_root_filesystem}; then
    136   1.1       pk 	echo	"ERROR: can't check root filesystem!"
    137   1.1       pk 	exit 1
    138   1.1       pk fi
    139   1.1       pk 
    140   1.1       pk echo	"Mounting root filesystem..."
    141   1.1       pk if ! mount -o ro ${_root_filesystem} /mnt; then
    142   1.1       pk 	echo	"ERROR: can't mount root filesystem!"
    143   1.1       pk 	exit 1
    144   1.1       pk fi
    145   1.1       pk 
    146   1.1       pk # Grab the fstab so we can munge it for our own use.
    147   1.1       pk if [ ! -f /mnt/etc/fstab ]; then
    148   1.1       pk 	echo	"ERROR: no /etc/fstab!"
    149   1.1       pk 	exit 1
    150   1.1       pk fi
    151   1.1       pk 
    152   1.1       pk # Grab the hosts table so we can use it.
    153   1.1       pk if [ ! -f /mnt/etc/hosts ]; then
    154   1.1       pk 	echo	"ERROR: no /etc/hosts!"
    155   1.1       pk 	exit 1
    156   1.1       pk fi
    157   1.1       pk cp /mnt/etc/hosts /tmp/hosts
    158   1.1       pk 
    159   1.1       pk # Start up the network in same/similar configuration as the installed system
    160   1.1       pk # uses.
    161   1.1       pk cat << \__network_config_1
    162   1.1       pk 
    163   1.1       pk The upgrade program would now like to enable the network.  It will use the
    164   1.1       pk configuration already stored on the root filesystem.  This is required
    165   1.1       pk if you wish to use the network installation capabilities of this program.
    166   1.1       pk 
    167   1.1       pk __network_config_1
    168   1.1       pk echo -n	"Enable network? [y] "
    169   1.1       pk getresp "y"
    170   1.1       pk case "$resp" in
    171   1.1       pk 	y*|Y*)
    172   1.1       pk 		if ! enable_network; then
    173   1.1       pk 			echo "ERROR: can't enable network!"
    174   1.1       pk 			exit 1
    175   1.1       pk 		fi
    176   1.1       pk 
    177   1.1       pk 		cat << \__network_config_2
    178   1.1       pk 
    179   1.1       pk You will now be given the opportunity to escape to the command shell to
    180   1.1       pk do any additional network configuration you may need.  This may include
    181   1.1       pk adding additional routes, if needed.  In addition, you might take this
    182   1.1       pk opportunity to redo the default route in the event that it failed above.
    183   1.1       pk 
    184   1.1       pk __network_config_2
    185   1.1       pk 		echo -n "Escape to shell? [n] "
    186   1.1       pk 		getresp "n"
    187   1.1       pk 		case "$resp" in
    188   1.1       pk 			y*|Y*)
    189   1.1       pk 				echo "Type 'exit' to return to upgrade."
    190   1.1       pk 				sh
    191   1.1       pk 				;;
    192   1.1       pk 
    193   1.1       pk 			*)
    194   1.1       pk 				;;
    195   1.1       pk 		esac
    196   1.1       pk 		;;
    197   1.1       pk 	*)
    198   1.1       pk 		;;
    199   1.1       pk esac
    200   1.1       pk 
    201   1.1       pk # Now that the network has been configured, it is safe to configure the
    202   1.7       pk # fstab.  We remove all but ufs/ffs.
    203   1.1       pk (
    204   1.7       pk 	> /tmp/fstab
    205   1.4       pk 	while read _dev _mp _fstype _rest ; do
    206   1.1       pk 		if [ "X${_fstype}" = X"ufs" -o \
    207   1.7       pk 		     "X${_fstype}" = X"ffs" ]; then
    208   1.4       pk 			if [ "X${_fstype}" = X"ufs" ]; then
    209   1.4       pk 				# Convert ufs to ffs.
    210   1.4       pk 				_fstype=ffs
    211   1.4       pk 			fi
    212   1.7       pk 			echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab
    213   1.1       pk 		fi
    214   1.1       pk 	done
    215   1.7       pk ) < /mnt/etc/fstab
    216   1.1       pk 
    217   1.1       pk echo	"The fstab is configured as follows:"
    218   1.1       pk echo	""
    219   1.1       pk cat /tmp/fstab
    220   1.1       pk cat << \__fstab_config_1
    221   1.1       pk 
    222   1.1       pk You may wish to edit the fstab.  For example, you may need to resolve
    223   1.1       pk dependencies in the order which the filesystems are mounted.  Note that
    224   1.1       pk this fstab is only for installation purposes, and will not be copied into
    225   1.1       pk the root filesystem.
    226   1.1       pk 
    227   1.1       pk __fstab_config_1
    228   1.1       pk echo -n	"Edit the fstab? [n] "
    229   1.1       pk getresp "n"
    230   1.1       pk case "$resp" in
    231   1.1       pk 	y*|Y*)
    232   1.3      leo 		${EDITOR} /tmp/fstab
    233   1.1       pk 		;;
    234   1.1       pk 
    235   1.1       pk 	*)
    236   1.1       pk 		;;
    237   1.1       pk esac
    238   1.1       pk 
    239   1.1       pk echo	""
    240   1.1       pk munge_fstab /tmp/fstab /tmp/fstab.shadow
    241   1.1       pk 
    242   1.1       pk if ! umount /mnt; then
    243   1.1       pk 	echo	"ERROR: can't unmount previously mounted root!"
    244   1.1       pk 	exit 1
    245   1.1       pk fi
    246   1.1       pk 
    247   1.1       pk # Check all of the filesystems.
    248   1.1       pk check_fs /tmp/fstab.shadow
    249   1.1       pk 
    250   1.1       pk # Mount filesystems.
    251   1.1       pk mount_fs /tmp/fstab.shadow
    252   1.1       pk 
    253   1.6       pk echo -n	"Are the upgrade sets on one of your normally mounted (local) filesystems? [y] "
    254   1.3      leo getresp "y"
    255   1.3      leo case "$resp" in
    256   1.3      leo 	y*|Y*)
    257   1.6       pk 		get_localdir /mnt
    258   1.3      leo 		;;
    259   1.3      leo 	*)
    260   1.3      leo 		;;
    261   1.3      leo esac
    262   1.3      leo 
    263   1.1       pk # Install sets.
    264   1.6       pk install_sets
    265   1.9       pk 
    266   1.9       pk # Remove files that have just been installed in a new location
    267   1.9       pk # from the old location
    268   1.9       pk rm_relocated_files `eval echo \\$RELOCATED_FILES_${VERSION}`
    269   1.1       pk 
    270   1.1       pk # Get timezone info
    271   1.1       pk get_timezone
    272   1.1       pk 
    273   1.1       pk # Fix up the fstab.
    274   1.1       pk echo -n	"Converting ufs to ffs in /etc/fstab..."
    275   1.4       pk (
    276   1.4       pk 	> /tmp/fstab
    277   1.4       pk 	while read _dev _mp _fstype _rest ; do
    278   1.7       pk 		if [ "X${_fstype}" = X"ufs" ]; then
    279   1.7       pk 			# Convert ufs to ffs.
    280   1.7       pk 			_fstype=ffs
    281   1.4       pk 		fi
    282   1.7       pk 		echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab
    283   1.4       pk 	done
    284   1.4       pk ) < /mnt/etc/fstab
    285   1.1       pk echo	"done."
    286   1.1       pk echo -n	"Would you like to edit the resulting fstab? [y] "
    287   1.1       pk getresp "y"
    288   1.1       pk case "$resp" in
    289   1.1       pk 	y*|Y*)
    290   1.3      leo 		${EDITOR} /tmp/fstab
    291   1.1       pk 		;;
    292   1.1       pk 
    293   1.1       pk 	*)
    294   1.1       pk 		;;
    295   1.1       pk esac
    296   1.1       pk 
    297   1.1       pk # Copy in configuration information and make devices in target root.
    298   1.1       pk (
    299   1.1       pk 	cd /tmp
    300   1.1       pk 	for file in fstab; do
    301   1.1       pk 		if [ -f $file ]; then
    302   1.1       pk 			echo -n "Copying $file..."
    303   1.1       pk 			cp $file /mnt/etc/$file
    304   1.1       pk 			echo "done."
    305   1.1       pk 		fi
    306   1.1       pk 	done
    307   1.1       pk 
    308   1.1       pk 	echo -n "Installing timezone link..."
    309   1.1       pk 	rm -f /mnt/etc/localtime
    310   1.1       pk 	ln -s /usr/share/zoneinfo/$TZ /mnt/etc/localtime
    311   1.1       pk 	echo "done."
    312   1.1       pk 
    313   1.1       pk 	echo -n "Making devices..."
    314   1.6       pk 	_pid=`twiddle`
    315   1.1       pk 	cd /mnt/dev
    316   1.1       pk 	sh MAKEDEV all
    317   1.6       pk 	kill $_pid
    318   1.1       pk 	echo "done."
    319   1.1       pk 
    320   1.3      leo 	md_copy_kernel
    321   1.1       pk 
    322   1.1       pk 	md_installboot ${ROOTDISK}
    323   1.1       pk )
    324   1.1       pk 
    325   1.1       pk unmount_fs /tmp/fstab.shadow
    326   1.1       pk 
    327   1.1       pk # Pat on the back.
    328   1.1       pk md_congrats
    329   1.1       pk 
    330   1.1       pk # ALL DONE!
    331   1.1       pk exit 0
    332