install.sh revision 1.8 1 1.1 chopps #!/bin/sh
2 1.8 cgd # $NetBSD: install.sh,v 1.8 2000/06/14 17:24:11 cgd Exp $
3 1.1 chopps #
4 1.1 chopps # Copyright (c) 1994 Christopher G. Demetriou
5 1.1 chopps # All rights reserved.
6 1.8 cgd #
7 1.1 chopps # Redistribution and use in source and binary forms, with or without
8 1.1 chopps # modification, are permitted provided that the following conditions
9 1.1 chopps # are met:
10 1.1 chopps # 1. Redistributions of source code must retain the above copyright
11 1.1 chopps # notice, this list of conditions and the following disclaimer.
12 1.1 chopps # 2. Redistributions in binary form must reproduce the above copyright
13 1.1 chopps # notice, this list of conditions and the following disclaimer in the
14 1.1 chopps # documentation and/or other materials provided with the distribution.
15 1.1 chopps # 3. All advertising materials mentioning features or use of this software
16 1.1 chopps # must display the following acknowledgement:
17 1.8 cgd # This product includes software developed for the
18 1.8 cgd # NetBSD Project. See http://www.netbsd.org/ for
19 1.8 cgd # information about NetBSD.
20 1.1 chopps # 4. The name of the author may not be used to endorse or promote products
21 1.8 cgd # derived from this software without specific prior written permission.
22 1.8 cgd #
23 1.1 chopps # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.1 chopps # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.1 chopps # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.1 chopps # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.1 chopps # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.1 chopps # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.1 chopps # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.1 chopps # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.1 chopps # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.1 chopps # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.8 cgd #
34 1.8 cgd # <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
35 1.1 chopps
36 1.1 chopps # NetBSD installation script.
37 1.1 chopps # In a perfect world, this would be a nice C program, with a reasonable
38 1.1 chopps # user interface.
39 1.1 chopps
40 1.1 chopps FSTABDIR=/mnt/etc # /mnt/etc
41 1.2 chopps #DONTDOIT==echo
42 1.1 chopps
43 1.4 chopps VERSION=1.2
44 1.1 chopps FSTAB=${FSTABDIR}/fstab
45 1.1 chopps
46 1.1 chopps getresp() {
47 1.1 chopps read resp
48 1.1 chopps if [ "X$resp" = "X" ]; then
49 1.1 chopps resp=$1
50 1.1 chopps fi
51 1.1 chopps }
52 1.1 chopps
53 1.2 chopps getvar() {
54 1.2 chopps echo $(eval $(echo "echo \$$1"))
55 1.2 chopps }
56 1.2 chopps
57 1.2 chopps shiftvar() {
58 1.2 chopps local - var
59 1.2 chopps var="$1"
60 1.2 chopps list="$(getvar $var)"
61 1.2 chopps set -- $list
62 1.2 chopps shift
63 1.2 chopps setvar $var "$*"
64 1.2 chopps }
65 1.2 chopps
66 1.2 chopps getparts() {
67 1.2 chopps disklabel $1 2>/dev/null | sed -e '/^[ ][ ][ad-p]/!d' |
68 1.2 chopps sed -e 's,^[ ]*\([a-p]\):[ ]*[0-9]*[ ]*[0-9]*[ ][ ]*\([a-zA-Z0-9.]*\).*,\1 \2,' |
69 1.2 chopps sed -e ':a
70 1.2 chopps N;${s/\n/ /g;p;d;}
71 1.2 chopps ba'
72 1.2 chopps }
73 1.2 chopps
74 1.2 chopps getdrives() {
75 1.2 chopps local du thispart
76 1.2 chopps for du in /dev/r${drivetype}?a; do
77 1.2 chopps dd if=$du of=/dev/null bs=1b count=1 >/dev/null 2>&1
78 1.2 chopps if [ $? -eq 0 ]; then
79 1.2 chopps thisunit=`echo $du | sed -e 's,/dev/r\(...\)a,\1,g'`
80 1.2 chopps driveunits="$driveunits $thisunit"
81 1.2 chopps else
82 1.2 chopps continue;
83 1.2 chopps fi
84 1.2 chopps setvar $thisunit "$(getparts $thisunit)"
85 1.2 chopps export $thisunit
86 1.2 chopps done
87 1.2 chopps export drivenunits
88 1.2 chopps }
89 1.2 chopps
90 1.2 chopps prepdrive() {
91 1.2 chopps echo "which drive would you like to prepare next?"
92 1.2 chopps echo "choices are: ${driveunits}"
93 1.2 chopps echo ""
94 1.2 chopps getresp
95 1.2 chopps case $resp in
96 1.2 chopps *) ;;
97 1.2 chopps esac
98 1.2 chopps }
99 1.2 chopps
100 1.1 chopps echo "Welcome to the NetBSD ${VERSION} installation program."
101 1.1 chopps echo ""
102 1.1 chopps echo "This program is designed to help you put NetBSD on your hard disk,"
103 1.2 chopps echo "in a simple and rational way. Its main objective is to format,"
104 1.2 chopps echo "mount and create an fstab for your root (/) and user (/usr)"
105 1.2 chopps echo "partitions."
106 1.1 chopps echo ""
107 1.1 chopps echo "As with anything which modifies your hard drive's contents, this"
108 1.1 chopps echo "program can cause SIGNIFICANT data loss, and you are advised"
109 1.1 chopps echo "to make sure your hard drive is backed up before beginning the"
110 1.1 chopps echo "installation process."
111 1.1 chopps echo ""
112 1.2 chopps echo "Default answers are displayed in brackets after the questions."
113 1.1 chopps echo "You can hit Control-C at any time to quit, but if you do so at a"
114 1.1 chopps echo "prompt, you may have to hit return. Also, quitting in the middle of"
115 1.1 chopps echo "installation may leave your system in an inconsistent state."
116 1.1 chopps echo ""
117 1.1 chopps echo -n "Proceed with installation? [n] "
118 1.1 chopps getresp "n"
119 1.1 chopps case "$resp" in
120 1.1 chopps y*|Y*)
121 1.2 chopps echo "scanning for the root device"
122 1.1 chopps ;;
123 1.1 chopps *)
124 1.1 chopps echo ""
125 1.1 chopps echo "OK, then. Enter 'halt' at the prompt to halt the"
126 1.1 chopps echo "machine. Once the machine has halted, remove the"
127 1.1 chopps echo "floppy and press any key to reboot."
128 1.1 chopps exit
129 1.1 chopps ;;
130 1.1 chopps esac
131 1.1 chopps
132 1.2 chopps drivetype=sd
133 1.2 chopps sect_fwd=""
134 1.1 chopps
135 1.1 chopps # find out what units are possible for that disk, and query the user.
136 1.2 chopps getdrives
137 1.2 chopps for du in $driveunits; do
138 1.2 chopps set -- $(getvar $du)
139 1.2 chopps if [ $# -ge 2 -a "$1" = "a" -a "`echo $2 | sed -e 's,.*BSD.*,BSD,'`" = "BSD" ]; then
140 1.2 chopps rdev=$du
141 1.2 chopps fi
142 1.2 chopps done
143 1.1 chopps
144 1.1 chopps echo ""
145 1.2 chopps echo "The following root devices are available on your machine:"
146 1.2 chopps echo " "${driveunits}
147 1.2 chopps echo ""
148 1.2 chopps prefdev=${rdev}
149 1.2 chopps rdev=""
150 1.2 chopps while [ "X${rdev}" = "X" ]; do
151 1.2 chopps echo -n "Which device would you like to install on ? [${prefdev}] "
152 1.2 chopps getresp ${prefdev}
153 1.1 chopps otherdrives=`echo "${driveunits}" | sed -e s,${resp},,`
154 1.1 chopps if [ "X${driveunits}" = "X${otherdrives}" ]; then
155 1.1 chopps echo ""
156 1.2 chopps echo "\"${resp}\" is an invalid drive name. Valid choices"
157 1.1 chopps echo "are: "${driveunits}
158 1.1 chopps else
159 1.2 chopps rdev=${resp}
160 1.1 chopps fi
161 1.1 chopps done
162 1.1 chopps
163 1.1 chopps echo ""
164 1.2 chopps echo "The root device you have chosen is on: ${rdev}"
165 1.1 chopps echo ""
166 1.2 chopps # driveunits=`ls /dev/${drivetype}?a | sed -e 's,/dev/\(...\)a,\1,g'`
167 1.2 chopps if [ "X${driveunits}" = "X" ]; then
168 1.2 chopps echo "FATAL ERROR:"
169 1.2 chopps echo "No devices for disks of type '${drivetype}'."
170 1.2 chopps echo "This is probably a bug in the install disks."
171 1.2 chopps echo "Exiting install program."
172 1.2 chopps exit
173 1.1 chopps fi
174 1.1 chopps
175 1.1 chopps echo ""
176 1.1 chopps echo "THIS IS YOUR LAST CHANCE!!!"
177 1.1 chopps echo ""
178 1.2 chopps echo "(answering yes will format your root partition on $rdev)"
179 1.1 chopps echo -n "Are you SURE you want NetBSD installed on your hard drive? (yes/no) "
180 1.1 chopps answer=""
181 1.1 chopps while [ "$answer" = "" ]; do
182 1.1 chopps getresp
183 1.1 chopps case $resp in
184 1.1 chopps yes|YES)
185 1.1 chopps echo ""
186 1.1 chopps answer=yes
187 1.1 chopps ;;
188 1.1 chopps no|NO)
189 1.1 chopps echo ""
190 1.1 chopps echo -n "OK, then. enter 'halt' to halt the machine. "
191 1.1 chopps echo "Once the machine has halted,"
192 1.1 chopps echo -n "remove the floppy, and press any key to "
193 1.1 chopps echo "reboot."
194 1.1 chopps exit
195 1.1 chopps ;;
196 1.1 chopps *)
197 1.1 chopps echo -n "I want a yes or no answer... well? "
198 1.1 chopps ;;
199 1.1 chopps esac
200 1.1 chopps done
201 1.2 chopps echo "Initializing / (root) filesystem, and mounting..."
202 1.2 chopps $DONTDOIT newfs /dev/r${rdev}a $name
203 1.2 chopps $DONTDOIT mount -v /dev/${rdev}a /mnt
204 1.2 chopps echo ""
205 1.2 chopps echo -n "Creating a fstab..."
206 1.2 chopps mkdir -p $FSTABDIR
207 1.3 chopps echo "/dev/${rdev}a / ffs rw 1 1" > $FSTAB
208 1.1 chopps
209 1.2 chopps # get rid of this partition
210 1.2 chopps shiftvar $rdev
211 1.2 chopps shiftvar $rdev
212 1.2 chopps
213 1.2 chopps echo ""
214 1.2 chopps echo "Now lets setup your /usr file system"
215 1.2 chopps echo "(Once a valid input for drive and partition is seen"
216 1.2 chopps echo "it will be FORMATTED and inserted in the fstab.)"
217 1.2 chopps while [ "X$usrpart" = "X" ]; do
218 1.2 chopps resp=""
219 1.2 chopps drivename=""
220 1.2 chopps while [ "X$resp" = "X" ]; do
221 1.2 chopps echo "choices: $driveunits"
222 1.2 chopps echo "which drive do you want /usr on?"
223 1.2 chopps getresp
224 1.2 chopps set -- $driveunits
225 1.2 chopps while [ $# -gt 0 ]; do
226 1.2 chopps if [ "X$resp" = "X$1" ]; then
227 1.2 chopps drivename=$1
228 1.2 chopps break;
229 1.2 chopps else
230 1.2 chopps shift
231 1.2 chopps fi
232 1.2 chopps done
233 1.2 chopps if [ "X$drivename" != "X" ]; then
234 1.2 chopps break
235 1.2 chopps fi
236 1.2 chopps done
237 1.1 chopps
238 1.2 chopps usrpart=""
239 1.2 chopps echo "You have selected $drivename"
240 1.2 chopps echo "here is a list of partitions on $drivename"
241 1.2 chopps disklabel $drivename 2>/dev/null | sed -e '/^[ ][ ][ad-p]:/p;/^#[ \t]*size/p;d'
242 1.2 chopps echo "which partition would you like to format and have"
243 1.2 chopps echo -n "mounted as /usr? (supply the letter): "
244 1.2 chopps getresp
245 1.2 chopps if [ "X$resp" = "X" ]; then
246 1.2 chopps continue;
247 1.2 chopps fi
248 1.1 chopps
249 1.2 chopps list=$(getvar $drivename)
250 1.2 chopps set -- $list
251 1.2 chopps while [ $# -gt 0 ]; do
252 1.2 chopps if [ "$resp" = "$1" ]; then
253 1.2 chopps if [ "`echo $2 | sed -e 's,.*BSD.*,BSD,'`" != "BSD" ]; then
254 1.2 chopps echo ""
255 1.2 chopps echo -n "$drivename$resp is of type $2 which is not"
256 1.2 chopps echo " a BSD filesystem type"
257 1.2 chopps break
258 1.2 chopps fi
259 1.2 chopps usrpart=$drivename$resp
260 1.2 chopps break
261 1.2 chopps else
262 1.2 chopps shift
263 1.2 chopps shift
264 1.2 chopps fi
265 1.2 chopps done
266 1.2 chopps if [ "X$usrpart" = "X" ]; then
267 1.2 chopps echo "$resp is not a valid input."
268 1.2 chopps echo ""
269 1.2 chopps fi
270 1.2 chopps done
271 1.1 chopps
272 1.2 chopps echo ""
273 1.2 chopps echo "Initializing /usr filesystem, and mounting..."
274 1.2 chopps $DONTDOIT newfs /dev/r${usrpart} $name
275 1.2 chopps $DONTDOIT mkdir -p /mnt/usr
276 1.2 chopps $DONTDOIT mount -v /dev/${usrpart} /mnt/usr
277 1.2 chopps echo ""
278 1.2 chopps echo -n "Adding to fstab..."
279 1.3 chopps echo "/dev/${usrpart} /usr ffs rw 1 2" >> $FSTAB
280 1.1 chopps sync
281 1.1 chopps echo " done."
282 1.1 chopps
283 1.1 chopps echo ""
284 1.1 chopps echo "OK! The preliminary work of setting up your disk is now complete,"
285 1.1 chopps echo "and you can install the actual NetBSD software."
286 1.1 chopps echo ""
287 1.2 chopps echo "Right now, your root is mounted on /mnt and your usr on /mnt/usr."
288 1.2 chopps echo "You should consult the installation notes to determine how to load"
289 1.2 chopps echo "and install the NetBSD distribution sets, and how to configure your"
290 1.2 chopps echo "system when you are done."
291 1.1 chopps echo ""
292 1.1 chopps echo "GOOD LUCK!"
293 1.1 chopps echo ""
294