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