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