xref: /netbsd/sys/arch/sparc/stand/binstall/binstall.sh (revision bf9ec67e)
1#!/bin/sh
2#	$NetBSD: binstall.sh,v 1.11 2002/05/07 14:13:02 pk Exp $
3#
4
5vecho () {
6# echo if VERBOSE on
7	if [ "$VERBOSE" = "1" ]; then
8		echo "$@" 1>&2
9	fi
10	return 0
11}
12
13Options () {
14	echo "Options:"
15	echo "	-h		- display this message"
16	echo "	-u		- install sparc64 (UltraSPARC) boot block"
17	echo "	-U		- install sparc boot block"
18	echo "	-b<bootprog>	- second-stage boot program to install"
19	echo "	-f<pathname>	- path to device/file image for filesystem"
20	echo "	-m<path>	- Look for boot programs in <path> (default: /usr/mdec)"
21	echo "	-i<progname>	- Use the installboot program at <progname>"
22	echo "			  (default: /usr/sbin/installboot)"
23	echo "	-v		- verbose mode"
24	echo "	-t		- test mode (implies -v)"
25}
26
27Usage () {
28	echo "Usage: $0 [options] <"'"net"|"ffs"'"> <directory>"
29	Options
30	exit 1
31}
32
33Help () {
34	echo "This script copies the boot programs to one of several"
35	echo "commonly used places."
36	echo "When installing an \"ffs\" boot program, this script also runs"
37	echo "installboot(8) which installs the default proto bootblocks into"
38	echo "the appropriate filesystem partition or filesystem image."
39	Options
40	exit 0
41}
42
43Secure () {
44	echo "This script has to be run when the kernel is in 'insecure' mode,"
45	echo "or when applying bootblocks to a file image (ala vnd)."
46	echo "The best way is to run this script in single-user mode."
47	exit 1
48}
49
50PATH=/bin:/usr/bin:/sbin:/usr/sbin
51MDEC=${MDEC:-/usr/mdec}
52INSTALLBOOT=${INSTALLBOOT:=/usr/sbin/installboot}
53BOOTPROG=${BOOTPROG:-boot}
54OFWBOOT=${OFWBOOTBLK:-ofwboot}
55if [ "`sysctl -n hw.machine`" = sparc64 ]; then
56	ULTRASPARC=1
57else
58	ULTRASPARC=0
59fi
60
61set -- `getopt "b:hf:i:m:tUuv" "$@"`
62if [ $? -gt 0 ]; then
63	Usage
64fi
65
66for a in $*
67do
68	case $1 in
69	-h) Help; shift ;;
70	-u) ULTRASPARC=1; shift ;;
71	-U) ULTRASPARC=0; shift ;;
72	-b) BOOTPROG=$2; OFWBOOT=$2; shift 2 ;;
73	-f) DEV=$2; shift 2 ;;
74	-m) MDEC=$2; shift 2 ;;
75	-i) INSTALLBOOT=$2; shift 2 ;;
76	-t) TEST=1; VERBOSE=1; shift ;;
77	-v) VERBOSE=1; shift ;;
78	--) shift; break ;;
79	esac
80done
81
82if [ "`sysctl -n kern.securelevel`" -gt 0 ] && [ ! -f "$DEV" ]; then
83	Secure
84fi
85
86DOIT=${TEST:+echo "=>"}
87
88if [ $# != 2 ]; then
89	Usage
90fi
91
92WHAT=$1
93DEST=$2
94
95if [ ! -d $DEST ]; then
96	echo "$DEST: not a directory"
97	Usage
98fi
99
100if [ "$ULTRASPARC" = "1" ]; then
101	machine=sparc64
102	targ=ofwboot
103	netboot=ofwboot.net
104	BOOTPROG=$OFWBOOT
105	BOOTXX=${MDEC}/bootblk
106else
107	machine=sparc
108	targ=boot
109	netboot=boot.net
110	BOOTXX=${MDEC}/bootxx
111fi
112
113case $WHAT in
114"ffs")
115	if [ "$DEV" = "" ]; then
116		# Lookup device mounted on DEST
117		DEV=`mount | while read line; do
118			set -- $line
119			vecho "Inspecting \"$line\""
120			if [ "$2" = "on" -a "$3" = "$DEST" ]; then
121				if [ ! -b $1 ]; then
122					continue
123				fi
124				RAW=\`echo -n "$1" | sed -e 's;/dev/;/dev/r;'\`
125				if [ ! -c \$RAW ]; then
126					continue
127				fi
128				echo -n $RAW
129				break;
130			fi
131		done`
132		if [ "$DEV" = "" ]; then
133			echo "Cannot find \"$DEST\" in mount table"
134			exit 1
135		fi
136	fi
137
138	vecho Boot device: $DEV
139	vecho Primary boot program: $BOOTXX
140	vecho Secondary boot program: $DEST/$targ
141
142	$DOIT cp -p -f ${MDEC}/${BOOTPROG} $DEST/$targ
143	sync; sync; sync
144	vecho ${INSTALLBOOT} ${VERBOSE:+-v} -m $machine $DEV ${BOOTXX} $targ
145	$DOIT ${INSTALLBOOT} ${VERBOSE:+-v} -m $machine $DEV ${BOOTXX} $targ
146	;;
147
148"net")
149	vecho Network boot program: $DEST/$boot.${machine}.netbsd
150	$DOIT cp -p -f ${MDEC}/$netboot $DEST/$boot.${machine}.netbsd
151	;;
152
153*)
154	echo "$WHAT: not recognised"
155	exit 1
156	;;
157esac
158
159exit $?
160