xref: /netbsd/distrib/amiga/miniroot/install.md (revision 6550d01e)
1#	$NetBSD: install.md,v 1.27 2009/05/24 22:59:18 mlelstv 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
37MDSETS="kern-GENERIC xbase xcomp xetc xfont xserver"
38
39md_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
59md_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
68md_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
75md_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
82md_get_partition_range() {
83	# return an expression describing the valid partition id's
84	echo '[a-p]'
85}
86
87md_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
103There is no installboot program found on the installed filesystems. No boot
104programs are installed.
105__md_installboot_1
106	else
107		cat << \__md_installboot_2
108There is no installboot program found on the upgraded filesystems. No boot
109programs are installed.
110__md_installboot_2
111	fi
112}
113
114md_native_fstype() {
115	echo "ados"
116}
117
118md_native_fsopts() {
119	echo "ro"
120}
121
122md_prep_disklabel() {
123}
124
125md_view_labels_possible=1
126md_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
141As a reminder: the 'c' partition is assigned to the whole disk and can't
142normally be used for a any file system!
143
144__prep_disklabel_1
145}
146
147md_labeldisk() {
148}
149
150md_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
156This program is designed to help you put NetBSD on your disk,
157in a simple and rational way.  You'll be asked several questions,
158and it would probably be useful to have your disk's hardware
159manual, 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
167This program is designed to help you upgrade your NetBSD system in a
168simple and rational way.
169
170As a reminder, installing the `etc' binary set is NOT recommended.
171Once the rest of your system has been upgraded, you should manually
172merge any changes to files in the `etc' set into those files which
173already exist on your system.
174__welcome_banner_2
175	fi
176
177cat << \__welcome_banner_3
178
179As with anything which modifies your disk's contents, this
180program can cause SIGNIFICANT data loss, and you are advised
181to make sure your data is backed up before beginning the
182installation process.
183
184Default answers are displayed in brackets after the questions.
185You can hit Control-C at any time to quit, but if you do so at a
186prompt, you may have to hit return.  Also, quitting in the middle of
187installation may leave your system in an inconsistent state.
188
189__welcome_banner_3
190}
191
192md_not_going_to_install() {
193	cat << \__not_going_to_install_1
194
195OK, then.  Enter `halt' at the prompt to halt the machine.  Once the
196machine has halted, power-cycle the system to load new boot code.
197
198Note: 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
204md_congrats() {
205	local what;
206	if [ "$MODE" = "install" ]; then
207		what="installed";
208	else
209		what="upgraded";
210	fi
211	cat << __congratulations_1
212
213CONGRATULATIONS!  You have successfully $what NetBSD!
214To boot the installed system, enter halt at the command prompt. Once the
215system has halted, reset the machine and boot from the disk.
216
217Note: 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
223md_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
259cat << \__md_copy_kernel_1
260Your installation set did not include a netbsd kernel on the installation
261filesystem. You are now given the opportunity install it from either the
262kernel-floppy from the distribution or another location on one of your disks.
263
264The following disk devices are installed on your system; please select
265the 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
327md_lib_is_aout() {
328	local r
329	test -h $1 && return 1
330	test -f $1 || return 1
331
332	[ "`dd if=$1 bs=1 skip=1 count=3 2> /dev/null`" = "ELF" ] && return 1
333	return 0
334}
335
336
337md_mv_usr_lib() {
338	local root
339	root=$1
340	for f in $root/usr/lib/lib*.so.[0-9]*.[0-9]* ; do
341		md_lib_is_aout $f || continue
342		mv -f $f $root/emul/aout/usr/lib || return 1
343	done
344	return 0
345}
346
347md_x_shlib_set_14=" \
348	libICE.so.6.3 \
349	libPEX5.so.6.0 \
350	libSM.so.6.0 \
351	libX11.so.6.1 \
352	libXIE.so.6.0 \
353	libXaw.so.6.1 \
354	libXext.so.6.3 \
355	libXi.so.6.0 \
356	libXmu.so.6.0 \
357	libXp.so.6.2 \
358	libXt.so.6.0 \
359	libXtst.so.6.1 \
360	liboldX.so.6.0"
361
362md_mv_x_lib() {
363	local root xlibdir
364	root=$1
365	xlibdir=$2
366	for f in $md_x_shlib_set_14; do
367		md_lib_is_aout $root/$xlibdir/$f || continue
368		mv -f $root/$xlibdir/$f $root/emul/aout/$xlibdir || return 1
369	done
370	return 0
371}
372
373md_mv_aout_libs()
374{
375	local root xlibdir
376
377	root=/mnt	# XXX - should be global
378
379	if [ -d $root/emul/aout/. ]; then
380		echo "Using existing /emul/aout directory"
381	else
382		echo "Creating /emul/aout hierachy"
383		mkdir -p $root/usr/aout || return 1
384
385		if [ ! -d $root/emul ]; then
386			mkdir $root/emul || return 1
387		fi
388
389		if [ -h $root/emul/aout ]; then
390			echo "Preserving existing symbolic link from /emul/aout"
391			mv -f $root/emul/aout $root/emul/aout.old || return 1
392		fi
393
394		ln -s ../usr/aout $root/emul/aout || return 1
395	fi
396
397	# Create /emul/aout/etc and /emul/aout/usr/lib
398	if [ ! -d $root/emul/aout/etc ]; then
399		mkdir $root/emul/aout/etc || return 1
400	fi
401	if [ ! -d $root/emul/aout/usr/lib ]; then
402		mkdir -p $root/emul/aout/usr/lib || return 1
403	fi
404
405	# Move ld.so.conf
406	if [ -f $root/etc/ld.so.conf ]; then
407		mv -f $root/etc/ld.so.conf $root/emul/aout/etc || return 1
408	fi
409
410	# Finally, move the aout shared libraries from /usr/lib
411	md_mv_usr_lib $root || return 1
412
413	# If X11 is installed, move the those libraries as well
414	xlibdir="/usr/X11R6/lib"
415	if [ -d $root/$xlibdir/. ]; then
416		mkdir -p $root/emul/aout/$xlibdir || return 1
417		md_mv_x_lib $root $xlibdir || return 1
418	fi
419
420	echo "a.out emulation environment setup completed."
421}
422
423md_prepare_upgrade()
424{
425cat << 'EOF'
426This release uses the ELF binary object format. Existing (a.out) binaries
427can still be used on your system after it has been upgraded, provided
428that the shared libraries needed by those binaries are made available
429in the filesystem hierarchy rooted at /emul/aout.
430
431This upgrade procedure will now establish this hierarchy by moving all
432shared libraries in a.out format found in /usr/lib to /emul/aout/usr/lib.
433It will also move the X11 shared libraries in a.out format from previous
434NetBSD/amiga X11 installation sets, if they are installed.
435
436EOF
437	md_mv_aout_libs || {
438		echo "Failed to setup a.out emulation environment"
439		return 1
440	}
441	return 0
442}
443
444# Flag to notify upgrade.sh of the existence of md_prepare_upgrade()
445md_upgrade_prep_needed=1
446