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