Home | History | Annotate | Line # | Download | only in miniroot
install.md revision 1.25
      1 #	$NetBSD: install.md,v 1.25 2006/01/18 13:39:05 is 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 # 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 xetc xfont 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 }
    131 
    132 md_view_labels_possible=1
    133 md_view_labels() {
    134 	_DKDEVS=`md_get_diskdevs`
    135 	echo "If you like, you can now examine the labels of your disks."
    136 	echo ""
    137 	echo -n "Available are "${_DKDEVS}". Look at which? [skip this step] "
    138 	getresp	"done"
    139 	while [ "X$resp" != "Xdone" ]; do
    140 		echo ""
    141 		disklabel ${resp}
    142 		echo ""
    143 		echo -n "Available are "${_DKDEVS}". Look at which? [done] "
    144 		getresp	"done"
    145 	done
    146 	cat << \__prep_disklabel_1
    147 
    148 As a reminder: the 'c' partition is assigned to the whole disk and can't
    149 normally be used for a any file system!
    150 
    151 __prep_disklabel_1
    152 }
    153 
    154 md_labeldisk() {
    155 }
    156 
    157 md_welcome_banner() {
    158 	if [ "$MODE" = "install" ]; then
    159 		echo ""
    160 		echo "Welcome to the NetBSD/amiga ${VERSION} installation program."
    161 		cat << \__welcome_banner_1
    162 
    163 This program is designed to help you put NetBSD on your disk,
    164 in a simple and rational way.  You'll be asked several questions,
    165 and it would probably be useful to have your disk's hardware
    166 manual, the installation notes, and a calculator handy.
    167 __welcome_banner_1
    168 
    169 	else
    170 		echo ""
    171 		echo "Welcome to the NetBSD/amiga ${VERSION} upgrade program."
    172 		cat << \__welcome_banner_2
    173 
    174 This program is designed to help you upgrade your NetBSD system in a
    175 simple and rational way.
    176 
    177 As a reminder, installing the `etc' binary set is NOT recommended.
    178 Once the rest of your system has been upgraded, you should manually
    179 merge any changes to files in the `etc' set into those files which
    180 already exist on your system.
    181 __welcome_banner_2
    182 	fi
    183 
    184 cat << \__welcome_banner_3
    185 
    186 As with anything which modifies your disk's contents, this
    187 program can cause SIGNIFICANT data loss, and you are advised
    188 to make sure your data is backed up before beginning the
    189 installation process.
    190 
    191 Default answers are displayed in brackets after the questions.
    192 You can hit Control-C at any time to quit, but if you do so at a
    193 prompt, you may have to hit return.  Also, quitting in the middle of
    194 installation may leave your system in an inconsistent state.
    195 
    196 __welcome_banner_3
    197 }
    198 
    199 md_not_going_to_install() {
    200 	cat << \__not_going_to_install_1
    201 
    202 OK, then.  Enter `halt' at the prompt to halt the machine.  Once the
    203 machine has halted, power-cycle the system to load new boot code.
    204 
    205 Note: If you wish to have another try. Just type '^D' at the prompt. After
    206       a moment, the installer will restart itself.
    207 
    208 __not_going_to_install_1
    209 }
    210 
    211 md_congrats() {
    212 	local what;
    213 	if [ "$MODE" = "install" ]; then
    214 		what="installed";
    215 	else
    216 		what="upgraded";
    217 	fi
    218 	cat << __congratulations_1
    219 
    220 CONGRATULATIONS!  You have successfully $what NetBSD!
    221 To boot the installed system, enter halt at the command prompt. Once the
    222 system has halted, reset the machine and boot from the disk.
    223 
    224 Note: If you wish to have another try. Just type '^D' at the prompt. After
    225       a moment, the installer will restart itself.
    226 
    227 __congratulations_1
    228 }
    229 
    230 md_copy_kernel() {
    231 	# This is largely a copy of install_disk and install_from_mounted_fs()
    232 	# with some special frobbing.
    233 
    234 	local _directory
    235 	local _sets
    236 	local _filename
    237 	local _f
    238 
    239 	if [ "$MODE" = "install" ]; then
    240 		echo -n "Adding keymap initialization to rc.local..."
    241 		echo /usr/sbin/loadkmap ${__keymap__} >> /mnt/etc/rc.local
    242 		echo "done."
    243 	fi
    244 
    245 	if [ -e /netbsd ]; then
    246 		if [ -e /mnt/netbsd ]; then
    247 			echo "On the installation filesystem there is this kernel: "
    248 			ls -l /netbsd
    249 			echo "The already installed kernel is: "
    250 			ls -l /mnt/netbsd
    251 			echo	"Do you want to replace the already installed kernel by the kernel"
    252 			echo -n "on the installation filesystem? (y/n) [n] "
    253 			resp="n"
    254 			getresp ""
    255 			if [ "${resp}" != "y" -a "${resp}" != "Y" ]; then
    256 				return
    257 			fi
    258 		fi
    259 
    260 		echo -n "Copying kernel..."
    261 		cp -p /netbsd /mnt/netbsd
    262 		echo "done."
    263 		return
    264 	fi
    265 
    266 cat << \__md_copy_kernel_1
    267 Your installation set did not include a netbsd kernel on the installation
    268 filesystem. You are now given the opportunity install it from either the
    269 kernel-floppy from the distribution or another location on one of your disks.
    270 
    271 The following disk devices are installed on your system; please select
    272 the disk device containing the partition with the netbsd kernel:
    273 __md_copy_kernel_1
    274 
    275 	_DKDEVS=`md_get_diskdevs`
    276 	echo    "$_DKDEVS"
    277 	echo	"fd0"
    278 	echo	""
    279 	_DKDEVS="$_DKDEVS fd0"		# Might be on the kernel floppy!
    280 	echo -n	"Which is the disk with the kernel? [abort] "
    281 
    282 	if mount_a_disk ; then
    283 		return	# couldn't mount the disk
    284 	fi
    285 
    286 	# Get the directory where the file lives
    287 	resp=""		# force one iteration
    288 	while [ "X${resp}" = X"" ]; do
    289 		echo "Enter the directory relative to the mount point that"
    290 		echo -n "contains the file. [${_directory}] "
    291 		getresp "${_directory}"
    292 	done
    293 	_directory=$resp
    294 
    295 	_sets=`(cd /mnt2/$_directory; ls netbsd* 2> /dev/null)`
    296 	if [ -z "$_sets" ]; then
    297 		echo "There are no NetBSD kernels available in \"$1\""
    298 		umount -f /mnt2 > /dev/null 2>&1
    299 		return
    300 	fi
    301 	while : ; do
    302 		echo "The following kernels are available:"
    303 		echo ""
    304 
    305 		for _f in $_sets ; do
    306 			echo "    $_f"
    307 		done
    308 		echo ""
    309 		set -- $_sets
    310 		echo -n "File name [$1]? "
    311 		getresp "$1"
    312 		_f=$resp
    313 		_filename="/mnt2/$_directory/$_f"
    314 
    315 		# Ensure file exists
    316 		if [ ! -f $_filename ]; then
    317 			echo "File $_filename does not exist.  Check to make"
    318 			echo "sure you entered the information properly."
    319 			echo -n "Do you want to retry [y]? "
    320 			getresp "y"
    321 			if [ "$resp" = "n" ]; then
    322 				break
    323 			fi
    324 			continue
    325 		fi
    326 
    327 		# Copy the kernel
    328 		cp $_filename /mnt
    329 		break
    330 	done
    331 	umount -f /mnt2 > /dev/null 2>&1
    332 }
    333 
    334 md_lib_is_aout() {
    335 	local r
    336 	test -h $1 && return 1
    337 	test -f $1 || return 1
    338 
    339 	r=`file $1 | sed -n -e '/ELF/p'`
    340 	test -z "$r" || return 1
    341 	return 0
    342 }
    343 
    344 
    345 md_mv_usr_lib() {
    346 	local root
    347 	root=$1
    348 	for f in $root/usr/lib/lib*.so.[0-9]*.[0-9]* ; do
    349 		md_lib_is_aout $f || continue
    350 		mv -f $f $root/emul/aout/usr/lib || return 1
    351 	done
    352 	return 0
    353 }
    354 
    355 md_x_shlib_set_14=" \
    356 	libICE.so.6.3 \
    357 	libPEX5.so.6.0 \
    358 	libSM.so.6.0 \
    359 	libX11.so.6.1 \
    360 	libXIE.so.6.0 \
    361 	libXaw.so.6.1 \
    362 	libXext.so.6.3 \
    363 	libXi.so.6.0 \
    364 	libXmu.so.6.0 \
    365 	libXp.so.6.2 \
    366 	libXt.so.6.0 \
    367 	libXtst.so.6.1 \
    368 	liboldX.so.6.0"
    369 
    370 md_mv_x_lib() {
    371 	local root xlibdir
    372 	root=$1
    373 	xlibdir=$2
    374 	for f in $md_x_shlib_set_14; do
    375 		md_lib_is_aout $root/$xlibdir/$f || continue
    376 		mv -f $root/$xlibdir/$f $root/emul/aout/$xlibdir || return 1
    377 	done
    378 	return 0
    379 }
    380 
    381 md_mv_aout_libs()
    382 {
    383 	local root xlibdir
    384 
    385 	root=/mnt	# XXX - should be global
    386 
    387 	if [ -d $root/emul/aout/. ]; then
    388 		echo "Using existing /emul/aout directory"
    389 	else
    390 		echo "Creating /emul/aout hierachy"
    391 		mkdir -p $root/usr/aout || return 1
    392 
    393 		if [ ! -d $root/emul ]; then
    394 			mkdir $root/emul || return 1
    395 		fi
    396 
    397 		if [ -h $root/emul/aout ]; then
    398 			echo "Preserving existing symbolic link from /emul/aout"
    399 			mv -f $root/emul/aout $root/emul/aout.old || return 1
    400 		fi
    401 
    402 		ln -s ../usr/aout $root/emul/aout || return 1
    403 	fi
    404 
    405 	# Create /emul/aout/etc and /emul/aout/usr/lib
    406 	if [ ! -d $root/emul/aout/etc ]; then
    407 		mkdir $root/emul/aout/etc || return 1
    408 	fi
    409 	if [ ! -d $root/emul/aout/usr/lib ]; then
    410 		mkdir -p $root/emul/aout/usr/lib || return 1
    411 	fi
    412 
    413 	# Move ld.so.conf
    414 	if [ -f $root/etc/ld.so.conf ]; then
    415 		mv -f $root/etc/ld.so.conf $root/emul/aout/etc || return 1
    416 	fi
    417 
    418 	# Finally, move the aout shared libraries from /usr/lib
    419 	md_mv_usr_lib $root || return 1
    420 
    421 	# If X11 is installed, move the those libraries as well
    422 	xlibdir="/usr/X11R6/lib"
    423 	if [ -d $root/$xlibdir/. ]; then
    424 		mkdir -p $root/emul/aout/$xlibdir || return 1
    425 		md_mv_x_lib $root $xlibdir || return 1
    426 	fi
    427 
    428 	echo "a.out emulation environment setup completed."
    429 }
    430 
    431 md_prepare_upgrade()  
    432 {
    433 cat << 'EOF'
    434 This release uses the ELF binary object format. Existing (a.out) binaries
    435 can still be used on your system after it has been upgraded, provided
    436 that the shared libraries needed by those binaries are made available
    437 in the filesystem hierarchy rooted at /emul/aout.
    438 
    439 This upgrade procedure will now establish this hierarchy by moving all
    440 shared libraries in a.out format found in /usr/lib to /emul/aout/usr/lib.
    441 It will also move the X11 shared libraries in a.out format from previous
    442 NetBSD/amiga X11 installation sets, if they are installed.
    443 
    444 EOF
    445 	md_mv_aout_libs || {
    446 		echo "Failed to setup a.out emulation environment"
    447 		return 1
    448 	}
    449 	return 0
    450 }
    451 
    452 # Flag to notify upgrade.sh of the existence of md_prepare_upgrade()
    453 md_upgrade_prep_needed=1
    454