install.md revision 1.22 1 # $NetBSD: install.md,v 1.22 2003/01/15 07:20:52 mhitch Exp $
2 #
3 #
4 # Copyright (c) 1996 The NetBSD Foundation, Inc.
5 # All rights reserved.
6 #
7 # This code is derived from software contributed to The NetBSD Foundation
8 # by Jason R. Thorpe.
9 #
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:
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.
25 #
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 FOUNDATION OR CONTRIBUTORS
30 # BE 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.
37 #
38
39 #
40 # machine dependent section of installation/upgrade script.
41 #
42
43 # Machine-dependent install sets
44 MDSETS="kern-GENERIC xbase xcomp xcontrib xfont xmisc xserver"
45
46 md_set_term() {
47 if [ ! -z "$TERM" ]; then
48 return
49 fi
50 echo -n "Specify terminal type [vt220]: "
51 getresp "vt220"
52 TERM="$resp"
53 export TERM
54 }
55
56 __mount_kernfs() {
57 #
58 # Force kern_fs to be mounted
59 #
60 if [ ! -d /kern -o ! -e /kern/msgbuf ]; then
61 mkdir /kern > /dev/null 2>&1
62 /sbin/mount_kernfs /kern /kern >/dev/null 2>&1
63 fi
64 }
65
66 md_makerootwritable() {
67 # Mount root rw for convenience of the tester ;-)
68 if ! cp /dev/null /tmp/.root_writable >/dev/null 2>&1; then
69 __mount_kernfs
70 # XXX: Use /kern/rootdev instead?
71 mount -t ffs -u /kern/rootdev / > /dev/null 2>&1
72 fi
73 }
74
75 md_get_diskdevs() {
76 # return available disk devices
77 __mount_kernfs
78 sed -n -e '/^[sw]d[0-9] /s/ .*//p' \
79 < /kern/msgbuf | sort -u
80 }
81
82 md_get_cddevs() {
83 # return available CDROM devices
84 __mount_kernfs
85 sed -n -e '/^cd[0-9] /s/ .*//p' \
86 < /kern/msgbuf | sort -u
87 }
88
89 md_get_partition_range() {
90 # return an expression describing the valid partition id's
91 echo '[a-p]'
92 }
93
94 md_installboot() {
95 if [ -x /mnt/usr/sbin/installboot ]; then
96 echo -n "Should a boot block be installed? [y] "
97 getresp "y"
98 case "$resp" in
99 y*|Y*)
100 echo "Installing boot block..."
101 chroot /mnt /usr/sbin/installboot /dev/r${1}a /usr/mdec/bootxx_ffs
102 cp -p /mnt/usr/mdec/boot.amiga /mnt/
103 ;;
104 *)
105 echo "No bootblock installed."
106 ;;
107 esac
108 elif [ "$MODE" = "install" ]; then
109 cat << \__md_installboot_1
110 There is no installboot program found on the installed filesystems. No boot
111 programs are installed.
112 __md_installboot_1
113 else
114 cat << \__md_installboot_2
115 There is no installboot program found on the upgraded filesystems. No boot
116 programs are installed.
117 __md_installboot_2
118 fi
119 }
120
121 md_native_fstype() {
122 echo "ados"
123 }
124
125 md_native_fsopts() {
126 echo "ro"
127 }
128
129 md_prep_disklabel() {
130 _DKDEVS=`md_get_diskdevs`
131 echo "If you like, you can now examine the labels of your disks."
132 echo ""
133 echo -n "Available are "${_DKDEVS}". Look at which? [skip this step] "
134 getresp "done"
135 while [ "X$resp" != "Xdone" ]; do
136 echo ""
137 disklabel ${resp}
138 echo ""
139 echo -n "Available are "${_DKDEVS}". Look at which? [done] "
140 getresp "done"
141 done
142 cat << \__prep_disklabel_1
143
144 As a reminder: the 'c' partition is assigned to the whole disk and can't
145 normally be used for a any file system!
146
147 __prep_disklabel_1
148 }
149
150 md_labeldisk() {
151 }
152
153 md_welcome_banner() {
154 if [ "$MODE" = "install" ]; then
155 echo ""
156 echo "Welcome to the NetBSD/amiga ${VERSION} installation program."
157 cat << \__welcome_banner_1
158
159 This program is designed to help you put NetBSD on your disk,
160 in a simple and rational way. You'll be asked several questions,
161 and it would probably be useful to have your disk's hardware
162 manual, the installation notes, and a calculator handy.
163 __welcome_banner_1
164
165 else
166 echo ""
167 echo "Welcome to the NetBSD/amiga ${VERSION} upgrade program."
168 cat << \__welcome_banner_2
169
170 This program is designed to help you upgrade your NetBSD system in a
171 simple and rational way.
172
173 As a reminder, installing the `etc' binary set is NOT recommended.
174 Once the rest of your system has been upgraded, you should manually
175 merge any changes to files in the `etc' set into those files which
176 already exist on your system.
177 __welcome_banner_2
178 fi
179
180 cat << \__welcome_banner_3
181
182 As with anything which modifies your disk's contents, this
183 program can cause SIGNIFICANT data loss, and you are advised
184 to make sure your data is backed up before beginning the
185 installation process.
186
187 Default answers are displayed in brackets after the questions.
188 You can hit Control-C at any time to quit, but if you do so at a
189 prompt, you may have to hit return. Also, quitting in the middle of
190 installation may leave your system in an inconsistent state.
191
192 __welcome_banner_3
193 }
194
195 md_not_going_to_install() {
196 cat << \__not_going_to_install_1
197
198 OK, then. Enter `halt' at the prompt to halt the machine. Once the
199 machine has halted, power-cycle the system to load new boot code.
200
201 Note: If you wish to have another try. Just type '^D' at the prompt. After
202 a moment, the installer will restart itself.
203
204 __not_going_to_install_1
205 }
206
207 md_congrats() {
208 local what;
209 if [ "$MODE" = "install" ]; then
210 what="installed";
211 else
212 what="upgraded";
213 fi
214 cat << __congratulations_1
215
216 CONGRATULATIONS! You have successfully $what NetBSD!
217 To boot the installed system, enter halt at the command prompt. Once the
218 system has halted, reset the machine and boot from the disk.
219
220 Note: If you wish to have another try. Just type '^D' at the prompt. After
221 a moment, the installer will restart itself.
222
223 __congratulations_1
224 }
225
226 md_copy_kernel() {
227 # This is largely a copy of install_disk and install_from_mounted_fs()
228 # with some special frobbing.
229
230 local _directory
231 local _sets
232 local _filename
233 local _f
234
235 if [ "$MODE" = "install" ]; then
236 echo -n "Adding keymap initialization to rc.local..."
237 echo /usr/sbin/loadkmap ${__keymap__} >> /mnt/etc/rc.local
238 echo "done."
239 fi
240
241 if [ -e /netbsd ]; then
242 if [ -e /mnt/netbsd ]; then
243 echo "On the installation filesystem there is this kernel: "
244 ls -l /netbsd
245 echo "The already installed kernel is: "
246 ls -l /mnt/netbsd
247 echo "Do you want to replace the already installed kernel by the kernel"
248 echo -n "on the installation filesystem? (y/n) [n] "
249 resp="n"
250 getresp ""
251 if [ "${resp}" != "y" -a "${resp}" != "Y" ]; then
252 return
253 fi
254 fi
255
256 echo -n "Copying kernel..."
257 cp -p /netbsd /mnt/netbsd
258 echo "done."
259 return
260 fi
261
262 cat << \__md_copy_kernel_1
263 Your installation set did not include a netbsd kernel on the installation
264 filesystem. You are now given the opportunity install it from either the
265 kernel-floppy from the distribution or another location on one of your disks.
266
267 The following disk devices are installed on your system; please select
268 the disk device containing the partition with the netbsd kernel:
269 __md_copy_kernel_1
270
271 _DKDEVS=`md_get_diskdevs`
272 echo "$_DKDEVS"
273 echo "fd0"
274 echo ""
275 _DKDEVS="$_DKDEVS fd0" # Might be on the kernel floppy!
276 echo -n "Which is the disk with the kernel? [abort] "
277
278 if mount_a_disk ; then
279 return # couldn't mount the disk
280 fi
281
282 # Get the directory where the file lives
283 resp="" # force one iteration
284 while [ "X${resp}" = X"" ]; do
285 echo "Enter the directory relative to the mount point that"
286 echo -n "contains the file. [${_directory}] "
287 getresp "${_directory}"
288 done
289 _directory=$resp
290
291 _sets=`(cd /mnt2/$_directory; ls netbsd* 2> /dev/null)`
292 if [ -z "$_sets" ]; then
293 echo "There are no NetBSD kernels available in \"$1\""
294 umount -f /mnt2 > /dev/null 2>&1
295 return
296 fi
297 while : ; do
298 echo "The following kernels are available:"
299 echo ""
300
301 for _f in $_sets ; do
302 echo " $_f"
303 done
304 echo ""
305 set -- $_sets
306 echo -n "File name [$1]? "
307 getresp "$1"
308 _f=$resp
309 _filename="/mnt2/$_directory/$_f"
310
311 # Ensure file exists
312 if [ ! -f $_filename ]; then
313 echo "File $_filename does not exist. Check to make"
314 echo "sure you entered the information properly."
315 echo -n "Do you want to retry [y]? "
316 getresp "y"
317 if [ "$resp" = "n" ]; then
318 break
319 fi
320 continue
321 fi
322
323 # Copy the kernel
324 cp $_filename /mnt
325 break
326 done
327 umount -f /mnt2 > /dev/null 2>&1
328 }
329
330 md_lib_is_aout() {
331 local r
332 test -h $1 && return 1
333 test -f $1 || return 1
334
335 r=`file $1 | sed -n -e '/ELF/p'`
336 test -z "$r" || return 1
337 return 0
338 }
339
340
341 md_mv_usr_lib() {
342 local root
343 root=$1
344 for f in $root/usr/lib/lib*.so.[0-9]*.[0-9]* ; do
345 md_lib_is_aout $f || continue
346 mv -f $f $root/emul/aout/usr/lib || return 1
347 done
348 return 0
349 }
350
351 md_x_shlib_set_14=" \
352 libICE.so.6.3 \
353 libPEX5.so.6.0 \
354 libSM.so.6.0 \
355 libX11.so.6.1 \
356 libXIE.so.6.0 \
357 libXaw.so.6.1 \
358 libXext.so.6.3 \
359 libXi.so.6.0 \
360 libXmu.so.6.0 \
361 libXp.so.6.2 \
362 libXt.so.6.0 \
363 libXtst.so.6.1 \
364 liboldX.so.6.0"
365
366 md_mv_x_lib() {
367 local root xlibdir
368 root=$1
369 xlibdir=$2
370 for f in $md_x_shlib_set_14; do
371 md_lib_is_aout $root/$xlibdir/$f || continue
372 mv -f $root/$xlibdir/$f $root/emul/aout/$xlibdir || return 1
373 done
374 return 0
375 }
376
377 md_mv_aout_libs()
378 {
379 local root xlibdir
380
381 root=/mnt # XXX - should be global
382
383 if [ -d $root/emul/aout/. ]; then
384 echo "Using existing /emul/aout directory"
385 else
386 echo "Creating /emul/aout hierachy"
387 mkdir -p $root/usr/aout || return 1
388
389 if [ ! -d $root/emul ]; then
390 mkdir $root/emul || return 1
391 fi
392
393 if [ -h $root/emul/aout ]; then
394 echo "Preserving existing symbolic link from /emul/aout"
395 mv -f $root/emul/aout $root/emul/aout.old || return 1
396 fi
397
398 ln -s ../usr/aout $root/emul/aout || return 1
399 fi
400
401 # Create /emul/aout/etc and /emul/aout/usr/lib
402 if [ ! -d $root/emul/aout/etc ]; then
403 mkdir $root/emul/aout/etc || return 1
404 fi
405 if [ ! -d $root/emul/aout/usr/lib ]; then
406 mkdir -p $root/emul/aout/usr/lib || return 1
407 fi
408
409 # Move ld.so.conf
410 if [ -f $root/etc/ld.so.conf ]; then
411 mv -f $root/etc/ld.so.conf $root/emul/aout/etc || return 1
412 fi
413
414 # Finally, move the aout shared libraries from /usr/lib
415 md_mv_usr_lib $root || return 1
416
417 # If X11 is installed, move the those libraries as well
418 xlibdir="/usr/X11R6/lib"
419 if [ -d $root/$xlibdir/. ]; then
420 mkdir -p $root/emul/aout/$xlibdir || return 1
421 md_mv_x_lib $root $xlibdir || return 1
422 fi
423
424 echo "a.out emulation environment setup completed."
425 }
426
427 md_prepare_upgrade()
428 {
429 cat << 'EOF'
430 This release uses the ELF binary object format. Existing (a.out) binaries
431 can still be used on your system after it has been upgraded, provided
432 that the shared libraries needed by those binaries are made available
433 in the filesystem hierarchy rooted at /emul/aout.
434
435 This upgrade procedure will now establish this hierarchy by moving all
436 shared libraries in a.out format found in /usr/lib to /emul/aout/usr/lib.
437 It will also move the X11 shared libraries in a.out format from previous
438 NetBSD/amiga X11 installation sets, if they are installed.
439
440 EOF
441 md_mv_aout_libs || {
442 echo "Failed to setup a.out emulation environment"
443 return 1
444 }
445 return 0
446 }
447
448 # Flag to notify upgrade.sh of the existence of md_prepare_upgrade()
449 md_upgrade_prep_needed=1
450