11.20Stsutsui# $NetBSD: dot.profile,v 1.20 2009/12/24 14:56:14 tsutsui Exp $
21.1Smrg#
31.11Spk# Copyright (c) 2000 The NetBSD Foundation, Inc.
41.1Smrg# All rights reserved.
51.11Spk#
61.11Spk# This code is derived from software contributed to The NetBSD Foundation
71.11Spk# by Paul Kranenburg.
81.11Spk#
91.1Smrg# Redistribution and use in source and binary forms, with or without
101.1Smrg# modification, are permitted provided that the following conditions
111.1Smrg# are met:
121.1Smrg# 1. Redistributions of source code must retain the above copyright
131.1Smrg#    notice, this list of conditions and the following disclaimer.
141.1Smrg# 2. Redistributions in binary form must reproduce the above copyright
151.1Smrg#    notice, this list of conditions and the following disclaimer in the
161.1Smrg#    documentation and/or other materials provided with the distribution.
171.11Spk#
181.11Spk# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
191.11Spk# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
201.11Spk# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
211.11Spk# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
221.11Spk# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
231.11Spk# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
241.11Spk# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
251.11Spk# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
261.11Spk# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
271.11Spk# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
281.11Spk# POSSIBILITY OF SUCH DAMAGE.
291.11Spk#
301.1Smrg
311.1SmrgPATH=/sbin:/bin:/usr/bin:/usr/sbin:/
321.1Smrgexport PATH
331.1SmrgHOME=/
341.1Smrgexport HOME
351.1Smrg
361.1Smrgumask 022
371.1Smrg
381.15SpkMACHINE=sparc
391.12SpkINSTFS_MP=/instfs
401.12SpkMINIROOT_FSSIZE=10000
411.17SlukemMINIROOT_BPINODE=1024
421.12Spk
431.12Spkif [ "${BOOTFS_DONEPROFILE}" != "YES" ]; then
441.12Spk
451.12Spk	BOOTFS_DONEPROFILE=YES
461.12Spk	export BOOTFS_DONEPROFILE
471.12Spk
481.12Spk	# mount root read-write
491.12Spk	mount_ffs -o update /dev/md0a /
501.12Spk
511.12Spk	# mount /instfs
521.17Slukem	mount_mfs -s $MINIROOT_FSSIZE -i $MINIROOT_BPINODE swap $INSTFS_MP
531.1Smrgfi
541.11Spk
551.12Spk# A cat simulator
561.12Spkcat()
571.12Spk{
581.12Spk	local l
591.12Spk	while read l; do
601.12Spk		echo "$l"
611.12Spk	done
621.12Spk}
631.12Spk
641.12Spk_resp=""
651.12Spkgetresp() {
661.12Spk	read _resp
671.12Spk	if [ "$_resp" = "" ]; then
681.12Spk		_resp=$1
691.12Spk	fi
701.12Spk}
711.11Spk
721.12Spk# Load instfs
731.11Spk
741.12Spkfloppy()
751.12Spk{
761.14Spk	local dev rval
771.14Spk
781.14Spk	rval=0
791.20Stsutsui	dev="/dev/fd0a"
801.14Spk
811.14Spk	echo "Ejecting floppy disk"
821.18Spk	eject $dev
831.14Spk
841.12Spk	cat <<EOF
851.14SpkRemove the boot disk from the floppy station and insert the second disk of
861.14Spkthe floppy installation set into the disk drive.
871.12Spk
881.12SpkThe question below allows you to specify the device name of the floppy
891.12Spkdrive.  Usually, the default device will do just fine.
901.12SpkEOF
911.12Spk	echo -n "Floppy device to load the installation utilities from [$dev]: "
921.12Spk	getresp "$dev"; dev="$_resp"
931.12Spk
941.12Spk	echo "Extracting installation utilities... "
951.14Spk	(cd $INSTFS_MP && tar zxpf $dev) || rval=1
961.14Spk
971.14Spk	echo "Ejecting floppy disk"
981.18Spk	eject $dev
991.14Spk	return $rval
1001.12Spk}
1011.12Spk
1021.12Spktape()
1031.12Spk{
1041.13Spk	local dev fn bsa
1051.12Spk	cat <<EOF
1061.12SpkBy default, the installation utilities are located in the second tape file
1071.12Spkon the NetBSD/sparc installation tape. In case your tape layout is different,
1081.12Spkchoose the appropriate tape file number below.
1091.12Spk
1101.12SpkEOF
1111.12Spk	dev="/dev/nrst0"
1121.12Spk	echo -n "Tape device to load the installation utilities from [$dev]: "
1131.12Spk	getresp "$dev"; dev="$_resp"
1141.12Spk
1151.12Spk	fn=2
1161.12Spk	echo -n "Tape file number [$fn]: "
1171.12Spk	getresp "$fn"; fn="$_resp"
1181.12Spk
1191.13Spk	echo -n "Tape block size (use only if you know you need it): "
1201.13Spk	getresp ""; if [ "$_resp" != "" ]; then
1211.13Spk		bsa="-b $_resp"
1221.13Spk	fi
1231.12Spk
1241.12Spk	echo "Positioning tape... "
1251.12Spk	mt -f $dev asf $(($fn - 1))
1261.12Spk	[ $? = 0 ] || return 1
1271.12Spk
1281.12Spk	echo "Extracting installation utilities... "
1291.13Spk	(cd $INSTFS_MP && tar $bsa -z -x -p -f $dev) || return 1
1301.12Spk}
1311.12Spk
1321.12Spkcdrom()
1331.12Spk{
1341.12Spk	local dev tf rval
1351.12Spk	cat <<EOF
1361.12SpkThe installation utilities are located on the ISO CD9660 filesystem on the
1371.12SpkNetBSD/sparc CD-ROM. We need to mount the filesystem from the CD-ROM device
1381.12Spkwhich you can specify below. Note: after the installation utilities are
1391.12Spkextracted this filesystem will be unmounted again.
1401.12Spk
1411.12SpkEOF
1421.12Spk
1431.12Spk	rval=0
1441.12Spk	dev="/dev/cd0a"
1451.12Spk	echo -n "CD-ROM device to use [$dev]: "
1461.12Spk	getresp "$dev"; dev="$_resp"
1471.12Spk
1481.12Spk	mount_cd9660 -o rdonly $dev /cdrom || return 1
1491.12Spk
1501.15Spk	# Look for instfs.tgz in MACHINE subdirectory first
1511.15Spk	tf=/cdrom/$MACHINE/installation/bootfs/instfs.tgz
1521.15Spk	[ -f $tf ] || tf=/cdrom/installation/bootfs/instfs.tgz
1531.16Spk	[ -f $tf ] || {
1541.16Spk		echo "Note: instfs.tgz image not found in default location"
1551.16Spk		tf=""
1561.16Spk	}
1571.16Spk
1581.16Spk	while :; do
1591.16Spk		echo -n "Path to instfs.tgz [$tf] "
1601.16Spk		[ -z "$tf" ] && echo -n "(<return> to abort) "
1611.16Spk		getresp "$tf"; tf="$_resp"
1621.16Spk		[ -z "$tf" ] && { rval=1; break; }
1631.16Spk		[ -f "$tf" ] && break;
1641.16Spk		echo "$tf not found"
1651.16Spk		tf=""
1661.16Spk	done
1671.15Spk
1681.15Spk	[ $rval = 0 ] && (cd $INSTFS_MP && tar zxpf $tf) || rval=1
1691.15Spk
1701.12Spk	umount /cdrom
1711.12Spk	return $rval
1721.12Spk}
1731.12Spk
1741.12Spkcat <<EOF
1751.12SpkWelcome to the NetBSD/sparc microroot setup utility.
1761.12Spk
1771.12SpkWe've just completed the first stage of a two-stage procedure to load a
1781.12Spkfully functional NetBSD installation environment on your machine.  In the
1791.12Spksecond stage which is to follow now, a set of additional installation
1801.12Spkutilities must be load from your NetBSD/sparc installation medium.
1811.11Spk
1821.12SpkEOF
1831.11Spk
1841.11Spkwhile :; do
1851.12Spk	cat <<EOF
1861.12SpkThis procedure supports one of the following media:
1871.12Spk
1881.12Spk	1) cdrom
1891.12Spk	2) tape
1901.12Spk	3) floppy
1911.12Spk
1921.12SpkEOF
1931.12Spk	echo -n "Installation medium to load the additional utilities from: "
1941.12Spk	read answer
1951.12Spk	echo ""
1961.12Spk	case "$answer" in
1971.12Spk		1|cdrom)	_func=cdrom;;
1981.12Spk		2|tape)		_func=tape;;
1991.12Spk		3|floppy)	_func=floppy;;
2001.12Spk		*)		echo "option not supported"; continue;;
2011.12Spk	esac
2021.12Spk	$_func && break
2031.11Spkdone
2041.11Spk
2051.11Spk# switch to /instfs, and pretend we logged in there.
2061.12Spkchroot $INSTFS_MP /bin/sh /.profile
2071.12Spk
2081.12Spk#
2091.12Spkecho "Back in microroot; halting machine..."
2101.12Spkhalt
211