Annotation of src/distrib/miniroot/install.sub, Revision 1.5.2.4
1.1 pk 1: #!/bin/sh
1.5.2.4 ! pk 2: # $NetBSD: install.sub,v 1.5.2.3 1996/06/25 07:43:53 thorpej 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: # 3. All advertising materials mentioning features or use of this software
19: # must display the following acknowledgement:
1.2 thorpej 20: # This product includes software developed by the NetBSD
21: # Foundation, Inc. and its contributors.
22: # 4. Neither the name of The NetBSD Foundation nor the names of its
23: # contributors may be used to endorse or promote products derived
24: # from this software without specific prior written permission.
1.1 pk 25: #
1.2 thorpej 26: # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27: # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28: # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29: # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
30: # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31: # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32: # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33: # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34: # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35: # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36: # POSSIBILITY OF SUCH DAMAGE.
1.1 pk 37: #
38:
39: # NetBSD installation/upgrade script - common subroutines.
40:
41: ROOTDISK="" # filled in below
1.5.2.1 pk 42: VERSION= # filled in automatically (see list)
43: export VERSION
1.1 pk 44:
45: ALLSETS="base comp etc games man misc text" # default install sets
46: UPGRSETS="base comp games man misc text" # default upgrade sets
47:
1.5.2.1 pk 48: # decide upon an editor
49: if [ X$EDITOR = X ]; then
50: if [ -x /usr/bin/vi ]; then
51: EDITOR=vi
52: else
53: EDITOR=ed
54: fi
55: fi
56:
1.1 pk 57: getresp() {
58: read resp
59: if [ "X$resp" = "X" ]; then
60: resp=$1
61: fi
62: }
63:
64: isin() {
65: # test the first argument against the remaining ones, return succes on a match
66: _a=$1; shift
67: while [ $# != 0 ]; do
68: if [ "$_a" = "$1" ]; then return 0; fi
69: shift
70: done
71: return 1
72: }
73:
74: rmel() {
75: # remove first argument from list formed by the remaining arguments
1.5.2.1 pk 76: local _a
77:
1.1 pk 78: _a=$1; shift
79: while [ $# != 0 ]; do
80: if [ "$_a" != "$1" ]; then
81: echo "$1";
82: fi
83: shift
84: done
85: }
86:
1.3 pk 87: cutword () {
88: # read a line of data, return Nth element.
89: local _a
90: local _n
1.4 pk 91: local _oifs
92:
93: # optional field separator
94: _oifs="$IFS"
95: case "$1" in
1.5.2.1 pk 96: -t?*) IFS=${1#-t}; shift;;
1.4 pk 97: esac
98:
1.3 pk 99: _n=$1
100: read _a; set -- $_a
1.4 pk 101: IFS="$_oifs"
1.3 pk 102: if [ "$1" = "" ]; then return; fi
103: eval echo \$$_n
104: }
105:
106: cutlast () {
107: # read a line of data, return last element. Equiv. of awk '{print $NF}'.
108: local _a
1.4 pk 109: local _oifs
110:
111: # optional field separator
112: _oifs="$IFS"
113: case "$1" in
1.5.2.1 pk 114: -t?*) IFS=${1#-t}; shift;;
1.4 pk 115: esac
116:
1.3 pk 117: read _a; set -- $_a
1.4 pk 118: IFS="$_oifs"
1.3 pk 119: if [ "$1" = "" ]; then return; fi
1.5 pk 120: while [ "$#" -gt 10 ]; do shift 10; done
1.3 pk 121: eval echo \$$#
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"
141: while [ "$#" -gt 10 ]; do shift 10; done
142: eval echo \$$#
143: }
144:
1.5.2.1 pk 145: dir_has_sets() {
146: # return true when the directory $1 contains a set for $2...$n
147: local _dir
148: local _file
149:
150: _dir=$1; shift
151: for _file in $*
152: do
153: if [ -f $_dir/${_file}.tar.gz ]; then
154: return 0
155: fi
156: done
157: return 1
158: }
159:
1.1 pk 160: twiddle() {
161: # spin the propeller so we don't get bored
162: while : ; do
163: sleep 1; echo -n "/";
164: sleep 1; echo -n "-";
165: sleep 1; echo -n "\\";
166: sleep 1; echo -n "|";
167: done > /dev/tty & echo $!
168: }
169:
170: do_mfs_mount() {
171: # $1 is the mount point
172: # $2 is the size in DEV_BIZE blocks
173:
174: umount $1 > /dev/null 2>&1
175: if ! mount_mfs -s $2 swap $1 ; then
176: cat << \__mfs_failed_1
177:
178: FATAL ERROR: Can't mount the memory filesystem.
179:
180: __mfs_failed_1
181: exit
182: fi
183:
184: # Bleh. Give mount_mfs a chance to DTRT.
185: sleep 2
186: }
187:
188: getrootdisk() {
189: cat << \__getrootdisk_1
190:
191: The installation program needs to know which disk to consider
192: the root disk. Note the unit number may be different than
193: the unit number you used in the standalone installation
194: program.
195:
196: Available disks are:
197:
198: __getrootdisk_1
199: _DKDEVS=`md_get_diskdevs`
200: echo "$_DKDEVS"
201: echo ""
202: echo -n "Which disk is the root disk? "
203: getresp ""
204: if isin $resp $_DKDEVS ; then
205: ROOTDISK="$resp"
206: else
207: echo ""
208: echo "The disk $resp does not exist."
209: ROOTDISK=""
210: fi
211: }
212:
213: labelmoredisks() {
214: cat << \__labelmoredisks_1
215:
216: You may label the following disks:
217:
218: __labelmoredisks_1
219: echo "$_DKDEVS"
220: echo ""
221: echo -n "Label which disk? [done] "
222: getresp "done"
223: case "$resp" in
224: done)
225: ;;
226:
227: *)
1.5 pk 228: if isin $resp $_DKDEVS ; then
1.1 pk 229: md_labeldisk $resp
230: else
231: echo ""
232: echo "The disk $resp does not exist."
233: fi
234: ;;
235: esac
236: }
237:
238: addhostent() {
239: # $1 - IP address
240: # $2 - symbolic name
241:
242: # Create an entry in the hosts table. If no host table
243: # exists, create one. If the IP address already exists,
244: # replace it's entry.
245: if [ ! -f /tmp/hosts ]; then
246: echo "127.0.0.1 localhost" > /tmp/hosts
247: fi
248:
1.3 pk 249: sed "/^$1 /d" < /tmp/hosts > /tmp/hosts.new
250: mv /tmp/hosts.new /tmp/hosts
1.1 pk 251:
252: echo "$1 $2 $2.$FQDN" >> /tmp/hosts
253: }
254:
255: addifconfig() {
256: # $1 - interface name
257: # $2 - interface symbolic name
258: # $3 - interface IP address
259: # $4 - interface netmask
260:
261: # Create a hostname.* file for the interface.
262: echo "inet $2 $4" > /tmp/hostname.$1
263:
264: addhostent $3 $2
265: }
266:
267: configurenetwork() {
268: local _ifsdone
269: local _ifs
270:
271: _IFS=`md_get_ifdevs`
272: _ifsdone=""
273: resp="" # force at least one iteration
274: while [ "X${resp}" != X"done" ]; do
275: cat << \__configurenetwork_1
276:
277: You may configure the following network interfaces (the interfaces
278: marked with [X] have been succesfully configured):
279:
280: __configurenetwork_1
281:
282: for _ifs in $_IFS; do
283: if isin $_ifs $_ifsdone ; then
284: echo -n "[X] "
285: else
286: echo -n " "
287: fi
288: echo $_ifs
289: done
290: echo ""
291: echo -n "Configure which interface? [done] "
292: getresp "done"
293: case "$resp" in
294: "done")
295: ;;
296: *)
297: _ifs=$resp
298: if isin $_ifs $_IFS ; then
299: if configure_ifs $_ifs ; then
300: _ifsdone="$_ifs $_ifsdone"
301: fi
302: else
303: echo "Invalid response: \"$resp\" is not in list"
304: fi
305: ;;
306: esac
307: done
308: }
309:
310: configure_ifs() {
311:
1.5.2.1 pk 312: local _up
313: local _interface_name
314: local _interface_ip
315: local _interface_mask
316: local _interface_symname
317:
1.1 pk 318: _interface_name=$1
319:
1.5.2.1 pk 320: set -- `ifconfig $_interface_name | sed -n '
321: 1s/.*<UP,.*$/UP/p
322: 1s/.*<.*>*$/DOWN/p
323: 2s/inet//
324: 2s/--> [0-9.][0-9.]*//
325: 2s/netmask//
326: 2s/broadcast//
327: 2p'`
328:
329: _up=$1
330: _interface_ip=$2
331: _interface_mask=$3
332:
1.1 pk 333: # Get IP address
334: resp="" # force one iteration
335: while [ "X${resp}" = X"" ]; do
1.5.2.1 pk 336: echo -n "IP address? [$_interface_ip] "
337: getresp "$_interface_ip"
1.1 pk 338: _interface_ip=$resp
339: done
340:
341: # Get symbolic name
342: resp="" # force one iteration
343: while [ "X${resp}" = X"" ]; do
344: echo -n "Symbolic (host) name? "
345: getresp ""
346: _interface_symname=$resp
347: done
348:
349: # Get netmask
350: resp="" # force one iteration
351: while [ "X${resp}" = X"" ]; do
1.5.2.1 pk 352: echo -n "Netmask? [$_interface_mask] "
353: getresp "$_interface_mask"
1.1 pk 354: _interface_mask=$resp
355: done
356:
357: # Configure the interface. If it
358: # succeeds, add it to the permanent
359: # network configuration info.
1.5.2.1 pk 360: if [ $_up != "UP" ]; then
361: ifconfig ${_interface_name} down
362: if ifconfig ${_interface_name} inet \
363: ${_interface_ip} \
364: netmask ${_interface_mask} up ; then
365: addifconfig \
366: ${_interface_name} \
367: ${_interface_symname} \
368: ${_interface_ip} \
369: ${_interface_mask}
370: return 0
371: fi
372: else
373: echo "Interface ${_interface_name} is already active."
374: echo "Just saving configuration on new root filesystem."
1.1 pk 375: addifconfig \
376: ${_interface_name} \
377: ${_interface_symname} \
378: ${_interface_ip} \
379: ${_interface_mask}
380: fi
381: return 1
382: }
383:
384: # Much of this is gratuitously stolen from /etc/netstart.
385: enable_network() {
386:
387: # Set up the hostname.
388: if [ ! -f /mnt/etc/myname ]; then
389: echo "ERROR: no /etc/myname!"
390: return 1
391: fi
392: hostname=`cat /mnt/etc/myname`
393: hostname $hostname
394:
395: # configure all the interfaces which we know about.
396: (
397: tmp="$IFS"
398: IFS="$IFS."
399: set -- `echo /mnt/etc/hostname*`
400: IFS=$tmp
401: unset tmp
402:
403: while [ $# -ge 2 ] ; do
404: shift # get rid of "hostname"
405: (
406: read af name mask bcaddr extras
407: read dt dtaddr
408:
409: if [ ! -n "$name" ]; then
410: echo "/etc/hostname.$1: invalid network configuration file"
411: exit
412: fi
413:
414: cmd="ifconfig $1 $af $name "
415: if [ "${dt}" = "dest" ]; then cmd="$cmd $dtaddr"; fi
416: if [ -n "$mask" ]; then cmd="$cmd netmask $mask"; fi
417: if [ -n "$bcaddr" -a "X$bcaddr" != "XNONE" ]; then
418: cmd="$cmd broadcast $bcaddr";
419: fi
420: cmd="$cmd $extras"
421:
422: $cmd
423: ) < /mnt/etc/hostname.$1
424: shift
425: done
426: )
427:
428: # set the address for the loopback interface
429: ifconfig lo0 inet localhost
430:
431: # use loopback, not the wire
432: route add $hostname localhost
433:
434: # /etc/mygate, if it exists, contains the name of my gateway host
435: # that name must be in /etc/hosts.
436: if [ -f /mnt/etc/mygate ]; then
437: route delete default > /dev/null 2>&1
438: route add default `cat /mnt/etc/mygate`
439: fi
440:
441: # enable the resolver, if appropriate.
442: if [ -f /mnt/etc/resolv.conf ]; then
443: _resolver_enabled="TRUE"
444: cp /mnt/etc/resolv.conf /tmp/resolv.conf.shadow
445: fi
446:
447: # Display results...
448: echo "Network interface configuration:"
449: ifconfig -a
450:
451: echo ""
452:
453: if [ "X${_resolver_enabled}" = X"TRUE" ]; then
454: netstat -r
455: echo ""
456: echo "Resolver enabled."
457: else
458: netstat -rn
459: echo ""
460: echo "Resolver not enabled."
461: fi
462:
463: return 0
464: }
465:
466: install_ftp() {
467: # Get several parameters from the user, and create
468: # a shell script that directs the appropriate
469: # commands into ftp.
470: cat << \__install_ftp_1
471:
472: This is an automated ftp-based installation process. You will be asked
473: several questions. The correct set of commands will be placed in a script
474: that will be fed to ftp(1).
475:
476: __install_ftp_1
477: # Get server IP address
478: resp="" # force one iteration
479: while [ "X${resp}" = X"" ]; do
480: echo -n "Server IP? [${_ftp_server_ip}] "
481: getresp "${_ftp_server_ip}"
482: _ftp_server_ip=$resp
483: done
484:
485: # Get server directory
486: resp="" # force one iteration
487: while [ "X${resp}" = X"" ]; do
488: echo -n "Server directory? [${_ftp_server_dir}] "
489: getresp "${_ftp_server_dir}"
490: _ftp_server_dir=$resp
491: done
492:
493: # Get login name
494: resp="" # force one iteration
495: while [ "X${resp}" = X"" ]; do
496: echo -n "Login? [${_ftp_server_login}] "
497: getresp "${_ftp_server_login}"
498: _ftp_server_login=$resp
499: done
500:
501: # Get password
502: resp="" # force one iteration
503: while [ "X${resp}" = X"" ]; do
504: echo -n "Password? [${_ftp_server_password}] "
505: getresp "${_ftp_server_password}"
506: _ftp_server_password=$resp
507: done
508:
509: # Get list of files for mget.
510: cat << \__install_ftp_2
511:
512: You will now be asked for files to extract. Enter one file at a time.
513: When you are done entering files, enter 'done'.
514:
515: __install_ftp_2
516: echo "#!/bin/sh" > /tmp/ftp-script.sh
517: echo "cd /mnt" >> /tmp/ftp-script.sh
518: echo "ftp -i -n $_ftp_server_ip << \__end_commands" >> \
519: /tmp/ftp-script.sh
520: echo "user $_ftp_server_login $_ftp_server_password" >> \
521: /tmp/ftp-script.sh
522: echo "bin" >> /tmp/ftp-script.sh
523: echo "cd $_ftp_server_dir" >> /tmp/ftp-script.sh
524:
525: resp="" # force one interation
526: while [ "X${resp}" != X"done" ]; do
527: echo -n "File? [done] "
528: getresp "done"
529: if [ "X${resp}" = X"done" ]; then
530: break
531: fi
532:
1.3 pk 533: _ftp_file=`echo ${resp} | cutword 1'`
1.1 pk 534: echo "get ${_ftp_file} |\"tar --unlink -zxvpf -\"" >> \
535: /tmp/ftp-script.sh
536: done
537:
538: echo "quit" >> /tmp/ftp-script.sh
539: echo "__end_commands" >> /tmp/ftp-script.sh
540:
541: sh /tmp/ftp-script.sh
542: rm -f /tmp/ftp-script.sh
543: echo "Extraction complete."
544: }
545:
1.5.2.2 pk 546: install_from_mounted_fs() {
547: # expects filesystem to be installed to be mounted on `/mnt2'
548: # $1 - directory containing file (within /mnt2)
1.1 pk 549: local _filename
550: local _setsdone
1.5.2.4 ! pk 551: local _next
1.1 pk 552: local _f
553:
1.5 pk 554: _sets=`(cd /mnt2/$1; ls *.tar.gz 2> /dev/null)`
555: if [ -z "$_sets" ]; then
556: # Try for stupid msdos convention
557: _sets=`(cd /mnt2/$1; ls *.tgz 2> /dev/null)`
558: fi
1.1 pk 559: if [ -z "$_sets" ]; then
560: echo "There are no NetBSD install sets available in \"$1\""
561: return
562: fi
563:
564: _setsdone=""
565: while : ; do
566: echo "The following sets are available for extraction:"
567: echo "(marked sets have already been extracted)"
568: echo ""
569:
1.5.2.4 ! pk 570: _next=""
1.1 pk 571: for _f in $_sets ; do
572: if isin $_f $_setsdone; then
573: echo -n "[X] "
1.5.2.4 ! pk 574: _next=""
1.1 pk 575: else
576: echo -n " "
1.5.2.4 ! pk 577: if [ -z "$_next" ]; then _next=$_f; fi
1.1 pk 578: fi
579: echo $_f
580: done
581: echo ""
582:
583: # Get the name of the file.
1.5.2.4 ! pk 584: if [ "X$_next" = "X" ]; then resp=n; else resp=y; fi
1.1 pk 585: echo -n "Continue extraction [$resp]?"
586: getresp "$resp"
587: if [ "$resp" = "n" ]; then
588: break
589: fi
590:
1.5.2.4 ! pk 591: echo -n "File name [$_next]? "
! 592: getresp "$_next"
1.1 pk 593: _f=$resp
594: _filename="/mnt2/$1/$_f"
595:
596: # Ensure file exists
597: if [ ! -f $_filename ]; then
598: echo "File $_filename does not exist. Check to make"
599: echo "sure you entered the information properly."
600: continue
601: fi
602:
603: # Extract file
1.5 pk 604: cat $_filename | (cd /mnt; tar --unlink -zxvpf -)
1.1 pk 605: echo "Extraction complete."
606: _setsdone="$_f $_setsdone"
607:
608: done
609: }
610:
611: install_cdrom() {
1.5 pk 612: local _drive
1.5.2.1 pk 613: local _partition_range
1.5 pk 614: local _partition
615: local _fstype
616: local _directory
617:
1.1 pk 618: # Get the cdrom device info
619: cat << \__install_cdrom_1
620:
621: The following CD-ROM devices are installed on your system; please select
1.5.2.1 pk 622: the CD-ROM device containing the partition with the installation sets:
1.1 pk 623:
624: __install_cdrom_1
625: _CDDEVS=`md_get_cddevs`
626: echo "$_CDDEVS"
627: echo ""
628: echo -n "Which is the CD-ROM with the installation media? [abort] "
629: getresp "abort"
630: case "$resp" in
631: abort)
632: echo "Aborting."
633: return
634: ;;
635:
636: *)
637: if isin $resp $_CDDEVS ; then
1.5 pk 638: _drive=$resp
1.1 pk 639: else
640: echo ""
641: echo "The CD-ROM $resp does not exist."
642: echo "Aborting."
643: return
644: fi
645: ;;
646: esac
647:
648: # Get partition
1.5.2.1 pk 649: _partition_range=`md_get_partition_range`
1.1 pk 650: resp="" # force one iteration
651: while [ "X${resp}" = X"" ]; do
652: echo -n "Partition? [c] "
653: getresp "c"
654: case "$resp" in
1.5.2.1 pk 655: $_partition_range)
1.5 pk 656: _partition=$resp
1.1 pk 657: ;;
658:
659: *)
660: echo "Invalid response: $resp"
661: resp="" # force loop to repeat
662: ;;
663: esac
664: done
665:
666: # Ask for filesystem type
667: cat << \__install_cdrom_2
668:
669: There are two CD-ROM filesystem types currently supported by this program:
670: 1) ISO-9660 (cd9660)
671: 2) Berkeley Fast Filesystem (ffs)
672:
673: __install_cdrom_2
674: resp="" # force one iteration
675: while [ "X${resp}" = X"" ]; do
676: echo -n "Which filesystem type? [cd9660] "
677: getresp "cd9660"
678: case "$resp" in
679: cd9660|ffs)
1.5 pk 680: _fstype=$resp
1.1 pk 681: ;;
682:
683: *)
684: echo "Invalid response: $resp"
685: resp="" # force loop to repeat
686: ;;
687: esac
688: done
689:
690: # Mount the CD-ROM
1.5 pk 691: if ! mount -t ${_filesystem} -o ro \
692: /dev/${_drive}${_partition} /mnt2 ; then
1.1 pk 693: echo "Cannot mount CD-ROM drive. Aborting."
694: return
695: fi
696:
697: # Get the directory where the file lives
698: resp="" # force one iteration
699: while [ "X${resp}" = X"" ]; do
700: echo "Enter the directory relative to the mount point that"
1.5 pk 701: echo -n "contains the file. [${_directory}] "
702: getresp "${_directory}"
1.1 pk 703: done
1.5 pk 704: _directory=$resp
1.1 pk 705:
1.5.2.2 pk 706: install_from_mounted_fs ${_directory}
1.5 pk 707: umount -f /mnt2 > /dev/null 2>&1
708: }
709:
710: install_disk() {
711: # Get the disk device info
712: local _drive
1.5.2.1 pk 713: local _partition_range
1.5 pk 714: local _partition
715: local _fstype
716: local _fsopts
717: local _directory
718: local _md_fstype
719: local _md_fsopts
720:
721: cat << \__install_disk_1
722:
723: The following disk devices are installed on your system; please select
724: the disk device containing the partition with the installation sets:
725:
726: __install_disk_1
727: _DKDEVS=`md_get_diskdevs`
728: echo "$_DKDEVS"
729: echo ""
730: echo -n "Which is the disk with the installation sets? [abort] "
731: getresp "abort"
732: case "$resp" in
733: abort)
734: echo "Aborting."
735: return
736: ;;
737:
738: *)
739: if isin $resp $_DKDEVS ; then
740: _drive=$resp
741: else
742: echo ""
743: echo "The disk $resp does not exist."
744: echo "Aborting."
745: return
746: fi
747: ;;
748: esac
749:
750: # Get partition
1.5.2.1 pk 751: _partition_range=`md_get_partition_range`
1.5 pk 752: resp="" # force one iteration
753: while [ "X${resp}" = X"" ]; do
754: echo -n "Partition? [d] "
755: getresp "d"
756: case "$resp" in
1.5.2.1 pk 757: $_partition_range)
1.5 pk 758: _partition=$resp
759: ;;
760:
761: *)
762: echo "Invalid response: $resp"
763: resp="" # force loop to repeat
764: ;;
765: esac
766: done
767:
768: # Ask for filesystem type
769: cat << \__install_disk_2
770:
771: The following filesystem types are supported:
772: 1) ffs
773: __install_disk_2
774: _md_fstype=`md_native_fstype`
775: _md_fsopts=`md_native_fsopts`
776: if [ ! -z "$_md_fstype" ]; then
777: echo " 2) $_md_fstype"
778: else
779: _md_fstype="_undefined_"
780: fi
781: resp="" # force one iteration
782: while [ "X${resp}" = X"" ]; do
783: echo -n "Which filesystem type? [ffs] "
784: getresp "ffs"
785: case "$resp" in
786: ffs)
787: _fstype=$resp
788: _fsopts="ro"
789: ;;
790: $_md_fstype)
791: _fstype=$resp
792: _fsopts=$_md_fsopts
793: ;;
794: *)
795: echo "Invalid response: $resp"
796: resp="" # force loop to repeat
797: ;;
798: esac
799: done
800:
801: # Mount the disk
802: if ! mount -t ${_fstype} -o $_fsopts \
803: /dev/${_drive}${_partition} /mnt2 ; then
804: echo "Cannot mount disk. Aborting."
805: return
806: fi
807:
808: # Get the directory where the file lives
809: resp="" # force one iteration
810: while [ "X${resp}" = X"" ]; do
811: echo "Enter the directory relative to the mount point that"
812: echo -n "contains the file. [${_directory}] "
813: getresp "${_directory}"
814: done
815: _directory=$resp
816:
1.5.2.2 pk 817: install_from_mounted_fs ${_directory}
1.1 pk 818: umount -f /mnt2 > /dev/null 2>&1
819: }
820:
821: install_nfs() {
822: # Get the IP address of the server
823: resp="" # force one iteration
824: while [ "X${resp}" = X"" ]; do
825: echo -n "Server IP address? [${_nfs_server_ip}] "
826: getresp "${_nfs_server_ip}"
827: done
828: _nfs_server_ip=$resp
829:
830: # Get server path to mount
831: resp="" # force one iteration
832: while [ "X${resp}" = X"" ]; do
833: echo -n "Filesystem on server to mount? [${_nfs_server_path}] "
834: getresp "${_nfs_server_path}"
835: done
836: _nfs_server_path=$resp
837:
838: # Determine use of TCP
839: echo -n "Use TCP transport (only works with capable NFS server)? [n] "
840: getresp "n"
841: case "$resp" in
842: y*|Y*)
843: _nfs_tcp="-T"
844: ;;
845:
846: *)
847: _nfs_tcp=""
848: ;;
849: esac
850:
851: # Mount the server
852: mkdir /mnt2 > /dev/null 2>&1
853: if ! mount_nfs $_nfs_tcp ${_nfs_server_ip}:${_nfs_server_path} \
854: /mnt2 ; then
855: echo "Cannot mount NFS server. Aborting."
856: return
857: fi
858:
859: # Get the directory where the file lives
860: resp="" # force one iteration
861: while [ "X${resp}" = X"" ]; do
862: echo "Enter the directory relative to the mount point that"
863: echo -n "contains the file. [${_nfs_directory}] "
864: getresp "${_nfs_directory}"
865: done
866: _nfs_directory=$resp
867:
1.5.2.2 pk 868: install_from_mounted_fs ${_nfs_directory}
1.1 pk 869: umount -f /mnt2 > /dev/null 2>&1
870: }
871:
872: install_tape() {
1.5.2.2 pk 873: local _xcmd
874:
1.1 pk 875: # Get the name of the tape from the user.
876: cat << \__install_tape_1
877:
878: The installation program needs to know which tape device to use. Make
879: sure you use a "no rewind on close" device.
880:
881: __install_tape_1
882: _tape=`basename $TAPE`
883: resp="" # force one iteration
884: while [ "X${resp}" = X"" ]; do
885: echo -n "Name of tape device? [${_tape}]"
886: getresp "${_tape}"
887: done
888: _tape=`basename $resp`
889: TAPE="/dev/${_tape}"
890: if [ ! -c $TAPE ]; then
891: echo "$TAPE does not exist or is not a character special file."
892: echo "Aborting."
893: return
894: fi
895: export TAPE
896:
897: # Rewind the tape device
898: echo -n "Rewinding tape..."
899: if ! mt rewind ; then
900: echo "$TAPE may not be attached to the system or may not be"
901: echo "a tape device. Aborting."
902: return
903: fi
904: echo "done."
905:
906: # Get the file number
907: resp="" # force one iteration
908: while [ "X${resp}" = X"" ]; do
909: echo -n "File number? "
910: getresp ""
911: case "$resp" in
912: [1-9]*)
913: _nskip=`expr $resp - 1`
914: ;;
915:
916: *)
917: echo "Invalid file number ${resp}."
918: resp="" # fore loop to repeat
919: ;;
920: esac
921: done
922:
923: # Skip to correct file.
924: echo -n "Skipping to source file..."
925: if [ "X${_nskip}" != X"0" ]; then
926: if ! mt fsf $_nskip ; then
927: echo "Could not skip $_nskip files. Aborting."
928: return
929: fi
930: fi
931: echo "done."
932:
933: cat << \__install_tape_2
934:
935: There are 2 different ways the file can be stored on tape:
936:
937: 1) an image of a gzipped tar file
938: 2) a standard tar image
939:
940: __install_tape_2
941: resp="" # force one iteration
942: while [ "X${resp}" = X"" ]; do
943: echo -n "Which way is it? [1] "
944: getresp "1"
945: case "$resp" in
1.5.2.2 pk 946: 1)
947: _xcmd="tar --unlink -zxvpf -"
948: ;;
1.1 pk 949:
1.5.2.2 pk 950: 2)
951: _xcmd="tar --unlink -xvpf -"
952: ;;
1.1 pk 953:
1.5.2.2 pk 954: *)
955: echo "Invalid response: $resp."
956: resp="" # force loop to repeat
957: ;;
1.1 pk 958: esac
1.5.2.2 pk 959: ( cd /mnt; dd if=$TAPE | $_xcmd )
1.1 pk 960: done
961: echo "Extraction complete."
962: }
963:
964: get_timezone() {
965: local _a
1.5.2.1 pk 966: local _zonepath
967:
968: #
969: # If the zoneinfo is not on the installation medium or on the
970: # installed filesystem, set TZ to GMT and return immediatly.
971: #
972: if [ ! -e /usr/share/zoneinfo -a ! -e /mnt/usr/share/zoneinfo ]; then
973: TZ=GMT
974: return
975: fi
976: if [ ! -d /usr/share/zoneinfo ]; then
977: _zonepath=/mnt
978: else
979: _zonepath=""
980: fi
981:
1.1 pk 982: cat << \__get_timezone_1
983:
984: Select a time zone for your location. Timezones are represented on the
985: system by a directory structure rooted in "/usr/share/timezone". Most
986: timezones can be selected by entering a token like "MET" or "GMT-6".
987: Other zones are grouped by continent, with detailed zone information
988: separated by a slash ("/"), e.g. "US/Pacific".
989:
990: To get a listing of what's available in /usr/share/zoneinfo, enter "?"
991: at the prompts below.
992:
993: __get_timezone_1
994: if [ X$TZ = X ]; then
1.3 pk 995: TZ=`ls -l /etc/localtime 2>/dev/null | cutlast`
996: TZ=${TZ#/usr/share/zoneinfo/}
1.1 pk 997: fi
998: while :; do
999: echo -n "What timezone are you in [\`?' for list] [$TZ]? "
1000: getresp "$TZ"
1001: case "$resp" in
1002: "")
1003: echo "Timezone defaults to GMT"
1004: TZ="GMT"
1005: break;
1006: ;;
1007: "?")
1.5.2.1 pk 1008: ls ${_zonepath}/usr/share/zoneinfo
1.1 pk 1009: ;;
1010: *)
1011: _a=$resp
1.5.2.1 pk 1012: while [ -d ${_zonepath}/usr/share/zoneinfo/$_a ]; do
1.1 pk 1013: echo -n "There are several timezones available"
1014: echo " within zone '$_a'"
1015: echo -n "Select a sub-timezone [\`?' for list]: "
1016: getresp ""
1017: case "$resp" in
1.5.2.1 pk 1018: "?") ls ${_zonepath}/usr/share/zoneinfo/$_a ;;
1.1 pk 1019: *) _a=${_a}/${resp}
1.5.2.1 pk 1020: if [ -f ${_zonepath}/usr/share/zoneinfo/$_a ]; then
1.1 pk 1021: break;
1022: fi
1023: ;;
1024: esac
1025: done
1.5.2.1 pk 1026: if [ -f ${_zonepath}/usr/share/zoneinfo/$_a ]; then
1.1 pk 1027: TZ="$_a"
1028: echo "You have selected timezone \"$_a\"".
1029: break 2
1030: fi
1031: echo "'/usr/share/zoneinfo/$_a' is not a valid timezone on this system."
1032: ;;
1033: esac
1034: done
1035: }
1036:
1037: install_sets()
1038: {
1039: # arguments: the base names of the distribution sets to consider
1040: # Ask the user which media to load the distribution from.
1041: cat << \__install_sets_1
1042:
1043: It is now time to extract the installation sets onto the hard disk.
1.5.2.3 thorpej 1044: Make sure the sets are either on a local device (i.e. tape, CD-ROM) or on a
1.1 pk 1045: network server.
1046:
1047: __install_sets_1
1.5.2.1 pk 1048: if dir_has_sets "/mnt/$RELDIR" $* ; then
1049: echo -n "Are you sure to install sets from $RELDIR ? [y] "
1.1 pk 1050: getresp "y"
1051: case "$resp" in
1052: y*|Y*)
1053: for _f do
1.5.2.1 pk 1054: if [ ! -f /mnt/$RELDIR/${_f}.tar.gz ]; then
1.1 pk 1055: continue
1056: fi
1057: echo -n "Install \"$_f\" ? [y]"
1058: getresp "y"
1059: case "$resp" in
1060: y*|Y*)
1.5.2.1 pk 1061: cat /mnt/$RELDIR/${_f}.tar.gz |
1.1 pk 1062: (cd /mnt; tar --unlink -zxvpf -)
1063: _yup="TRUE"
1064: echo "Extraction complete."
1065: ;;
1066: *)
1067: echo "Skipping \"$_f\"."
1068: ;;
1069: esac
1070: done
1071: ;;
1072: *)
1073: _yup="FALSE"
1074: ;;
1075: esac
1076: else
1077: _yup="FALSE"
1078: fi
1079:
1080: # Go on prodding for alternate locations
1081: resp="" # force at least one iteration
1082: while [ "X${resp}" = X"" ]; do
1083: # If _yup is not FALSE, it means that we extracted sets above.
1084: # If that's the case, bypass the menu the first time.
1085: if [ X"$_yup" = X"FALSE" ]; then
1.5.2.1 pk 1086: echo -n "Install from (f)tp, (t)ape, (C)D-ROM, (N)FS"
1.5.2.3 thorpej 1087: echo -n " or local (d)isk? "
1.5.2.1 pk 1088: getresp ""
1.1 pk 1089: case "$resp" in
1.5 pk 1090: d*|D*)
1091: install_disk
1092: ;;
1.1 pk 1093: f*|F*)
1094: install_ftp
1095: ;;
1096:
1097: t*|T*)
1098: install_tape
1099: ;;
1100:
1101: c*|C*)
1102: install_cdrom
1103: ;;
1104:
1105: n*|N*)
1106: install_nfs
1107: ;;
1108:
1109: *)
1110: echo "Invalid response: $resp"
1111: resp=""
1112: ;;
1113: esac
1114: else
1115: _yup="FALSE" # So we'll ask next time
1116: fi
1117:
1118: # Give the user the opportunity to extract more sets. They don't
1119: # necessarily have to come from the same media.
1120: echo ""
1121: echo -n "Extract more sets? [n] "
1122: getresp "n"
1123: case "$resp" in
1124: y*|Y*)
1125: # Force loop to repeat
1126: resp=""
1127: ;;
1128:
1129: *)
1130: ;;
1131: esac
1132: done
1133: }
1134:
1135: munge_fstab()
1136: {
1137: local _fstab
1138: local _fstab_shadow
1.5 pk 1139: local _dev
1140: local _mp
1.5.2.1 pk 1141: local _fstype
1.5 pk 1142: local _rest
1.5.2.1 pk 1143:
1.1 pk 1144: # Now that the 'real' fstab is configured, we munge it into a 'shadow'
1145: # fstab which we'll use for mounting and unmounting all of the target
1146: # filesystems relative to /mnt. Mount all filesystems.
1147: _fstab=$1
1148: _fstab_shadow=$2
1.5.2.1 pk 1149: ( while read _dev _mp _fstype _rest; do
1150: # Skip comment lines
1151: case "$_dev" in
1152: \#*) continue;;
1153: *) ;;
1154: esac
1155: # and some filesystem types (like there are swap,kernfs,...)
1156: case "$_fstype" in
1157: ffs|ufs|nfs) ;;
1158: *) continue;;
1159: esac
1.3 pk 1160: if [ "$_mp" = "/" ]; then
1.5.2.1 pk 1161: echo $_dev /mnt $_fstype $_rest
1.1 pk 1162: else
1.5.2.1 pk 1163: echo $_dev /mnt$_mp $_fstype $_rest
1.3 pk 1164: fi
1.5.2.1 pk 1165: done ) < $_fstab > $_fstab_shadow
1.1 pk 1166: }
1167:
1168: mount_fs()
1169: {
1170: # Must mount filesystems manually, one at a time, so we can make
1171: # sure the mount points exist.
1172: # $1 is a file in fstab format
1173: local _fstab
1174:
1175: _fstab=$1
1176:
1177: ( while read line; do
1.4 pk 1178: set -- $line
1179: _dev=$1
1180: _mp=$2
1181: _fstype=$3
1182: _opt=$4
1.1 pk 1183:
1184: # If not the root filesystem, make sure the mount
1185: # point is present.
1186: if [ "X{$_mp}" != X"/mnt" ]; then
1187: mkdir -p $_mp
1188: fi
1189:
1190: # Mount the filesystem. If the mount fails, exit
1191: # with an error condition to tell the outer
1192: # later to bail.
1193: if ! mount -v -t $_fstype -o $_opt $_dev $_mp ; then
1194: # error message displated by mount
1195: exit 1
1196: fi
1197: done ) < $_fstab
1198:
1199: if [ "X${?}" != X"0" ]; then
1200: cat << \__mount_filesystems_1
1201:
1202: FATAL ERROR: Cannot mount filesystems. Double-check your configuration
1203: and restart the installation process.
1204: __mount_filesystems_1
1205: exit
1206: fi
1207: }
1208:
1209: unmount_fs()
1210: {
1211: # Unmount all filesystems and check their integrity.
1212: # $1 is a file in fstab format
1213: local _fstab
1214:
1215: _fstab=$1
1216:
1217: echo -n "Syncing disks..."
1218: pid=`twiddle`
1219: sync; sleep 4; sync; sleep 2; sync; sleep 2
1220: kill $pid
1221: echo "done."
1222:
1223: (
1224: _devs=""
1225: _mps=""
1226: # maintain reverse order
1227: while read line; do
1.3 pk 1228: set -- $line
1229: _devs="$1 ${_devs}"
1230: _mps="$2 ${_mps}"
1.1 pk 1231: done
1232: echo -n "Umounting filesystems... "
1233: for _mp in ${_mps}; do
1234: echo -n "${_mp} "
1235: umount ${_mp}
1236: done
1237: echo "Done."
1238:
1239: echo "Checking filesystem integrity..."
1240: for _dev in ${_devs}; do
1241: echo "${_dev}"
1242: fsck -f ${_dev}
1243: done
1244: echo "Done."
1245: ) < $_fstab
1246: }
1247:
1248: check_fs()
1249: {
1250: # Check filesystem integrity.
1251: # $1 is a file in fstab format
1252: local _fstab
1253:
1254: _fstab=$1
1255:
1256: (
1257: _devs=""
1258: _mps=""
1259: while read line; do
1.3 pk 1260: set -- $line
1261: _devs="$1 ${_devs}"
1262: _mps="$2 ${_mps}"
1.1 pk 1263: done
1264:
1265: echo "Checking filesystem integrity..."
1266: for _dev in ${_devs}; do
1267: echo "${_dev}"
1268: fsck -f ${_dev}
1269: done
1270: echo "Done."
1271: ) < $_fstab
1272: }
CVSweb <webmaster@jp.NetBSD.org>