Home | History | Annotate | Line # | Download | only in binstall
binstall.sh revision 1.5
      1 #!/bin/sh
      2 #	$NetBSD: binstall.sh,v 1.5 2000/08/10 13:27:47 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 [-hvt] [-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 "	-b<bootprog>	- second-stage boot program to install"
     29 	echo "	-m<path>	- Look for boot programs in <path> (default: /usr/mdec)"
     30 	echo "	-v		- verbose mode"
     31 	echo "	-t		- test mode (implies -v)"
     32 	exit 0
     33 }
     34 
     35 Secure () {
     36 	echo "This script has to be run when the kernel is in 'insecure' mode."
     37 	echo "The best way is to run this script in single-user mode."
     38 	exit 1
     39 }
     40 
     41 PATH=/bin:/usr/bin:/sbin:/usr/sbin
     42 MDEC=${MDEC:-/usr/mdec}
     43 BOOTPROG=${BOOTPROG:-boot}
     44 OFWBOOT=${OFWBOOTBLK:-ofwboot.sparc64}
     45 if [ "`uname -m`" = sparc64 ]; then
     46 	ULTRASPARC=1
     47 else
     48 	ULTRASPARC=0
     49 fi
     50 
     51 if [ "`sysctl -n kern.securelevel`" -gt 0 ]; then
     52 	Secure
     53 fi
     54 
     55 set -- `getopt "b:hm:tv" "$@"`
     56 if [ $? -gt 0 ]; then
     57 	Usage
     58 fi
     59 
     60 for a in $*
     61 do
     62 	case $1 in
     63 	-h) Help; shift ;;
     64 	-u) ULTRASPARC=1; shift ;;
     65 	-b) BOOTPROG=$2; OFWBOOT=$2; shift 2 ;;
     66 	-m) MDEC=$2; shift 2 ;;
     67 	-o) OFWBOOT=$2; shift 2 ;;
     68 	-t) TEST=1; VERBOSE=1; shift ;;
     69 	-v) VERBOSE=1; shift ;;
     70 	--) shift; break ;;
     71 	esac
     72 done
     73 
     74 DOIT=${TEST:+echo "=>"}
     75 
     76 if [ $# != 2 ]; then
     77 	Usage
     78 fi
     79 
     80 WHAT=$1
     81 DEST=$2
     82 
     83 if [ ! -d $DEST ]; then
     84 	echo "$DEST: not a directory"
     85 	Usage
     86 fi
     87 
     88 SKIP=0
     89 
     90 if [ "$ULTRASPARC" = "1" ]; then
     91 	targ=ofwboot
     92 	netboot=ofwboot.net.sparc64
     93 	nettarg=boot.sparc.netbsd
     94 	BOOTPROG=$OFWBOOT
     95 else
     96 	targ=boot
     97 	netboot=boot.net
     98 	nettarg=boot.sparc64.netbsd
     99 fi
    100 
    101 case $WHAT in
    102 "ffs")
    103 	DEV=`mount | while read line; do
    104 		set -- $line
    105 		vecho "Inspecting \"$line\""
    106 		if [ "$2" = "on" -a "$3" = "$DEST" ]; then
    107 			if [ ! -b $1 ]; then
    108 				continue
    109 			fi
    110 			RAW=\`echo -n "$1" | sed -e 's;/dev/;/dev/r;'\`
    111 			if [ ! -c \$RAW ]; then
    112 				continue
    113 			fi
    114 			echo -n $RAW
    115 			break;
    116 		fi
    117 	done`
    118 	if [ "$DEV" = "" ]; then
    119 		echo "Cannot find \"$DEST\" in mount table"
    120 		exit 1
    121 	fi
    122 	TARGET=$DEST/$targ
    123 	vecho Boot device: $DEV
    124 	vecho Target: $TARGET
    125 	$DOIT dd if=${MDEC}/${BOOTPROG} of=$TARGET bs=32 skip=$SKIP
    126 	sync; sync; sync
    127 	if [ "$ULTRASPARC" = "1" ]; then
    128 		vecho ${MDEC}/installboot -u ${VERBOSE:+-v} ${MDEC}/bootblk.sparc64 $DEV
    129 		$DOIT ${MDEC}/installboot -u ${VERBOSE:+-v} ${MDEC}/bootblk.sparc64 $DEV
    130 	else
    131 		vecho ${MDEC}/installboot ${VERBOSE:+-v} $TARGET ${MDEC}/bootxx $DEV
    132 		$DOIT ${MDEC}/installboot ${VERBOSE:+-v} $TARGET ${MDEC}/bootxx $DEV
    133 	fi
    134 	;;
    135 
    136 "net")
    137 	TARGET=$DEST/$nettarg
    138 	vecho Target: $TARGET
    139 	$DOIT cp -f ${MDEC}/$netboot $TARGET
    140 	;;
    141 
    142 *)
    143 	echo "$WHAT: not recognised"
    144 	exit 1
    145 	;;
    146 esac
    147 
    148 exit $?
    149