Home | History | Annotate | Line # | Download | only in miniroot
install.sub revision 1.49
      1   1.1        pk #!/bin/sh
      2  1.49      maya #	$NetBSD: install.sub,v 1.49 2019/10/02 11:15:59 maya 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 #
     19   1.2   thorpej # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.2   thorpej # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.2   thorpej # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.22       jtc # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.22       jtc # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.2   thorpej # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.2   thorpej # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.2   thorpej # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.2   thorpej # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.2   thorpej # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.2   thorpej # POSSIBILITY OF SUCH DAMAGE.
     30   1.1        pk #
     31   1.1        pk 
     32   1.1        pk #	NetBSD installation/upgrade script - common subroutines.
     33   1.1        pk 
     34   1.1        pk ROOTDISK=""				# filled in below
     35  1.48  christos VERSION=89936
     36   1.7       leo export VERSION
     37   1.1        pk 
     38  1.49      maya ALLSETS="base comp etc games man misc rescue text"	# default install sets
     39  1.49      maya UPGRSETS="base comp games man misc text"		# default upgrade sets
     40  1.49      maya THESETS=						# one of the above
     41  1.13        pk 
     42  1.13        pk local_sets_dir=""			# Path searched for sets by install_sets
     43  1.13        pk 					# on the local filesystems
     44   1.1        pk 
     45   1.7       leo # decide upon an editor
     46  1.48  christos if [ -z "$EDITOR" ]; then
     47   1.7       leo 	if [ -x /usr/bin/vi ]; then
     48   1.7       leo 		EDITOR=vi
     49   1.7       leo 	else
     50   1.7       leo 		EDITOR=ed
     51   1.7       leo 	fi
     52   1.7       leo fi
     53   1.7       leo 
     54   1.1        pk getresp() {
     55   1.1        pk 	read resp
     56  1.47  christos 	if [ -z "$resp" ]; then
     57   1.1        pk 		resp=$1
     58   1.1        pk 	fi
     59   1.1        pk }
     60   1.1        pk 
     61   1.1        pk isin() {
     62   1.1        pk # test the first argument against the remaining ones, return succes on a match
     63   1.1        pk 	_a=$1; shift
     64   1.1        pk 	while [ $# != 0 ]; do
     65   1.1        pk 		if [ "$_a" = "$1" ]; then return 0; fi
     66   1.1        pk 		shift
     67   1.1        pk 	done
     68   1.1        pk 	return 1
     69   1.1        pk }
     70   1.1        pk 
     71   1.1        pk rmel() {
     72   1.1        pk # remove first argument from list formed by the remaining arguments
     73   1.6       leo 	local	_a
     74   1.6       leo 
     75   1.1        pk 	_a=$1; shift
     76   1.1        pk 	while [ $# != 0 ]; do
     77   1.1        pk 		if [ "$_a" != "$1" ]; then
     78   1.1        pk 			echo "$1";
     79   1.1        pk 		fi
     80   1.1        pk 		shift
     81   1.1        pk 	done
     82   1.1        pk }
     83   1.1        pk 
     84   1.3        pk cutword () {
     85   1.3        pk # read a line of data, return Nth element.
     86   1.3        pk 	local _a
     87   1.3        pk 	local _n
     88   1.4        pk 	local _oifs
     89   1.4        pk 
     90   1.4        pk 	# optional field separator
     91   1.4        pk 	_oifs="$IFS"
     92   1.4        pk 	case "$1" in
     93   1.6       leo 		-t?*) IFS=${1#-t}; shift;;
     94   1.4        pk 	esac
     95   1.4        pk 
     96   1.3        pk 	_n=$1
     97   1.3        pk 	read _a; set -- $_a
     98   1.4        pk 	IFS="$_oifs"
     99   1.3        pk 	if [ "$1" = "" ]; then return; fi
    100   1.3        pk 	eval echo \$$_n
    101   1.3        pk }
    102   1.3        pk 
    103   1.3        pk cutlast () {
    104   1.3        pk # read a line of data, return last element. Equiv. of awk '{print $NF}'.
    105   1.3        pk 	local _a
    106   1.4        pk 	local _oifs
    107   1.4        pk 
    108   1.4        pk 	# optional field separator
    109   1.4        pk 	_oifs="$IFS"
    110   1.4        pk 	case "$1" in
    111   1.6       leo 		-t?*) IFS=${1#-t}; shift;;
    112   1.4        pk 	esac
    113   1.4        pk 
    114   1.3        pk 	read _a; set -- $_a
    115   1.4        pk 	IFS="$_oifs"
    116   1.3        pk 	if [ "$1" = "" ]; then return; fi
    117   1.5        pk 	while [ "$#" -gt 10 ]; do shift 10; done
    118   1.3        pk 	eval echo \$$#
    119   1.3        pk }
    120   1.3        pk 
    121   1.3        pk firstchar () {
    122   1.3        pk # return first character of argument
    123   1.3        pk 	local _a
    124   1.3        pk 	_a=$1
    125   1.3        pk 	while [ ${#_a} != 1 ]; do
    126   1.3        pk 		_a=${_a%?}
    127   1.3        pk 	done
    128   1.3        pk 	echo $_a
    129   1.3        pk }
    130   1.3        pk 
    131   1.5        pk basename () {
    132   1.5        pk 	local _oifs
    133   1.5        pk 	if [ "$1" = "" ]; then return; fi
    134   1.5        pk 	_oifs="$IFS"
    135   1.5        pk 	IFS="/"
    136   1.5        pk 	set -- $1
    137   1.5        pk 	IFS="$_oifs"
    138   1.5        pk 	while [ "$#" -gt 10 ]; do shift 10; done
    139   1.5        pk 	eval echo \$$#
    140   1.5        pk }
    141   1.5        pk 
    142   1.7       leo dir_has_sets() {
    143   1.7       leo 	# return true when the directory $1 contains a set for $2...$n
    144   1.7       leo 	local _dir
    145   1.7       leo 	local _file
    146   1.7       leo 
    147   1.7       leo 	_dir=$1; shift
    148   1.7       leo 	for _file in $*
    149   1.7       leo 	do
    150   1.7       leo 		if [ -f $_dir/${_file}.tar.gz ]; then
    151   1.7       leo 			return 0
    152   1.7       leo 		fi
    153  1.13        pk 		# Try for stupid msdos convention
    154  1.13        pk 		if [ -f $_dir/${_file}.tgz ]; then
    155  1.13        pk 			return 0
    156  1.13        pk 		fi
    157  1.40  fredette 		# Try for uncompressed files
    158  1.40  fredette 		if [ -f $_dir/${_file}.tar ]; then
    159  1.40  fredette 			return 0
    160  1.40  fredette 		fi
    161  1.18        is 		# Try for split files
    162  1.18        is 		if [ -f $_dir/${_file}${VERSION}.aa ]; then
    163  1.18        is 			return 0
    164  1.18        is 		fi
    165   1.7       leo 	done
    166   1.7       leo 	return 1
    167   1.7       leo }
    168   1.7       leo 
    169   1.1        pk twiddle() {
    170   1.1        pk # spin the propeller so we don't get bored
    171   1.1        pk 	while : ; do  
    172   1.1        pk 		sleep 1; echo -n "/";
    173   1.1        pk 		sleep 1; echo -n "-";
    174   1.1        pk 		sleep 1; echo -n "\\";
    175   1.1        pk 		sleep 1; echo -n "|";
    176   1.1        pk 	done > /dev/tty & echo $!
    177   1.1        pk }
    178   1.1        pk 
    179  1.13        pk get_localdir() {
    180  1.13        pk 	# $1 is relative mountpoint
    181  1.13        pk 	local _mp
    182  1.13        pk 	local _dir
    183  1.13        pk 
    184  1.13        pk 	_mp=$1
    185  1.13        pk 	_dir=
    186  1.13        pk 	while : ; do
    187  1.48  christos 	    if [ -n "$_mp" ]; then
    188  1.32        pk 		cat << __get_localdir_1
    189  1.32        pk Note: your filesystems are mounted under the temporary mount point \"$_mp\".
    190  1.32        pk The pathname you are requested to enter below should NOT include the \"$_mp\"
    191  1.32        pk prefix.
    192  1.32        pk __get_localdir_1
    193  1.32        pk 	    fi
    194  1.13        pk 	    echo -n "Enter the pathname where the sets are stored [$_dir] "
    195  1.13        pk 	    getresp "$_dir"
    196  1.13        pk 	    _dir=$resp
    197  1.13        pk 
    198  1.13        pk 	    # Allow break-out with empty response
    199  1.13        pk 	    if [ -z "$_dir" ]; then
    200  1.13        pk 		echo -n "Are you sure you don't want to set the pathname? [n] "
    201  1.13        pk 		getresp "n"
    202  1.13        pk 		case "$resp" in
    203  1.13        pk 			y*|Y*)
    204  1.13        pk 				break
    205  1.13        pk 				;;
    206  1.13        pk 			*)
    207  1.13        pk 				continue
    208  1.13        pk 				;;
    209  1.13        pk 		esac
    210  1.13        pk 	    fi
    211  1.13        pk 
    212  1.13        pk 	    if dir_has_sets "$_mp/$_dir" $THESETS
    213  1.13        pk 	    then
    214  1.13        pk 		local_sets_dir="$_mp/$_dir"
    215  1.13        pk 		break
    216  1.13        pk 	    else
    217  1.32        pk 		cat << __get_localdir_2
    218  1.32        pk The directory \"$_mp/$_dir\" does not exist, or does not hold any of the
    219  1.13        pk upgrade sets.
    220  1.32        pk __get_localdir_2
    221  1.13        pk 		echo -n "Re-enter pathname? [y] "
    222  1.13        pk 		getresp "y"
    223  1.13        pk 		case "$resp" in
    224  1.13        pk 			y*|Y*)
    225  1.13        pk 				;;
    226  1.13        pk 			*)
    227  1.13        pk 				local_sets_dir=""
    228  1.13        pk 				break
    229  1.13        pk 				;;
    230  1.13        pk 		esac
    231  1.13        pk 	    fi
    232  1.13        pk 	done
    233  1.13        pk }
    234  1.13        pk 
    235   1.1        pk getrootdisk() {
    236   1.1        pk 	cat << \__getrootdisk_1
    237   1.1        pk 
    238   1.1        pk The installation program needs to know which disk to consider
    239   1.1        pk the root disk.  Note the unit number may be different than
    240   1.1        pk the unit number you used in the standalone installation
    241   1.1        pk program.
    242   1.1        pk 
    243   1.1        pk Available disks are:
    244   1.1        pk 
    245   1.1        pk __getrootdisk_1
    246  1.47  christos 	_DKDEVS=$(md_get_diskdevs)
    247   1.1        pk 	echo	"$_DKDEVS"
    248   1.1        pk 	echo	""
    249   1.1        pk 	echo -n	"Which disk is the root disk? "
    250   1.1        pk 	getresp ""
    251   1.1        pk 	if isin $resp $_DKDEVS ; then
    252   1.1        pk 		ROOTDISK="$resp"
    253   1.1        pk 	else
    254   1.1        pk 		echo ""
    255   1.1        pk 		echo "The disk $resp does not exist."
    256   1.1        pk 		ROOTDISK=""
    257   1.1        pk 	fi
    258   1.1        pk }
    259   1.1        pk 
    260   1.1        pk labelmoredisks() {
    261   1.1        pk 	cat << \__labelmoredisks_1
    262   1.1        pk 
    263   1.1        pk You may label the following disks:
    264   1.1        pk 
    265   1.1        pk __labelmoredisks_1
    266   1.1        pk 	echo "$_DKDEVS"
    267   1.1        pk 	echo	""
    268   1.1        pk 	echo -n	"Label which disk? [done] "
    269   1.1        pk 	getresp "done"
    270   1.1        pk 	case "$resp" in
    271  1.31       sjg 		"done")
    272   1.1        pk 			;;
    273   1.1        pk 
    274   1.1        pk 		*)
    275   1.5        pk 			if isin $resp $_DKDEVS ; then
    276   1.1        pk 				md_labeldisk $resp
    277   1.1        pk 			else
    278   1.1        pk 				echo ""
    279   1.1        pk 				echo "The disk $resp does not exist."
    280   1.1        pk 			fi
    281   1.1        pk 			;;
    282   1.1        pk 	esac
    283   1.1        pk }
    284   1.1        pk 
    285   1.1        pk addhostent() {
    286   1.1        pk 	# $1 - IP address
    287   1.1        pk 	# $2 - symbolic name
    288   1.1        pk 
    289  1.34        pk 	local fqdn
    290  1.34        pk 
    291   1.1        pk 	# Create an entry in the hosts table.  If no host table
    292   1.1        pk 	# exists, create one.  If the IP address already exists,
    293  1.44       snj 	# replace its entry.
    294   1.1        pk 	if [ ! -f /tmp/hosts ]; then
    295   1.1        pk 		echo "127.0.0.1 localhost" > /tmp/hosts
    296   1.1        pk 	fi
    297   1.1        pk 
    298   1.3        pk 	sed "/^$1 /d" < /tmp/hosts > /tmp/hosts.new
    299   1.3        pk 	mv /tmp/hosts.new /tmp/hosts
    300   1.1        pk 
    301  1.48  christos 	if [ -n "${FQDN}" ]; then
    302  1.34        pk 		fqdn=$2.$FQDN
    303  1.34        pk 	fi
    304  1.34        pk 	echo "$1 $2 $fqdn" >> /tmp/hosts
    305   1.1        pk }
    306   1.1        pk 
    307   1.1        pk addifconfig() {
    308   1.1        pk 	# $1 - interface name
    309   1.1        pk 	# $2 - interface symbolic name
    310   1.1        pk 	# $3 - interface IP address
    311   1.1        pk 	# $4 - interface netmask
    312  1.38        is 	# $5 - (optional) interface link-layer medium, preceded by "media ", else ""
    313  1.16        pk 	# $6 - (optional) interface link-layer directives
    314  1.16        pk 	local _m
    315  1.16        pk 
    316  1.16        pk 	# Create a ifconfig.* file for the interface.
    317  1.38        is 	echo "inet $2 netmask $4 $5 $6" > /tmp/ifconfig.$1
    318   1.1        pk 
    319   1.1        pk 	addhostent $3 $2
    320   1.1        pk }
    321   1.1        pk 
    322   1.1        pk configurenetwork() {
    323   1.1        pk 	local _ifsdone
    324   1.1        pk 	local _ifs
    325   1.1        pk 
    326  1.47  christos #	_IFS=$(md_get_ifdevs)
    327  1.47  christos 	_IFS=$(ifconfig -l | sed '
    328  1.16        pk 		s/lo0//
    329  1.16        pk 		s/ppp[0-9]//g
    330  1.16        pk 		s/sl[0-9]//g
    331  1.47  christos 		s/tun[0-9]//g')
    332  1.16        pk 
    333   1.1        pk 	_ifsdone=""
    334   1.1        pk 	resp=""		# force at least one iteration
    335  1.47  christos 	while [ "${resp}" != "done" ]; do
    336   1.1        pk 	cat << \__configurenetwork_1
    337   1.1        pk 
    338   1.1        pk You may configure the following network interfaces (the interfaces
    339  1.41  fredette marked with [X] have been successfully configured):
    340   1.1        pk 
    341   1.1        pk __configurenetwork_1
    342   1.1        pk 
    343   1.1        pk 		for _ifs in $_IFS; do
    344   1.1        pk 			if isin $_ifs $_ifsdone ; then
    345   1.1        pk 				echo -n "[X] "
    346   1.1        pk 			else
    347   1.1        pk 				echo -n "    "
    348   1.1        pk 			fi
    349   1.1        pk 			echo $_ifs
    350   1.1        pk 		done
    351   1.1        pk 		echo	""
    352   1.1        pk 		echo -n	"Configure which interface? [done] "
    353   1.1        pk 		getresp "done"
    354   1.1        pk 		case "$resp" in
    355   1.1        pk 		"done")
    356   1.1        pk 			;;
    357   1.1        pk 		*)
    358   1.1        pk 			_ifs=$resp
    359   1.1        pk 			if isin $_ifs $_IFS ; then
    360   1.1        pk 				if configure_ifs $_ifs ; then
    361   1.1        pk 					_ifsdone="$_ifs $_ifsdone"
    362   1.1        pk 				fi
    363   1.1        pk 			else
    364   1.1        pk 				echo "Invalid response: \"$resp\" is not in list"
    365   1.1        pk 			fi
    366   1.1        pk 			;;
    367   1.1        pk 		esac
    368   1.1        pk 	done
    369   1.1        pk }
    370   1.1        pk 
    371   1.1        pk configure_ifs() {
    372   1.1        pk 
    373   1.8        pk 	local _up
    374   1.8        pk 	local _interface_name
    375   1.8        pk 	local _interface_ip
    376   1.8        pk 	local _interface_mask
    377   1.8        pk 	local _interface_symname
    378  1.15       gwr 	local _interface_extra
    379  1.19        pk 	local _interface_mediumtype
    380  1.19        pk 	local _interface_supported_media
    381  1.28        is 	local _m
    382  1.29       mrg 	local _t
    383   1.8        pk 
    384   1.1        pk 	_interface_name=$1
    385  1.16        pk 	_up=DOWN
    386  1.47  christos 	if isin $_interface_name $(ifconfig -l -u); then
    387  1.16        pk 		_up=UP
    388  1.16        pk 	fi
    389  1.16        pk 
    390  1.47  christos 	_interface_supported_media=$(ifconfig -m $_interface_name | sed -n '
    391  1.29       mrg 		/^[ 	]*media autoselect/d
    392  1.47  christos 		4,$s/[ 	]*media //p')
    393   1.1        pk 
    394  1.29       mrg 	# get current "media" "ip" and "netmask" ("broadcast")
    395  1.47  christos 	_t=$(ifconfig $_interface_name | sed -n '
    396  1.47  christos 		s/^[ 	]*media: [^ 	]* \([^ ][^ ]*\).*/\1/p')
    397   1.8        pk 
    398  1.47  christos 	if [ "$_t" != "manual" ] && [ "$_t" != "media:" ] && [ "$_t" != "autoselect" ];
    399  1.29       mrg 	then
    400  1.19        pk 		_interface_mediumtype=$1
    401  1.19        pk 	fi
    402  1.29       mrg 
    403  1.47  christos 	set -- $(ifconfig $_interface_name | sed -n '
    404  1.29       mrg 		/^[ 	]*inet/{
    405  1.29       mrg 		s/inet//
    406  1.29       mrg 		s/--> [0-9.][0-9.]*//
    407  1.29       mrg 		s/netmask//
    408  1.29       mrg 		s/broadcast//
    409  1.47  christos 		p;}')
    410  1.29       mrg 
    411  1.29       mrg 	_interface_ip=$1
    412  1.29       mrg 	_interface_mask=$2
    413   1.8        pk 
    414   1.1        pk 	# Get IP address
    415   1.1        pk 	resp=""		# force one iteration
    416  1.47  christos 	while [ -z "${resp}" ]; do
    417   1.8        pk 		echo -n "IP address? [$_interface_ip] "
    418   1.8        pk 		getresp "$_interface_ip"
    419   1.1        pk 		_interface_ip=$resp
    420   1.1        pk 	done
    421   1.1        pk 
    422   1.1        pk 	# Get symbolic name
    423   1.1        pk 	resp=""		# force one iteration
    424  1.47  christos 	while [ -z "${resp}" ]; do
    425   1.1        pk 		echo -n "Symbolic (host) name? "
    426   1.1        pk 		getresp ""
    427   1.1        pk 		_interface_symname=$resp
    428   1.1        pk 	done
    429   1.1        pk 
    430   1.1        pk 	# Get netmask
    431   1.1        pk 	resp=""		# force one iteration
    432  1.47  christos 	while [ -n "${resp}" ]; do
    433   1.8        pk 		echo -n "Netmask? [$_interface_mask] "
    434   1.8        pk 		getresp "$_interface_mask"
    435   1.1        pk 		_interface_mask=$resp
    436   1.1        pk 	done
    437   1.1        pk 
    438  1.16        pk 	echo "Your network interface might require explicit selection"
    439  1.16        pk 	echo "of the type of network medium attached. Supported media:"
    440  1.29       mrg 	echo "$_interface_supported_media"
    441  1.29       mrg 	echo -n "Additional media type arguments (none)? [$_interface_mediumtype] "
    442  1.16        pk 	getresp "$_interface_mediumtype"
    443  1.28        is 	_m=""
    444  1.47  christos 	if [ "${resp:-none}" != "none" ]; then
    445  1.16        pk 		_interface_mediumtype=$resp
    446  1.28        is 		_m="media ${resp}"
    447  1.16        pk 	fi
    448  1.16        pk 
    449  1.16        pk 
    450  1.15       gwr 	echo "Your network interface might require additional link-layer"
    451  1.47  christos 	echo "directives (like 'link0'). If this is the case you can enter"
    452  1.15       gwr 	echo "these at the next prompt."
    453  1.15       gwr 	echo ""
    454  1.29       mrg 	echo -n "Additional link-layer arguments (none)? [$_interface_extra] "
    455  1.15       gwr 	getresp "$_interface_extra"
    456  1.47  christos 	if [ "${resp:-none}" != "none" ]; then
    457  1.15       gwr 		_interface_extra=$resp
    458  1.15       gwr 	fi
    459  1.15       gwr 
    460   1.1        pk 	# Configure the interface.  If it
    461   1.1        pk 	# succeeds, add it to the permanent
    462   1.1        pk 	# network configuration info.
    463   1.8        pk 	if [ $_up != "UP" ]; then
    464   1.8        pk 		ifconfig ${_interface_name} down
    465   1.8        pk 		if ifconfig ${_interface_name} inet \
    466   1.8        pk 		    ${_interface_ip} \
    467  1.28        is 		    netmask ${_interface_mask} \
    468  1.28        is 		    ${_interface_extra} ${_m} up ; then
    469   1.8        pk 			addifconfig \
    470  1.28        is 			    "${_interface_name}" \
    471  1.28        is 			    "${_interface_symname}" \
    472  1.28        is 			    "${_interface_ip}" \
    473  1.28        is 			    "${_interface_mask}" \
    474  1.38        is 			    "${_m}" \
    475  1.28        is 			    "${_interface_extra}"
    476   1.8        pk 			return 0
    477   1.8        pk 		fi
    478   1.8        pk 	else
    479   1.8        pk 		echo "Interface ${_interface_name} is already active."
    480   1.8        pk 		echo "Just saving configuration on new root filesystem."
    481   1.1        pk 		addifconfig \
    482  1.28        is 		    "${_interface_name}" \
    483  1.28        is 		    "${_interface_symname}" \
    484  1.28        is 		    "${_interface_ip}" \
    485  1.28        is 		    "${_interface_mask}" \
    486  1.38        is 		    "${_m}" \
    487  1.28        is 		    "${_interface_extra}"
    488   1.1        pk 	fi
    489   1.1        pk 	return 1
    490   1.1        pk }
    491   1.1        pk 
    492  1.35     lukem # Much of this is gratuitously stolen from /etc/rc.d/network.
    493   1.1        pk enable_network() {
    494   1.1        pk 
    495   1.1        pk 	# Set up the hostname.
    496  1.39       abs 	if [ -f /mnt/etc/myname ]; then
    497  1.47  christos 		hostname=$(cat /mnt/etc/myname)
    498  1.39       abs 	elif [ -f /mnt/etc/rc.conf ];then
    499  1.47  christos 		hostname=$(sh -c '. /mnt/etc/rc.conf ; echo $hostname')
    500  1.39       abs 	else
    501   1.1        pk 		echo "ERROR: no /etc/myname!"
    502   1.1        pk 		return 1
    503   1.1        pk 	fi
    504  1.39       abs 	if [ -z "$hostname" ];then
    505  1.39       abs 		echo "ERROR: hostname not set in /etc/myname or /etc/rc.conf!"
    506  1.39       abs 		return 1
    507  1.39       abs 	fi
    508   1.1        pk 	hostname $hostname
    509   1.1        pk 
    510   1.1        pk 	# configure all the interfaces which we know about.
    511  1.16        pk if [ -f /mnt/etc/rc.conf ]; then
    512  1.16        pk (
    513  1.16        pk 	# assume network interface configuration style 1.2D and up
    514  1.43    bouyer 	if [ -f /mnt/etc/defaults/rc.conf ]; then
    515  1.43    bouyer 		. /mnt/etc/defaults/rc.conf
    516  1.43    bouyer 	fi
    517  1.16        pk 	. /mnt/etc/rc.conf
    518  1.16        pk 
    519  1.16        pk 	if [ "$net_interfaces" != NO ]; then
    520  1.24        pk 		if [ "$auto_ifconfig" = YES ]; then
    521  1.47  christos 			tmp="$(ifconfig -l)"
    522  1.16        pk 		else
    523  1.16        pk 			tmp="$net_interfaces"
    524  1.16        pk 		fi
    525  1.16        pk 		echo -n "configuring network interfaces:"
    526  1.16        pk 		for i in $tmp; do
    527  1.47  christos 			eval $(echo 'args=$ifconfig_'$i)
    528  1.16        pk 			if [ ! -z "$args" ]; then
    529  1.16        pk 				echo -n " $i"
    530  1.16        pk 				ifconfig $i $args
    531  1.16        pk 			elif [ -f /mnt/etc/ifconfig.$i ]; then
    532  1.16        pk 				echo -n " $i"
    533  1.16        pk 				(while read args; do
    534  1.16        pk 					ifconfig $i $args
    535  1.16        pk 				done) < /mnt/etc/ifconfig.$i
    536  1.24        pk 			elif [ "$auto_ifconfig" != YES ]; then
    537  1.16        pk 				echo
    538  1.16        pk 				echo -n "/mnt/etc/ifconfig.$i missing"
    539  1.16        pk 				echo -n "& ifconfig_$i not set"
    540  1.16        pk 				echo "; interface $i can't be configured"
    541  1.16        pk 			fi
    542  1.16        pk 		done
    543  1.16        pk 		echo "."
    544  1.16        pk 	fi
    545  1.16        pk )
    546  1.16        pk else
    547   1.1        pk (
    548   1.1        pk 	tmp="$IFS"
    549   1.1        pk 	IFS="$IFS."
    550  1.47  christos 	set -- $(echo /mnt/etc/hostname*)
    551   1.1        pk 	IFS=$tmp
    552   1.1        pk 	unset tmp
    553   1.1        pk 
    554   1.1        pk 	while [ $# -ge 2 ] ; do
    555   1.1        pk 		shift		# get rid of "hostname"
    556   1.1        pk 		(
    557   1.1        pk 			read af name mask bcaddr extras
    558   1.1        pk 			read dt dtaddr
    559   1.1        pk 
    560   1.1        pk 			if [ ! -n "$name" ]; then
    561   1.1        pk 		    echo "/etc/hostname.$1: invalid network configuration file"
    562   1.1        pk 				exit
    563   1.1        pk 			fi
    564   1.1        pk 
    565   1.1        pk 			cmd="ifconfig $1 $af $name "
    566   1.1        pk 			if [ "${dt}" = "dest" ]; then cmd="$cmd $dtaddr"; fi
    567   1.1        pk 			if [ -n "$mask" ]; then cmd="$cmd netmask $mask"; fi
    568  1.47  christos 			if [ "${bcaddr:-NONE}" != "NONE" ]; then
    569   1.1        pk 				cmd="$cmd broadcast $bcaddr";
    570   1.1        pk 			fi
    571   1.1        pk 			cmd="$cmd $extras"
    572   1.1        pk 
    573   1.1        pk 			$cmd
    574   1.1        pk 		) < /mnt/etc/hostname.$1
    575   1.1        pk 		shift
    576   1.1        pk 	done
    577   1.1        pk )
    578  1.16        pk fi
    579   1.1        pk 
    580   1.1        pk 	# set the address for the loopback interface
    581   1.1        pk 	ifconfig lo0 inet localhost
    582   1.1        pk 
    583   1.1        pk 	# use loopback, not the wire
    584   1.1        pk 	route add $hostname localhost
    585   1.1        pk 
    586   1.1        pk 	# /etc/mygate, if it exists, contains the name of my gateway host
    587   1.1        pk 	# that name must be in /etc/hosts.
    588   1.1        pk 	if [ -f /mnt/etc/mygate ]; then
    589   1.1        pk 		route delete default > /dev/null 2>&1
    590  1.47  christos 		route add default $(cat /mnt/etc/mygate)
    591   1.1        pk 	fi
    592   1.1        pk 
    593   1.1        pk 	# enable the resolver, if appropriate.
    594   1.1        pk 	if [ -f /mnt/etc/resolv.conf ]; then
    595   1.1        pk 		_resolver_enabled="TRUE"
    596   1.1        pk 		cp /mnt/etc/resolv.conf /tmp/resolv.conf.shadow
    597   1.1        pk 	fi
    598   1.1        pk 
    599   1.1        pk 	# Display results...
    600   1.1        pk 	echo	"Network interface configuration:"
    601   1.1        pk 	ifconfig -a
    602   1.1        pk 
    603   1.1        pk 	echo	""
    604   1.1        pk 
    605  1.47  christos 	if [ "${_resolver_enabled:-FALSE}" = "TRUE" ]; then
    606   1.1        pk 		netstat -r
    607   1.1        pk 		echo	""
    608   1.1        pk 		echo	"Resolver enabled."
    609   1.1        pk 	else
    610   1.1        pk 		netstat -rn
    611   1.1        pk 		echo	""
    612   1.1        pk 		echo	"Resolver not enabled."
    613   1.1        pk 	fi
    614   1.1        pk 
    615   1.1        pk 	return 0
    616   1.1        pk }
    617   1.1        pk 
    618   1.1        pk install_ftp() {
    619  1.21       leo 	local	_f
    620  1.21       leo 	local	_sets
    621  1.21       leo 	local	_next
    622  1.21       leo 
    623  1.21       leo 	# Build a script to extract valid files from a list
    624  1.21       leo 	# of filenames on stdin.
    625  1.21       leo 	# XXX : Can we use this on more places? Leo.
    626  1.21       leo 
    627  1.21       leo 	echo "#!/bin/sh" > /tmp/fname_filter.sh
    628  1.21       leo 	echo "while read line; do"	>> /tmp/fname_filter.sh
    629  1.21       leo 	echo "    case \$line in"	>> /tmp/fname_filter.sh
    630  1.21       leo 	for _f in $THESETS; do
    631  1.40  fredette 		echo "    $_f.tar.gz|$_f.tgz|$_f.tar|$_f.${VERSION}.aa)" \
    632  1.21       leo 					>> /tmp/fname_filter.sh
    633  1.21       leo 		echo '        echo -n "$line ";;' \
    634  1.21       leo 					>> /tmp/fname_filter.sh
    635  1.21       leo 	done
    636  1.21       leo 	echo "        *) ;;"		>> /tmp/fname_filter.sh
    637  1.21       leo 	echo "    esac"			>> /tmp/fname_filter.sh
    638  1.21       leo 	echo "done"			>> /tmp/fname_filter.sh
    639  1.21       leo 
    640   1.1        pk 	# Get several parameters from the user, and create
    641   1.1        pk 	# a shell script that directs the appropriate
    642   1.1        pk 	# commands into ftp.
    643   1.1        pk 	cat << \__install_ftp_1
    644   1.1        pk 
    645   1.1        pk This is an automated ftp-based installation process.  You will be asked
    646   1.1        pk several questions.  The correct set of commands will be placed in a script
    647   1.1        pk that will be fed to ftp(1).
    648   1.1        pk 
    649   1.1        pk __install_ftp_1
    650   1.1        pk 	# Get server IP address
    651   1.1        pk 	resp=""		# force one iteration
    652  1.47  christos 	while [ -z "${resp}" ]; do
    653   1.1        pk 		echo -n "Server IP? [${_ftp_server_ip}] "
    654   1.1        pk 		getresp "${_ftp_server_ip}"
    655   1.1        pk 		_ftp_server_ip=$resp
    656   1.1        pk 	done
    657   1.1        pk 
    658   1.1        pk 	# Get login name
    659   1.1        pk 	resp=""		# force one iteration
    660  1.47  christos 	while [ -z "${resp}" ]; do
    661   1.1        pk 		echo -n "Login? [${_ftp_server_login}] "
    662   1.1        pk 		getresp "${_ftp_server_login}"
    663   1.1        pk 		_ftp_server_login=$resp 
    664   1.1        pk 	done
    665   1.1        pk 
    666   1.1        pk 	# Get password
    667   1.1        pk 	resp=""		# force one iteration
    668  1.47  christos 	while [ -z "${resp}" ]; do
    669  1.16        pk 		echo -n "Password? "
    670  1.16        pk 		stty -echo
    671  1.16        pk 		getresp ""
    672  1.16        pk 		echo ""
    673  1.16        pk 		stty echo
    674   1.1        pk 		_ftp_server_password=$resp
    675   1.1        pk 	done
    676   1.1        pk 
    677   1.1        pk 	cat << \__install_ftp_2
    678   1.1        pk 
    679  1.21       leo You will be asked to enter the name of the directory that contains the
    680  1.21       leo installation sets. When you enter a '?' you will see a listing of the
    681  1.21       leo current directory on the server.
    682  1.21       leo __install_ftp_2
    683  1.21       leo 	_sets=""
    684  1.21       leo 	while [ -z "$_sets" ]
    685  1.21       leo 	do
    686  1.21       leo 		resp=""		# force one iteration
    687  1.47  christos 		while [ -z "${resp}" ]; do
    688  1.21       leo 			echo -n "Server directory? [${_ftp_server_dir}] "
    689  1.21       leo 		    getresp "${_ftp_server_dir}"
    690  1.47  christos 		    if [ -z "$resp" ] && [ -z "$_ftp_server_dir" ]; then
    691  1.21       leo 			resp=""
    692  1.21       leo 		    fi
    693  1.21       leo 		done
    694  1.21       leo 		if [ $resp != '?' ]; then
    695  1.21       leo 			_ftp_server_dir=$resp
    696  1.21       leo 		fi
    697  1.21       leo 
    698  1.21       leo 		# Build the basics of an ftp-script...
    699  1.21       leo 		echo "#!/bin/sh" > /tmp/ftp-script.sh
    700  1.21       leo 		echo "cd /mnt" >> /tmp/ftp-script.sh
    701  1.26        is 		echo "ftp -e -i -n $_ftp_server_ip << \__end_commands" >> \
    702  1.21       leo 		    /tmp/ftp-script.sh
    703  1.21       leo 		echo "user $_ftp_server_login $_ftp_server_password" >> \
    704  1.21       leo 		    /tmp/ftp-script.sh
    705  1.21       leo 		echo "bin" >> /tmp/ftp-script.sh
    706  1.21       leo 		echo "cd $_ftp_server_dir" >> /tmp/ftp-script.sh
    707  1.21       leo 
    708  1.21       leo 		# Make a copy of this script that lists the directory
    709  1.21       leo 		# contents, and use that to determine the files to get.
    710  1.21       leo 		cat /tmp/ftp-script.sh	>  /tmp/ftp-dir.sh
    711  1.36        pk 		echo "nlist"		>> /tmp/ftp-dir.sh
    712  1.21       leo 		echo "quit"		>> /tmp/ftp-dir.sh
    713  1.21       leo 		echo "__end_commands"	>> /tmp/ftp-dir.sh
    714  1.21       leo 
    715  1.21       leo 		if [ $resp = '?' ]; then
    716  1.21       leo 			sh /tmp/ftp-dir.sh
    717  1.21       leo 		else
    718  1.47  christos 			_sets=$(sh /tmp/ftp-dir.sh | sh /tmp/fname_filter.sh)
    719  1.21       leo 		fi
    720  1.21       leo 	done
    721  1.21       leo 	rm -f /tmp/ftp-dir.sh /tmp/fname_filter.sh
    722  1.21       leo 
    723  1.21       leo 	while : ; do
    724  1.21       leo 		echo "The following sets are available for extraction:"
    725  1.27        is 		echo "(marked sets are already on the extraction list)"
    726  1.21       leo 		echo ""
    727   1.1        pk 
    728  1.21       leo 		_next=""
    729  1.21       leo 		for _f in $_sets ; do
    730  1.21       leo 			if isin $_f $_setsdone; then
    731  1.21       leo 				echo -n "[X] "
    732  1.21       leo 				_next=""
    733  1.21       leo 			else
    734  1.21       leo 				echo -n "    "
    735  1.21       leo 				if [ -z "$_next" ]; then _next=$_f; fi
    736  1.21       leo 			fi
    737  1.21       leo 			echo $_f
    738  1.21       leo 		done
    739  1.21       leo 		echo ""
    740   1.1        pk 
    741  1.21       leo 		# Get name of the file and add extraction command
    742  1.21       leo 		# to the ftp-script.
    743  1.47  christos 		if [ -z "$_next" ]; then resp=n; else resp=y; fi
    744  1.21       leo 		echo -n "Continue to add filenames [$resp]? "
    745  1.21       leo 		getresp "$resp"
    746  1.21       leo 		if [ "$resp" = "n" ]; then
    747   1.1        pk 			break
    748   1.1        pk 		fi
    749   1.1        pk 
    750  1.21       leo 		echo -n "File name [$_next]? "
    751  1.21       leo 		getresp "$_next"
    752  1.21       leo 		if isin $resp $_sets; then
    753  1.33       mrg 			echo "get $resp |\"pax -zr${verbose_flag}pe\"" >> \
    754  1.21       leo 					/tmp/ftp-script.sh
    755  1.21       leo 			_setsdone="$resp $_setsdone"
    756  1.21       leo 		else
    757  1.21       leo 			echo "You entered an invalid filename."
    758  1.21       leo 			echo ""
    759  1.21       leo 		fi
    760   1.1        pk 	done
    761   1.1        pk 
    762   1.1        pk 	echo "quit" >> /tmp/ftp-script.sh
    763   1.1        pk 	echo "__end_commands" >> /tmp/ftp-script.sh
    764   1.1        pk 
    765   1.1        pk 	sh /tmp/ftp-script.sh
    766   1.1        pk 	rm -f /tmp/ftp-script.sh
    767   1.1        pk 	echo "Extraction complete."
    768   1.1        pk }
    769   1.1        pk 
    770  1.11        pk install_from_mounted_fs() {
    771  1.13        pk 	# $1 - directory containing installation sets
    772   1.1        pk 	local _filename
    773  1.13        pk 	local _sets
    774  1.12        pk 	local _next
    775  1.29       mrg 	local _all
    776   1.1        pk 	local _f
    777  1.18        is 	local _dirname
    778   1.1        pk 
    779  1.18        is 	_dirname=$1
    780  1.13        pk 	_sets=""
    781  1.20        is 
    782  1.31       sjg 	if ! dir_has_sets ${_dirname} $THESETS
    783  1.31       sjg 	then
    784  1.20        is 
    785  1.18        is 		echo ""
    786  1.31       sjg 		echo "The directory at the mount point, \"${_dirname}\", contains: "
    787  1.18        is 		echo ""
    788  1.18        is 		ls -F ${_dirname}
    789  1.18        is 		echo ""
    790  1.31       sjg 		echo    "Enter the subdirectory relative to the mountpoint, that"
    791  1.31       sjg 		echo -n "contains the savesets: [try this directory] "
    792  1.18        is 		getresp ""
    793  1.47  christos 		if [ -n "${resp}" ]; then
    794  1.18        is 			_dirname=${_dirname}/$resp
    795  1.18        is 		fi
    796  1.31       sjg 
    797  1.31       sjg 		while ! dir_has_sets ${_dirname} $THESETS; do
    798  1.31       sjg 			echo ""
    799  1.31       sjg 			echo -n "There are no NetBSD install sets available in "
    800  1.31       sjg 			echo "\"${_dirname}\"."
    801  1.31       sjg 			echo "\"${_dirname}\" contains: "
    802  1.31       sjg 			echo ""
    803  1.31       sjg 			ls -F ${_dirname}
    804  1.31       sjg 			echo ""
    805  1.31       sjg 			echo -n "Enter subdirectory: [try other install media] "
    806  1.31       sjg 			getresp ""
    807  1.47  christos 			if [ -z "${resp}" ]; then
    808  1.31       sjg 				return
    809  1.31       sjg 			fi
    810  1.31       sjg 			if [ ! -d ${_dirname}/${resp} ]; then
    811  1.31       sjg 				echo "\"${resp}\" is no directory; try again."
    812  1.31       sjg 			else
    813  1.31       sjg 				_dirname=${_dirname}/$resp
    814  1.31       sjg 			fi
    815  1.31       sjg 		done
    816  1.31       sjg 	fi
    817  1.18        is 
    818  1.18        is 	for _f in $THESETS ; do
    819  1.18        is 		if [ -f ${_dirname}/${_f}.tar.gz ]; then
    820  1.18        is 			_sets="$_sets ${_f}.tar.gz"
    821  1.18        is 		elif [ -f ${_dirname}/${_f}.tgz ]; then
    822  1.18        is 			_sets="$_sets ${_f}.tgz"
    823  1.40  fredette 		elif [ -f ${_dirname}/${_f}.tar ]; then
    824  1.40  fredette 			_sets="$_sets ${_f}.tar"
    825  1.18        is 		elif [ -f ${_dirname}/${_f}${VERSION}.aa ]; then
    826  1.18        is 			_sets="$_sets ${_f}${VERSION}"
    827  1.18        is 		fi
    828  1.18        is 	done
    829   1.1        pk 
    830   1.1        pk 	while : ; do
    831   1.1        pk 		echo "The following sets are available for extraction:"
    832   1.1        pk 		echo "(marked sets have already been extracted)"
    833   1.1        pk 		echo ""
    834   1.1        pk 
    835  1.12        pk 		_next=""
    836  1.29       mrg 		_all=""
    837   1.1        pk 		for _f in $_sets ; do
    838   1.1        pk 			if isin $_f $_setsdone; then
    839   1.1        pk 				echo -n "[X] "
    840  1.12        pk 				_next=""
    841   1.1        pk 			else
    842   1.1        pk 				echo -n "    "
    843  1.29       mrg 				if [ -z "$_next" ]; then
    844  1.29       mrg 					_next=$_f;
    845  1.29       mrg 				fi
    846  1.29       mrg 				_all="$_all $_f"
    847   1.1        pk 			fi
    848   1.1        pk 			echo $_f
    849   1.1        pk 		done
    850   1.1        pk 		echo ""
    851   1.1        pk 
    852   1.1        pk 		# Get the name of the file.
    853  1.47  christos 		if [ -z "$_next" ]; then
    854  1.33       mrg 			resp=n
    855  1.33       mrg 		else
    856  1.33       mrg 			resp=y
    857  1.33       mrg 		fi
    858   1.1        pk 		echo -n "Continue extraction [$resp]?"
    859   1.1        pk 		getresp "$resp"
    860   1.1        pk 		if [ "$resp" = "n" ]; then
    861   1.1        pk 			break
    862   1.1        pk 		fi
    863   1.1        pk 
    864  1.29       mrg 		echo -n "File name(s) (or "all") [$_next]? "
    865  1.12        pk 		getresp "$_next"
    866  1.29       mrg 		if [ "x$resp" = xall ]; then
    867  1.29       mrg 			resp="$_all"
    868  1.29       mrg 		fi
    869  1.29       mrg 
    870  1.29       mrg 		for _f in $resp; do
    871  1.29       mrg 			_filename="/${_dirname}/$_f"
    872   1.1        pk 
    873  1.29       mrg 			# Ensure file exists
    874  1.29       mrg 			if [ ! -f $_filename ]; then
    875  1.29       mrg 				if [ -f ${_filename}.aa ]; then
    876  1.29       mrg 					_filename=${_filename}.\?\?
    877  1.29       mrg 				else
    878  1.18        is 			 echo "File $_filename does not exist.  Check to make"
    879  1.18        is 			 echo "sure you entered the information properly."
    880  1.29       mrg 			 continue 2
    881  1.29       mrg 				fi
    882  1.18        is 			fi
    883   1.1        pk 
    884  1.29       mrg 			# Extract file
    885  1.29       mrg 			echo "Extracting the $_f set:"
    886  1.40  fredette 			case "$_filename" in
    887  1.40  fredette 			*.tar)
    888  1.40  fredette 				(cd /mnt; pax -r${verbose_flag}pe < $_filename)
    889  1.40  fredette 				;;
    890  1.40  fredette 			*)
    891  1.40  fredette 				cat $_filename | \
    892  1.40  fredette 					(cd /mnt; pax -zr${verbose_flag}pe)
    893  1.40  fredette 				;;
    894  1.40  fredette 			esac
    895  1.29       mrg 			echo "Extraction complete."
    896  1.29       mrg 			_setsdone="$_f $_setsdone"
    897  1.29       mrg 		done
    898   1.1        pk 
    899   1.1        pk 	done
    900   1.1        pk }
    901   1.1        pk 
    902   1.1        pk install_cdrom() {
    903   1.5        pk 	local _drive
    904   1.6       leo 	local _partition_range
    905   1.5        pk 	local _partition
    906   1.5        pk 	local _fstype
    907   1.5        pk 	local _directory
    908   1.5        pk 
    909   1.1        pk 	# Get the cdrom device info
    910   1.1        pk 	cat << \__install_cdrom_1
    911   1.1        pk 
    912   1.1        pk The following CD-ROM devices are installed on your system; please select
    913   1.6       leo the CD-ROM device containing the partition with the installation sets:
    914   1.1        pk 
    915   1.1        pk __install_cdrom_1
    916  1.47  christos 	_CDDEVS=$(md_get_cddevs)
    917   1.1        pk 	echo    "$_CDDEVS"
    918   1.1        pk 	echo	""
    919   1.1        pk 	echo -n	"Which is the CD-ROM with the installation media? [abort] "
    920   1.1        pk 	getresp "abort"
    921   1.1        pk 	case "$resp" in
    922   1.1        pk 		abort)
    923   1.1        pk 			echo "Aborting."
    924   1.1        pk 			return
    925   1.1        pk 			;;
    926   1.1        pk 
    927   1.1        pk 		*)
    928   1.1        pk 			if isin $resp $_CDDEVS ; then
    929   1.5        pk 				_drive=$resp
    930   1.1        pk 			else
    931   1.1        pk 				echo ""
    932   1.1        pk 				echo "The CD-ROM $resp does not exist."
    933   1.1        pk 				echo "Aborting."
    934   1.1        pk 				return
    935   1.1        pk 			fi
    936   1.1        pk 			;;
    937   1.1        pk 	esac
    938   1.1        pk 
    939   1.1        pk 	# Get partition
    940  1.47  christos 	_partition_range=$(md_get_partition_range)
    941   1.1        pk 	resp=""		# force one iteration
    942  1.47  christos 	while [ -z "${resp}" ]; do
    943  1.17        is 		echo -n "Partition? [a] "
    944  1.17        is 		getresp "a"
    945   1.1        pk 		case "$resp" in
    946   1.6       leo 			$_partition_range)
    947   1.5        pk 				_partition=$resp
    948   1.1        pk 				;;
    949   1.1        pk 
    950   1.1        pk 			*)
    951   1.1        pk 				echo "Invalid response: $resp"
    952   1.1        pk 				resp=""		# force loop to repeat
    953   1.1        pk 				;;
    954   1.1        pk 		esac
    955   1.1        pk 	done
    956   1.1        pk 
    957   1.1        pk 	# Ask for filesystem type
    958   1.1        pk 	cat << \__install_cdrom_2
    959   1.1        pk 
    960   1.1        pk There are two CD-ROM filesystem types currently supported by this program:
    961   1.1        pk 	1) ISO-9660 (cd9660)
    962   1.1        pk 	2) Berkeley Fast Filesystem (ffs)
    963   1.1        pk 
    964   1.1        pk __install_cdrom_2
    965   1.1        pk 	resp=""		# force one iteration
    966  1.47  christos 	while [ -z "${resp}" ]; do
    967   1.1        pk 		echo -n "Which filesystem type? [cd9660] "
    968   1.1        pk 		getresp "cd9660"
    969   1.1        pk 		case "$resp" in
    970   1.1        pk 			cd9660|ffs)
    971   1.5        pk 				_fstype=$resp
    972   1.1        pk 				;;
    973   1.1        pk 
    974   1.1        pk 			*)
    975   1.1        pk 				echo "Invalid response: $resp"
    976   1.1        pk 				resp=""		# force loop to repeat
    977   1.1        pk 				;;
    978   1.1        pk 		esac
    979   1.1        pk 	done
    980   1.1        pk 
    981   1.1        pk 	# Mount the CD-ROM
    982  1.17        is 	if ! mount -t ${_fstype} -o ro \
    983   1.5        pk 	    /dev/${_drive}${_partition} /mnt2 ; then
    984   1.1        pk 		echo "Cannot mount CD-ROM drive.  Aborting."
    985   1.1        pk 		return
    986   1.1        pk 	fi
    987   1.1        pk 
    988  1.20        is 	install_from_mounted_fs /mnt2
    989   1.5        pk 	umount -f /mnt2 > /dev/null 2>&1
    990   1.5        pk }
    991   1.5        pk 
    992  1.14       leo mount_a_disk() {
    993  1.14       leo 	# Mount a disk on /mnt2. The set of disk devices to choose from
    994  1.14       leo 	# is $_DKDEVS.
    995  1.14       leo 	# returns 0 on failure.
    996  1.14       leo 
    997   1.5        pk 	local _drive
    998   1.6       leo 	local _partition_range
    999   1.5        pk 	local _partition
   1000   1.5        pk 	local _fstype
   1001   1.5        pk 	local _fsopts
   1002   1.5        pk 	local _directory
   1003   1.5        pk 	local _md_fstype
   1004   1.5        pk 	local _md_fsopts
   1005   1.5        pk 
   1006   1.5        pk 	getresp "abort"
   1007   1.5        pk 	case "$resp" in
   1008   1.5        pk 		abort)
   1009   1.5        pk 			echo "Aborting."
   1010  1.14       leo 			return 0
   1011   1.5        pk 			;;
   1012   1.5        pk 
   1013   1.5        pk 		*)
   1014   1.5        pk 			if isin $resp $_DKDEVS ; then
   1015   1.5        pk 				_drive=$resp
   1016   1.5        pk 			else
   1017   1.5        pk 				echo ""
   1018   1.5        pk 				echo "The disk $resp does not exist."
   1019   1.5        pk 				echo "Aborting."
   1020  1.14       leo 				return 0
   1021   1.5        pk 			fi
   1022   1.5        pk 			;;
   1023   1.5        pk 	esac
   1024   1.5        pk 
   1025   1.5        pk 	# Get partition
   1026  1.47  christos 	_partition_range=$(md_get_partition_range)
   1027   1.5        pk 	resp=""		# force one iteration
   1028  1.47  christos 	while [ -z "${resp}" ]; do
   1029   1.5        pk 		echo -n "Partition? [d] "
   1030   1.5        pk 		getresp "d"
   1031   1.5        pk 		case "$resp" in
   1032   1.6       leo 			$_partition_range)
   1033   1.5        pk 				_partition=$resp
   1034   1.5        pk 				;;
   1035   1.5        pk 
   1036   1.5        pk 			*)
   1037   1.5        pk 				echo "Invalid response: $resp"
   1038   1.5        pk 				resp=""		# force loop to repeat
   1039   1.5        pk 				;;
   1040   1.5        pk 		esac
   1041   1.5        pk 	done
   1042   1.5        pk 
   1043   1.5        pk 	# Ask for filesystem type
   1044  1.14       leo 	cat << \__mount_a_disk_2
   1045   1.5        pk 
   1046   1.5        pk The following filesystem types are supported:
   1047   1.5        pk 	1) ffs
   1048  1.46   mlelstv 	2) cd9660
   1049  1.14       leo __mount_a_disk_2
   1050  1.47  christos 	_md_fstype=$(md_native_fstype)
   1051  1.47  christos 	_md_fsopts=$(md_native_fsopts)
   1052   1.5        pk 	if [ ! -z "$_md_fstype" ]; then
   1053  1.46   mlelstv 		echo "	3) $_md_fstype"
   1054   1.5        pk 	else
   1055   1.5        pk 		_md_fstype="_undefined_"
   1056   1.5        pk 	fi
   1057   1.5        pk 	resp=""		# force one iteration
   1058  1.47  christos 	while [ -z "${resp}" ]; do
   1059   1.5        pk 		echo -n "Which filesystem type? [ffs] "
   1060   1.5        pk 		getresp "ffs"
   1061   1.5        pk 		case "$resp" in
   1062  1.46   mlelstv 			ffs|cd9660)
   1063   1.5        pk 				_fstype=$resp
   1064   1.5        pk 				_fsopts="ro"
   1065   1.5        pk 				;;
   1066   1.5        pk 			$_md_fstype)
   1067   1.5        pk 				_fstype=$resp
   1068   1.5        pk 				_fsopts=$_md_fsopts
   1069   1.5        pk 				;;
   1070   1.5        pk 			*)
   1071   1.5        pk 				echo "Invalid response: $resp"
   1072   1.5        pk 				resp=""		# force loop to repeat
   1073   1.5        pk 				;;
   1074   1.5        pk 		esac
   1075   1.5        pk 	done
   1076   1.5        pk 
   1077   1.5        pk 	# Mount the disk
   1078   1.5        pk 	if ! mount -t ${_fstype} -o $_fsopts \
   1079   1.5        pk 	    /dev/${_drive}${_partition} /mnt2 ; then
   1080   1.5        pk 		echo "Cannot mount disk.  Aborting."
   1081  1.14       leo 		return 0
   1082  1.14       leo 	fi
   1083  1.14       leo 	return 1
   1084  1.14       leo }
   1085  1.14       leo 
   1086  1.14       leo install_disk() {
   1087  1.14       leo 	local _directory
   1088  1.14       leo 
   1089  1.14       leo 	cat << \__install_disk_1
   1090  1.14       leo 
   1091  1.30       mrg Ok, lets install from a disk.  The file-system the install sets on may
   1092  1.30       mrg already mounted, or we might have to mount the filesystem to get to it.
   1093  1.30       mrg 
   1094  1.30       mrg __install_disk_1
   1095  1.30       mrg 
   1096  1.30       mrg 	echo -n "Is the file-system with the install sets already mounted? [n] "
   1097  1.30       mrg 	getresp "n"
   1098  1.30       mrg 	case $resp in
   1099  1.30       mrg 	y*|Y*)
   1100  1.30       mrg 		echo "What mount point are the sets located in? [] "
   1101  1.30       mrg 		getresp ""
   1102  1.30       mrg 		if [ -d "$resp" ]; then
   1103  1.30       mrg 			install_from_mounted_fs $resp
   1104  1.30       mrg 		else
   1105  1.30       mrg 			echo "$resp: Not a directory, aborting..."
   1106  1.30       mrg 		fi
   1107  1.30       mrg 		return
   1108  1.30       mrg 		;;
   1109  1.30       mrg 	*)
   1110  1.30       mrg 		;;
   1111  1.30       mrg 	esac
   1112  1.30       mrg 
   1113  1.30       mrg 	cat << \__install_disk_2
   1114  1.30       mrg 
   1115  1.14       leo The following disk devices are installed on your system; please select
   1116  1.14       leo the disk device containing the partition with the installation sets:
   1117  1.14       leo 
   1118  1.30       mrg __install_disk_2
   1119  1.47  christos 	_DKDEVS=$(md_get_diskdevs)
   1120  1.14       leo 	echo    "$_DKDEVS"
   1121  1.14       leo 	echo	""
   1122  1.14       leo 	echo -n	"Which is the disk with the installation sets? [abort] "
   1123  1.14       leo 
   1124  1.14       leo 	if mount_a_disk ; then
   1125   1.5        pk 		return
   1126   1.5        pk 	fi
   1127   1.5        pk 
   1128  1.20        is 	install_from_mounted_fs /mnt2
   1129   1.1        pk 	umount -f /mnt2 > /dev/null 2>&1
   1130   1.1        pk }
   1131   1.1        pk 
   1132   1.1        pk install_nfs() {
   1133   1.1        pk 	# Get the IP address of the server
   1134   1.1        pk 	resp=""		# force one iteration
   1135  1.47  christos 	while [ -z "${resp}" ]; do
   1136   1.1        pk 		echo -n "Server IP address? [${_nfs_server_ip}] "
   1137   1.1        pk 		getresp "${_nfs_server_ip}"
   1138   1.1        pk 	done
   1139   1.1        pk 	_nfs_server_ip=$resp
   1140   1.1        pk 
   1141   1.1        pk 	# Get server path to mount
   1142   1.1        pk 	resp=""		# force one iteration
   1143  1.47  christos 	while [ -z "${resp}" ]; do
   1144   1.1        pk 		echo -n "Filesystem on server to mount? [${_nfs_server_path}] "
   1145   1.1        pk 		getresp "${_nfs_server_path}"
   1146   1.1        pk 	done
   1147   1.1        pk 	_nfs_server_path=$resp
   1148   1.1        pk 
   1149   1.1        pk 	# Determine use of TCP
   1150   1.1        pk 	echo -n "Use TCP transport (only works with capable NFS server)? [n] "
   1151   1.1        pk 	getresp "n"
   1152   1.1        pk 	case "$resp" in
   1153   1.1        pk 		y*|Y*)
   1154   1.1        pk 			_nfs_tcp="-T"
   1155   1.1        pk 			;;
   1156   1.1        pk 
   1157   1.1        pk 		*)
   1158  1.40  fredette 			echo -n "Use small NFS transfers (needed when server "
   1159  1.40  fredette 			echo "or client"
   1160  1.40  fredette 			echo -n "has a slow network card)? [n] "
   1161  1.40  fredette 			getresp "n"
   1162  1.40  fredette 			case "$resp" in
   1163  1.40  fredette 			y*|Y*)
   1164  1.40  fredette 				_nfs_tcp="-r 1024 -w 1024"
   1165  1.40  fredette 				;;
   1166  1.40  fredette 
   1167  1.40  fredette 			*)
   1168  1.40  fredette 				_nfs_tcp=""
   1169  1.40  fredette 				;;
   1170  1.40  fredette 			esac
   1171   1.1        pk 			;;
   1172   1.1        pk 	esac
   1173   1.1        pk 
   1174   1.1        pk 	# Mount the server
   1175   1.1        pk 	mkdir /mnt2 > /dev/null 2>&1
   1176   1.1        pk 	if ! mount_nfs $_nfs_tcp ${_nfs_server_ip}:${_nfs_server_path} \
   1177   1.1        pk 	    /mnt2 ; then
   1178   1.1        pk 		echo "Cannot mount NFS server.  Aborting."
   1179   1.1        pk 		return
   1180   1.1        pk 	fi
   1181   1.1        pk 
   1182  1.20        is 	install_from_mounted_fs /mnt2
   1183   1.1        pk 	umount -f /mnt2 > /dev/null 2>&1
   1184   1.1        pk }
   1185   1.1        pk 
   1186   1.1        pk install_tape() {
   1187  1.11        pk 	local _xcmd
   1188  1.11        pk 
   1189   1.1        pk 	# Get the name of the tape from the user.
   1190   1.1        pk 	cat << \__install_tape_1
   1191   1.1        pk 
   1192   1.1        pk The installation program needs to know which tape device to use.  Make
   1193   1.1        pk sure you use a "no rewind on close" device.
   1194   1.1        pk 
   1195   1.1        pk __install_tape_1
   1196  1.47  christos 	_tape=$(basename $TAPE)
   1197   1.1        pk 	resp=""		# force one iteration
   1198  1.47  christos 	while [ -z "${resp}" ]; do
   1199   1.1        pk 		echo -n "Name of tape device? [${_tape}]"
   1200   1.1        pk 		getresp "${_tape}"
   1201   1.1        pk 	done
   1202  1.47  christos 	_tape=$(basename $resp)
   1203   1.1        pk 	TAPE="/dev/${_tape}"
   1204   1.1        pk 	if [ ! -c $TAPE ]; then
   1205   1.1        pk 		echo "$TAPE does not exist or is not a character special file."
   1206   1.1        pk 		echo "Aborting."
   1207   1.1        pk 		return
   1208   1.1        pk 	fi
   1209   1.1        pk 	export TAPE
   1210   1.1        pk 
   1211   1.1        pk 	# Rewind the tape device
   1212   1.1        pk 	echo -n "Rewinding tape..."
   1213   1.1        pk 	if ! mt rewind ; then
   1214   1.1        pk 		echo "$TAPE may not be attached to the system or may not be"
   1215   1.1        pk 		echo "a tape device.  Aborting."
   1216   1.1        pk 		return
   1217   1.1        pk 	fi
   1218   1.1        pk 	echo "done."
   1219   1.1        pk 
   1220   1.1        pk 	# Get the file number
   1221   1.1        pk 	resp=""		# force one iteration
   1222  1.47  christos 	while [ -z "${resp}" ]; do
   1223   1.1        pk 		echo -n "File number? "
   1224   1.1        pk 		getresp ""
   1225   1.1        pk 		case "$resp" in
   1226   1.1        pk 			[1-9]*)
   1227  1.47  christos 				_nskip=$(expr $resp - 1)
   1228   1.1        pk 				;;
   1229   1.1        pk 
   1230   1.1        pk 			*)
   1231   1.1        pk 				echo "Invalid file number ${resp}."
   1232   1.1        pk 				resp=""		# fore loop to repeat
   1233   1.1        pk 				;;
   1234   1.1        pk 		esac
   1235   1.1        pk 	done
   1236   1.1        pk 
   1237   1.1        pk 	# Skip to correct file.
   1238   1.1        pk 	echo -n "Skipping to source file..."
   1239  1.47  christos 	if [ "${_nskip}" != "0" ]; then
   1240   1.1        pk 		if ! mt fsf $_nskip ; then
   1241   1.1        pk 			echo "Could not skip $_nskip files.  Aborting."
   1242   1.1        pk 			return
   1243   1.1        pk 		fi
   1244   1.1        pk 	fi
   1245   1.1        pk 	echo "done."
   1246   1.1        pk 
   1247   1.1        pk 	cat << \__install_tape_2
   1248   1.1        pk 
   1249   1.1        pk There are 2 different ways the file can be stored on tape:
   1250   1.1        pk 
   1251   1.1        pk 	1) an image of a gzipped tar file
   1252   1.1        pk 	2) a standard tar image
   1253   1.1        pk 
   1254   1.1        pk __install_tape_2
   1255   1.1        pk 	resp=""		# force one iteration
   1256  1.47  christos 	while [ -z "${resp}" ]; do
   1257   1.1        pk 		echo -n "Which way is it? [1] "
   1258   1.1        pk 		getresp "1"
   1259   1.1        pk 		case "$resp" in
   1260  1.11        pk 		1)
   1261  1.33       mrg 			_xcmd="pax -zr${verbose_flag}pe"
   1262  1.11        pk 			;;
   1263   1.1        pk 
   1264  1.11        pk 		2)
   1265  1.33       mrg 			_xcmd="pax -r${verbose_flag}pe"
   1266  1.11        pk 			;;
   1267   1.1        pk 
   1268  1.11        pk 		*)
   1269  1.11        pk 			echo "Invalid response: $resp."
   1270  1.11        pk 			resp=""		# force loop to repeat
   1271  1.11        pk 			;;
   1272   1.1        pk 		esac
   1273  1.11        pk 		( cd /mnt; dd if=$TAPE | $_xcmd )
   1274   1.1        pk 	done
   1275   1.1        pk 	echo "Extraction complete."
   1276   1.1        pk }
   1277   1.1        pk 
   1278   1.1        pk get_timezone() {
   1279   1.1        pk 	local _a
   1280   1.6       leo 	local _zonepath
   1281   1.6       leo 
   1282   1.6       leo 	#
   1283   1.6       leo 	# If the zoneinfo is not on the installation medium or on the
   1284   1.6       leo 	# installed filesystem, set TZ to GMT and return immediatly.
   1285   1.6       leo 	#
   1286  1.47  christos 	if [ ! -e /usr/share/zoneinfo ] && [ ! -e /mnt/usr/share/zoneinfo ]; then
   1287   1.6       leo 		TZ=GMT
   1288   1.6       leo 		return
   1289   1.6       leo 	fi
   1290   1.6       leo 	if [ ! -d /usr/share/zoneinfo ]; then
   1291   1.6       leo 		_zonepath=/mnt
   1292   1.6       leo 	else
   1293   1.6       leo 		_zonepath=""
   1294   1.6       leo 	fi
   1295   1.6       leo 		
   1296   1.1        pk cat << \__get_timezone_1
   1297   1.1        pk 
   1298   1.1        pk Select a time zone for your location. Timezones are represented on the
   1299  1.42   nathanw system by a directory structure rooted in "/usr/share/zoneinfo". Most
   1300   1.1        pk timezones can be selected by entering a token like "MET" or "GMT-6".
   1301   1.1        pk Other zones are grouped by continent, with detailed zone information
   1302   1.1        pk separated by a slash ("/"), e.g. "US/Pacific".
   1303   1.1        pk 
   1304   1.1        pk To get a listing of what's available in /usr/share/zoneinfo, enter "?"
   1305   1.1        pk at the prompts below.
   1306   1.1        pk 
   1307   1.1        pk __get_timezone_1
   1308  1.48  christos 	if [ -z "$TZ" ]; then
   1309  1.47  christos 		TZ=$(ls -l /mnt/etc/localtime 2>/dev/null | cutlast)
   1310   1.3        pk 		TZ=${TZ#/usr/share/zoneinfo/}
   1311   1.1        pk 	fi
   1312   1.1        pk 	while :; do
   1313  1.47  christos 		echo -n	"What timezone are you in ['?' for list] [$TZ]? "
   1314   1.1        pk 		getresp "$TZ"
   1315   1.1        pk 		case "$resp" in
   1316   1.1        pk 		"")
   1317   1.1        pk 			echo "Timezone defaults to GMT"
   1318   1.1        pk 			TZ="GMT"
   1319   1.1        pk 			break;
   1320   1.1        pk 			;;
   1321   1.1        pk 		"?")
   1322   1.6       leo 			ls ${_zonepath}/usr/share/zoneinfo
   1323   1.1        pk 			;;
   1324   1.1        pk 		*)
   1325   1.1        pk 			_a=$resp
   1326   1.6       leo 			while [ -d ${_zonepath}/usr/share/zoneinfo/$_a ]; do
   1327   1.1        pk 				echo -n "There are several timezones available"
   1328   1.1        pk 				echo " within zone '$_a'"
   1329  1.47  christos 				echo -n "Select a sub-timezone ['?' for list]: "
   1330   1.1        pk 				getresp ""
   1331   1.1        pk 				case "$resp" in
   1332   1.6       leo 				"?") ls ${_zonepath}/usr/share/zoneinfo/$_a ;;
   1333   1.1        pk 				*)	_a=${_a}/${resp}
   1334   1.6       leo 					if [ -f ${_zonepath}/usr/share/zoneinfo/$_a ]; then
   1335   1.1        pk 						break;
   1336   1.1        pk 					fi
   1337   1.1        pk 					;;
   1338   1.1        pk 				esac
   1339   1.1        pk 			done
   1340   1.6       leo 			if [ -f ${_zonepath}/usr/share/zoneinfo/$_a ]; then
   1341   1.1        pk 				TZ="$_a"
   1342   1.1        pk 				echo "You have selected timezone \"$_a\"".
   1343   1.1        pk 				break 2
   1344   1.1        pk 			fi
   1345   1.1        pk 			echo "'/usr/share/zoneinfo/$_a' is not a valid timezone on this system."
   1346   1.1        pk 			;;
   1347   1.1        pk 		esac
   1348   1.1        pk 	done
   1349   1.1        pk }
   1350   1.1        pk 
   1351   1.1        pk install_sets()
   1352   1.1        pk {
   1353  1.13        pk 	local _yup
   1354  1.13        pk 	_yup="FALSE"
   1355  1.13        pk 
   1356  1.13        pk 	# Ask the user which media to load the distribution from.
   1357  1.33       mrg 	# Ask the user if they want verbose extraction.  They might not want
   1358  1.33       mrg 	# it on, eg, SPARC frame buffer console.
   1359  1.13        pk 	cat << \__install_sets_1
   1360   1.1        pk 
   1361   1.1        pk It is now time to extract the installation sets onto the hard disk.
   1362  1.10   thorpej Make sure the sets are either on a local device (i.e. tape, CD-ROM) or on a
   1363   1.1        pk network server.
   1364   1.1        pk 
   1365  1.33       mrg Would you like to see each file listed during extraction (verbose) mode?
   1366  1.33       mrg On some console hardware, such as serial consoles and Sun frame buffers,
   1367  1.33       mrg this can extend the total extraction time.
   1368   1.1        pk __install_sets_1
   1369  1.33       mrg 	echo -n "Use verbose listing for extractions? [y] "
   1370  1.33       mrg 	getresp "y"
   1371  1.33       mrg 	case "$resp" in
   1372  1.33       mrg 	y*|Y*)
   1373  1.33       mrg 		verbose_flag=v
   1374  1.33       mrg 		;;
   1375  1.33       mrg 	*)
   1376  1.37        is 		echo "Not using verbose listing."
   1377  1.33       mrg 		verbose_flag=""
   1378  1.33       mrg 		;;
   1379  1.33       mrg 	esac
   1380  1.13        pk 
   1381  1.31       sjg 	if [ -d ${Default_sets_dir:-/dev/null} ]; then
   1382  1.31       sjg 		if dir_has_sets $Default_sets_dir $THESETS; then
   1383  1.31       sjg 			local_sets_dir=$Default_sets_dir
   1384  1.31       sjg 		fi
   1385  1.31       sjg 	fi
   1386  1.47  christos 	if [ -n "${local_sets_dir}" ]; then
   1387  1.13        pk 		install_from_mounted_fs ${local_sets_dir}
   1388  1.48  christos 		if [ -n "$_setsdone" ]; then
   1389  1.13        pk 			_yup="TRUE"
   1390  1.13        pk 		fi
   1391  1.13        pk 	fi
   1392  1.13        pk 
   1393  1.13        pk 	# Go on prodding for alternate locations
   1394  1.13        pk 	resp=""		# force at least one iteration
   1395  1.48  christos 	while [ -z "${resp}" ]; do
   1396  1.13        pk 		# If _yup is not FALSE, it means that we extracted sets above.
   1397  1.13        pk 		# If that's the case, bypass the menu the first time.
   1398  1.48  christos 		if [ "${_yup}" = "FALSE" ]; then
   1399  1.13        pk 			echo -n	"Install from (f)tp, (t)ape, (C)D-ROM, (N)FS"
   1400  1.13        pk 			echo -n " or local (d)isk? "
   1401  1.13        pk 			getresp ""
   1402   1.1        pk 			case "$resp" in
   1403  1.13        pk 			d*|D*)
   1404  1.13        pk 				install_disk
   1405  1.13        pk 				;;
   1406  1.13        pk 			f*|F*)
   1407  1.13        pk 				install_ftp
   1408  1.13        pk 				;;
   1409  1.13        pk 			t*|T*)
   1410  1.13        pk 				install_tape
   1411  1.13        pk 				;;
   1412  1.13        pk 			c*|C*)
   1413  1.13        pk 				install_cdrom
   1414  1.13        pk 				;;
   1415  1.13        pk 			n*|N*)
   1416  1.13        pk 				install_nfs
   1417   1.1        pk 				;;
   1418   1.1        pk 			*)
   1419  1.13        pk 				echo "Invalid response: $resp"
   1420  1.13        pk 				resp=""
   1421   1.1        pk 				;;
   1422   1.1        pk 			esac
   1423  1.13        pk 		else
   1424  1.13        pk 			_yup="FALSE"	# So we'll ask next time
   1425  1.13        pk 		fi
   1426   1.1        pk 
   1427  1.13        pk 		# Give the user the opportunity to extract more sets. They
   1428  1.13        pk 		# don't necessarily have to come from the same media.
   1429  1.13        pk 		echo	""
   1430  1.13        pk 		echo -n	"Extract more sets? [n] "
   1431  1.13        pk 		getresp "n"
   1432   1.1        pk 		case "$resp" in
   1433  1.13        pk 		y*|Y*)
   1434  1.13        pk 			# Force loop to repeat
   1435  1.13        pk 			resp=""
   1436   1.1        pk 			;;
   1437   1.1        pk 
   1438   1.1        pk 		*)
   1439   1.1        pk 			;;
   1440   1.1        pk 		esac
   1441  1.13        pk 	done
   1442   1.1        pk }
   1443   1.1        pk 
   1444   1.1        pk munge_fstab()
   1445   1.1        pk {
   1446   1.1        pk 	local _fstab
   1447   1.1        pk 	local _fstab_shadow
   1448   1.5        pk 	local _dev
   1449   1.5        pk 	local _mp
   1450   1.7       leo 	local _fstype
   1451   1.5        pk 	local _rest
   1452   1.6       leo 
   1453   1.1        pk 	# Now that the 'real' fstab is configured, we munge it into a 'shadow'
   1454   1.1        pk 	# fstab which we'll use for mounting and unmounting all of the target
   1455   1.1        pk 	# filesystems relative to /mnt.  Mount all filesystems.
   1456   1.1        pk 	_fstab=$1
   1457   1.1        pk 	_fstab_shadow=$2
   1458   1.7       leo 	( while read _dev _mp _fstype _rest; do
   1459   1.7       leo 		# Skip comment lines
   1460   1.7       leo 		case "$_dev" in
   1461   1.7       leo 			\#*)	continue;;
   1462   1.7       leo 			*)	;;
   1463   1.7       leo 		esac
   1464   1.7       leo 		# and some filesystem types (like there are swap,kernfs,...)
   1465   1.7       leo 		case "$_fstype" in
   1466   1.7       leo 			ffs|ufs|nfs)	;;
   1467   1.7       leo 			*)	continue;;
   1468   1.7       leo 		esac
   1469   1.3        pk 		if [ "$_mp" = "/" ]; then
   1470   1.8        pk 			echo $_dev /mnt $_fstype $_rest
   1471   1.1        pk 		else
   1472   1.8        pk 			echo $_dev /mnt$_mp $_fstype $_rest
   1473   1.3        pk 		fi
   1474   1.6       leo 	    done ) < $_fstab > $_fstab_shadow
   1475   1.1        pk }
   1476   1.1        pk 
   1477   1.1        pk mount_fs()
   1478   1.1        pk {
   1479   1.1        pk 	# Must mount filesystems manually, one at a time, so we can make
   1480   1.1        pk 	# sure the mount points exist.
   1481   1.1        pk 	# $1 is a file in fstab format
   1482   1.1        pk 	local _fstab
   1483   1.1        pk 
   1484   1.1        pk 	_fstab=$1
   1485   1.1        pk 
   1486   1.1        pk 	( while read line; do
   1487   1.4        pk 		set -- $line
   1488   1.4        pk 		_dev=$1
   1489   1.4        pk 		_mp=$2
   1490   1.4        pk 		_fstype=$3
   1491   1.4        pk 		_opt=$4
   1492   1.1        pk 
   1493   1.1        pk 		# If not the root filesystem, make sure the mount
   1494   1.1        pk 		# point is present.
   1495  1.47  christos 		if [ "$_mp" != "/mnt" ]; then
   1496   1.1        pk 			mkdir -p $_mp
   1497   1.1        pk 		fi
   1498   1.1        pk 
   1499   1.1        pk 		# Mount the filesystem.  If the mount fails, exit
   1500   1.1        pk 		# with an error condition to tell the outer
   1501   1.1        pk 		# later to bail.
   1502  1.29       mrg 		if ! mount -v -t $_fstype -o async -o $_opt $_dev $_mp ; then
   1503   1.1        pk 			# error message displated by mount
   1504   1.1        pk 			exit 1
   1505   1.1        pk 		fi
   1506   1.1        pk 	done ) < $_fstab
   1507   1.1        pk 
   1508  1.47  christos 	if [ "$?" != "0" ]; then
   1509   1.1        pk 		cat << \__mount_filesystems_1
   1510   1.1        pk 
   1511   1.1        pk FATAL ERROR:  Cannot mount filesystems.  Double-check your configuration
   1512   1.1        pk and restart the installation process.
   1513   1.1        pk __mount_filesystems_1
   1514   1.1        pk 		exit
   1515   1.1        pk 	fi
   1516   1.1        pk }
   1517   1.1        pk 
   1518   1.1        pk unmount_fs()
   1519   1.1        pk {
   1520   1.1        pk 	# Unmount all filesystems and check their integrity.
   1521  1.13        pk 	# Usage: [-fast] <fstab file>
   1522  1.13        pk 	local _fast
   1523   1.1        pk 	local _fstab
   1524  1.13        pk 	local _pid
   1525  1.13        pk 
   1526  1.13        pk 	if [ "$1" = "-fast" ]; then
   1527  1.13        pk 		_fast=1
   1528  1.13        pk 		_fstab=$2
   1529  1.13        pk 	else
   1530  1.13        pk 		_fast=0
   1531  1.13        pk 		_fstab=$1
   1532  1.13        pk 	fi
   1533   1.1        pk 
   1534  1.13        pk 	if [ ! \( -f $_fstab -a -s $_fstab \) ]; then
   1535  1.13        pk 		echo "fstab empty" > /dev/tty
   1536  1.13        pk 		return
   1537  1.13        pk 	fi
   1538   1.1        pk 
   1539  1.13        pk 	if [ $_fast = 0 ]; then
   1540  1.13        pk 		echo -n	"Syncing disks..."
   1541  1.47  christos 		_pid=$(twiddle)
   1542  1.13        pk 		sync; sleep 4; sync; sleep 2; sync; sleep 2
   1543  1.13        pk 		kill $_pid
   1544  1.13        pk 		echo	"done."
   1545  1.13        pk 	fi
   1546   1.1        pk 
   1547   1.1        pk 	(
   1548   1.1        pk 		_devs=""
   1549   1.1        pk 		_mps=""
   1550   1.1        pk 		# maintain reverse order
   1551   1.1        pk 		while read line; do
   1552   1.3        pk 			set -- $line
   1553   1.3        pk 			_devs="$1 ${_devs}"
   1554   1.3        pk 			_mps="$2 ${_mps}"
   1555   1.1        pk 		done
   1556   1.1        pk 		echo -n "Umounting filesystems... "
   1557   1.1        pk 		for _mp in ${_mps}; do
   1558   1.1        pk 			echo -n "${_mp} "
   1559   1.1        pk 			umount ${_mp}
   1560   1.1        pk 		done
   1561   1.1        pk 		echo "Done."
   1562   1.1        pk 
   1563  1.13        pk 		if [ $_fast = 0 ]; then
   1564  1.13        pk 			exit
   1565  1.13        pk 		fi
   1566   1.1        pk 		echo "Checking filesystem integrity..."
   1567   1.1        pk 		for _dev in ${_devs}; do
   1568   1.1        pk 			echo  "${_dev}"
   1569   1.1        pk 			fsck -f ${_dev}
   1570   1.1        pk 		done
   1571   1.1        pk 		echo "Done."
   1572   1.1        pk 	) < $_fstab
   1573   1.1        pk }
   1574   1.1        pk 
   1575   1.1        pk check_fs()
   1576   1.1        pk {
   1577   1.1        pk 	# Check filesystem integrity.
   1578   1.1        pk 	# $1 is a file in fstab format
   1579   1.1        pk 	local _fstab
   1580   1.1        pk 
   1581   1.1        pk 	_fstab=$1
   1582   1.1        pk 
   1583   1.1        pk 	(
   1584   1.1        pk 		_devs=""
   1585   1.1        pk 		_mps=""
   1586   1.1        pk 		while read line; do
   1587   1.3        pk 			set -- $line
   1588   1.3        pk 			_devs="$1 ${_devs}"
   1589   1.3        pk 			_mps="$2 ${_mps}"
   1590   1.1        pk 		done
   1591   1.1        pk 
   1592   1.1        pk 		echo "Checking filesystem integrity..."
   1593   1.1        pk 		for _dev in ${_devs}; do
   1594   1.1        pk 			echo  "${_dev}"
   1595   1.1        pk 			fsck -f ${_dev}
   1596   1.1        pk 		done
   1597   1.1        pk 		echo "Done."
   1598   1.1        pk 	) < $_fstab
   1599   1.1        pk }
   1600  1.48  christos 
   1601  1.48  christos mi_mount_kernfs() {
   1602  1.48  christos 	# Make sure kernfs is mounted.
   1603  1.48  christos 	if [ ! -d /kern ] || [ ! -e /kern/msgbuf ]; then
   1604  1.48  christos 		mkdir /kern > /dev/null 2>&1
   1605  1.48  christos 		/sbin/mount_kernfs /kern /kern
   1606  1.48  christos 	fi
   1607  1.48  christos }
   1608  1.48  christos 
   1609  1.48  christos mi_filter_msgbuf() {
   1610  1.48  christos 	# Remove timestemps, sort.
   1611  1.48  christos 	sed -e 's/^\[[0-9. ]*\] //' < /kern/msgbuf | sort -u
   1612  1.48  christos }
   1613  1.48  christos 
   1614  1.48  christos mi_filter_dmesg() {
   1615  1.48  christos 	# Remove timestemps, sort.
   1616  1.48  christos 	dmesg | awk '{ h=$0; gsub("^\[[0-9. ]*\] ", "", h); print h; }' \
   1617  1.48  christos 	    | sort -u
   1618  1.48  christos }
   1619