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