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