Home | History | Annotate | Line # | Download | only in binstall
binstall.sh revision 1.1
      1 #!/bin/sh
      2 #	$NetBSD: binstall.sh,v 1.1 1997/06/01 03:39:24 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 "	-m<path>	- Look for boot programs in <path> (default: /usr/mdec)"
     28 	echo "	-v		- verbose mode"
     29 	echo "	-t		- test mode (implies -v)"
     30 	exit 0
     31 }
     32 
     33 
     34 PATH=/bin:/usr/bin:/sbin:/usr/sbin
     35 MDEC=${MDEC:-/usr/mdec}
     36 
     37 set -- `getopt "hm:tv" "$@"`
     38 if [ $? -gt 0 ]; then
     39 	Usage
     40 fi
     41 
     42 for a in $*
     43 do
     44 	case $1 in
     45 	-h) Help; shift ;;
     46 	-m) MDEC=$2; shift 2 ;;
     47 	-t) TEST=1; VERBOSE=1; shift ;;
     48 	-v) VERBOSE=1; shift ;;
     49 	--) shift; break ;;
     50 	esac
     51 done
     52 
     53 DOIT=${TEST:+echo "=>"}
     54 
     55 if [ $# != 2 ]; then
     56 	Usage
     57 fi
     58 
     59 WHAT=$1
     60 DEST=$2
     61 
     62 if [ ! -d $DEST ]; then
     63 	echo "$DEST: not a directory"
     64 	Usage
     65 fi
     66 
     67 
     68 SKIP=0
     69 
     70 case $WHAT in
     71 "ffs")
     72 	DEV=`mount | while read line; do
     73 		set -- $line
     74 		vecho "Inspecting \"$line\""
     75 		if [ "$2" = "on" -a "$3" = "$DEST" ]; then
     76 			if [ ! -b $1 ]; then
     77 				continue
     78 			fi
     79 			RAW=\`echo -n "$1" | sed -e 's;/dev/;/dev/r;'\`
     80 			if [ ! -c \$RAW ]; then
     81 				continue
     82 			fi
     83 			echo -n $RAW
     84 			break;
     85 		fi
     86 	done`
     87 	if [ "$DEV" = "" ]; then
     88 		echo "Cannot find \"$DEST\" in mount table"
     89 		exit 1
     90 	fi
     91 	TARGET=$DEST/boot
     92 	vecho Boot device: $DEV
     93 	vecho Target: $TARGET
     94 	$DOIT dd if=${MDEC}/boot of=$TARGET bs=32 skip=$SKIP
     95 	sync; sync; sync
     96 	vecho ${MDEC}/installboot ${VERBOSE:+-v} $TARGET ${MDEC}/bootxx $DEV
     97 	$DOIT ${MDEC}/installboot ${VERBOSE:+-v} $TARGET ${MDEC}/bootxx $DEV
     98 	;;
     99 
    100 "net")
    101 	TARGET=$DEST/boot.sparc.netbsd
    102 	TMP=/tmp/boot.$$
    103 	vecho Target: $TARGET
    104 	vecho Copying to temporary file.
    105 	cp ${MDEC}/boot $TMP; chmod +w $TMP
    106 	vecho Stripping $TMP
    107 	strip $TMP
    108 	vecho Creating header magic.
    109 	printf '\01\03\01\07\060\200\0\07' | dd of=$TARGET bs=32 conv=sync
    110 	vecho Concatenating boot code.
    111 	dd if=$TMP of=$TARGET bs=32 skip=1 seek=1
    112 	rm $TMP
    113 	;;
    114 
    115 *)
    116 	echo "$WHAT: not recognised"
    117 	exit 1
    118 	;;
    119 esac
    120 
    121 exit $?
    122