install.sh revision 1.2 1 1.1 leo #!/bin/sh
2 1.2 martin # $NetBSD: install.sh,v 1.2 2008/04/30 13:10:48 martin Exp $
3 1.1 leo #
4 1.1 leo # Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.1 leo # All rights reserved.
6 1.1 leo #
7 1.1 leo # This code is derived from software contributed to The NetBSD Foundation
8 1.1 leo # by Jason R. Thorpe.
9 1.1 leo #
10 1.1 leo # Redistribution and use in source and binary forms, with or without
11 1.1 leo # modification, are permitted provided that the following conditions
12 1.1 leo # are met:
13 1.1 leo # 1. Redistributions of source code must retain the above copyright
14 1.1 leo # notice, this list of conditions and the following disclaimer.
15 1.1 leo # 2. Redistributions in binary form must reproduce the above copyright
16 1.1 leo # notice, this list of conditions and the following disclaimer in the
17 1.1 leo # documentation and/or other materials provided with the distribution.
18 1.1 leo #
19 1.1 leo # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 leo # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 leo # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 leo # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 leo # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 leo # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 leo # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 leo # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 leo # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 leo # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 leo # POSSIBILITY OF SUCH DAMAGE.
30 1.1 leo #
31 1.1 leo
32 1.1 leo # NetBSD installation script.
33 1.1 leo # In a perfect world, this would be a nice C program, with a reasonable
34 1.1 leo # user interface.
35 1.1 leo
36 1.1 leo FILESYSTEMS="/tmp/filesystems" # used thoughout
37 1.1 leo MODE="install"
38 1.1 leo
39 1.1 leo # include machine-dependent functions
40 1.1 leo # The following functions must be provided:
41 1.1 leo # md_prep_disklabel() - label the root disk
42 1.1 leo # md_welcome_banner() - display friendly message
43 1.1 leo # md_congrats() - display friendly message
44 1.1 leo # md_makerootwritable() - make root writable (at least /tmp)
45 1.1 leo
46 1.1 leo # we need to make sure .'s below work if this directory is not in $PATH
47 1.1 leo # dirname may not be available but expr is
48 1.1 leo Mydir=`expr $0 : '^\(.*\)/[^/]*$'`
49 1.1 leo Mydir=`cd ${Mydir:-.}; pwd`
50 1.1 leo
51 1.1 leo #
52 1.1 leo # Sub-parts
53 1.1 leo #
54 1.1 leo getresp() {
55 1.1 leo read resp
56 1.1 leo if [ "X$resp" = "X" ]; then
57 1.1 leo resp=$1
58 1.1 leo fi
59 1.1 leo }
60 1.1 leo
61 1.1 leo isin() {
62 1.1 leo # test the first argument against the remaining ones, return succes on a match
63 1.1 leo _a=$1; shift
64 1.1 leo while [ $# != 0 ]; do
65 1.1 leo if [ "$_a" = "$1" ]; then return 0; fi
66 1.1 leo shift
67 1.1 leo done
68 1.1 leo return 1
69 1.1 leo }
70 1.1 leo
71 1.1 leo getrootdisk() {
72 1.1 leo cat << \__getrootdisk_1
73 1.1 leo
74 1.1 leo The installation program needs to know which disk to consider
75 1.1 leo the root disk. Note the unit number may be different than
76 1.1 leo the unit number you used in the standalone installation
77 1.1 leo program.
78 1.1 leo
79 1.1 leo Available disks are:
80 1.1 leo
81 1.1 leo __getrootdisk_1
82 1.1 leo _DKDEVS=`md_get_diskdevs`
83 1.1 leo echo "$_DKDEVS"
84 1.1 leo echo ""
85 1.1 leo echo -n "Which disk is the root disk? "
86 1.1 leo getresp ""
87 1.1 leo if isin $resp $_DKDEVS ; then
88 1.1 leo ROOTDISK="$resp"
89 1.1 leo else
90 1.1 leo echo ""
91 1.1 leo echo "The disk $resp does not exist."
92 1.1 leo ROOTDISK=""
93 1.1 leo fi
94 1.1 leo }
95 1.1 leo
96 1.1 leo labelmoredisks() {
97 1.1 leo cat << \__labelmoredisks_1
98 1.1 leo
99 1.1 leo You may label the following disks:
100 1.1 leo
101 1.1 leo __labelmoredisks_1
102 1.1 leo echo "$_DKDEVS"
103 1.1 leo echo ""
104 1.1 leo echo -n "Label which disk? [done] "
105 1.1 leo getresp "done"
106 1.1 leo case "$resp" in
107 1.1 leo "done")
108 1.1 leo ;;
109 1.1 leo
110 1.1 leo *)
111 1.1 leo if isin $resp $_DKDEVS ; then
112 1.1 leo md_labeldisk $resp
113 1.1 leo else
114 1.1 leo echo ""
115 1.1 leo echo "The disk $resp does not exist."
116 1.1 leo fi
117 1.1 leo ;;
118 1.1 leo esac
119 1.1 leo }
120 1.1 leo
121 1.1 leo #
122 1.1 leo # include machine dependent subroutines
123 1.1 leo . $Mydir/install.md
124 1.1 leo
125 1.1 leo # Good {morning,afternoon,evening,night}.
126 1.1 leo md_welcome_banner
127 1.1 leo echo -n "Proceed? [n] "
128 1.1 leo getresp "n"
129 1.1 leo case "$resp" in
130 1.1 leo y*|Y*)
131 1.1 leo echo "Cool! Let's get to it..."
132 1.1 leo ;;
133 1.1 leo *)
134 1.1 leo md_not_going_to_install
135 1.1 leo exit
136 1.1 leo ;;
137 1.1 leo esac
138 1.1 leo
139 1.1 leo # XXX Work around vnode aliasing bug (thanks for the tip, Chris...)
140 1.1 leo ls -l /dev > /dev/null 2>&1
141 1.1 leo
142 1.1 leo # Deal with terminal issues
143 1.1 leo md_set_term
144 1.1 leo
145 1.1 leo # Make sure we can write files (at least in /tmp)
146 1.1 leo # This might make an MFS mount on /tmp, or it may
147 1.1 leo # just re-mount the root with read-write enabled.
148 1.1 leo md_makerootwritable
149 1.1 leo
150 1.1 leo while [ "X${ROOTDISK}" = "X" ]; do
151 1.1 leo getrootdisk
152 1.1 leo done
153 1.1 leo
154 1.1 leo # Deal with disklabels, including editing the root disklabel
155 1.1 leo # and labeling additional disks. This is machine-dependent since
156 1.1 leo # some platforms may not be able to provide this functionality.
157 1.1 leo md_prep_disklabel ${ROOTDISK}
158 1.1 leo
159 1.1 leo # Pat on the back.
160 1.1 leo md_congrats
161 1.1 leo
162 1.1 leo # ALL DONE!
163 1.1 leo exit 0
164