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