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