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