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