1 #!/bin/sh 2 # $NetBSD: binstall.sh,v 1.10 2002/01/02 04:13:42 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 Options () { 14 echo "Options:" 15 echo " -h - display this message" 16 echo " -u - install sparc64 (UltraSPARC) boot block" 17 echo " -U - install sparc boot block" 18 echo " -b<bootprog> - second-stage boot program to install" 19 echo " -f<pathname> - path to device/file image for filesystem" 20 echo " -m<path> - Look for boot programs in <path> (default: /usr/mdec)" 21 echo " -i<progname> - Use the installboot program at <progname>" 22 echo " (default: /usr/mdec/installboot)" 23 echo " -v - verbose mode" 24 echo " -t - test mode (implies -v)" 25 } 26 27 Usage () { 28 echo "Usage: $0 [options] <"'"net"|"ffs"'"> <directory>" 29 Options 30 exit 1 31 } 32 33 Help () { 34 echo "This script copies the boot programs to one of several" 35 echo "commonly used places. It takes care of stripping the" 36 echo "a.out(5) header off the installed boot program on sun4 machines." 37 echo "When installing an \"ffs\" boot program, this script also runs" 38 echo "installboot(8) which installs the default proto bootblocks into" 39 echo "the appropriate filesystem partition." 40 Options 41 exit 0 42 } 43 44 Secure () { 45 echo "This script has to be run when the kernel is in 'insecure' mode," 46 echo "or when applying bootblocks to a file image (ala vnd)." 47 echo "The best way is to run this script in single-user mode." 48 exit 1 49 } 50 51 PATH=/bin:/usr/bin:/sbin:/usr/sbin 52 MDEC=${MDEC:-/usr/mdec} 53 INSTALLBOOT=${INSTALLBOOT:=${MDEC}/installboot} 54 BOOTPROG=${BOOTPROG:-boot} 55 OFWBOOT=${OFWBOOTBLK:-ofwboot} 56 if [ "`sysctl -n hw.machine`" = sparc64 ]; then 57 ULTRASPARC=1 58 else 59 ULTRASPARC=0 60 fi 61 62 set -- `getopt "b:hf:i:m:tUuv" "$@"` 63 if [ $? -gt 0 ]; then 64 Usage 65 fi 66 67 for a in $* 68 do 69 case $1 in 70 -h) Help; shift ;; 71 -u) ULTRASPARC=1; shift ;; 72 -U) ULTRASPARC=0; shift ;; 73 -b) BOOTPROG=$2; OFWBOOT=$2; shift 2 ;; 74 -f) FILENAME=$2; shift 2 ;; 75 -m) MDEC=$2; shift 2 ;; 76 -i) INSTALLBOOT=$2; shift 2 ;; 77 -t) TEST=1; VERBOSE=1; shift ;; 78 -v) VERBOSE=1; shift ;; 79 --) shift; break ;; 80 esac 81 done 82 83 if [ "`sysctl -n kern.securelevel`" -gt 0 ] && [ ! -f "$FILENAME" ]; then 84 Secure 85 fi 86 87 DOIT=${TEST:+echo "=>"} 88 89 if [ $# != 2 ]; then 90 Usage 91 fi 92 93 WHAT=$1 94 DEST=$2 95 96 if [ ! -d $DEST ]; then 97 echo "$DEST: not a directory" 98 Usage 99 fi 100 101 SKIP=0 102 103 if [ "$ULTRASPARC" = "1" ]; then 104 targ=ofwboot 105 netboot=ofwboot.net 106 nettarg=boot.sparc.netbsd 107 BOOTPROG=$OFWBOOT 108 else 109 targ=boot 110 netboot=boot.net 111 nettarg=boot.sparc64.netbsd 112 fi 113 114 case $WHAT in 115 "ffs") 116 DEV=`mount | while read line; do 117 set -- $line 118 vecho "Inspecting \"$line\"" 119 if [ "$2" = "on" -a "$3" = "$DEST" ]; then 120 if [ ! -b $1 ]; then 121 continue 122 fi 123 RAW=\`echo -n "$1" | sed -e 's;/dev/;/dev/r;'\` 124 if [ ! -c \$RAW ]; then 125 continue 126 fi 127 echo -n $RAW 128 break; 129 fi 130 done` 131 if [ "$FILENAME" != "" ]; then 132 DEV=$FILENAME 133 fi 134 if [ "$DEV" = "" ]; then 135 echo "Cannot find \"$DEST\" in mount table" 136 exit 1 137 fi 138 TARGET=$DEST/$targ 139 vecho Boot device: $DEV 140 vecho Target: $TARGET 141 $DOIT dd if=${MDEC}/${BOOTPROG} of=$TARGET bs=32 skip=$SKIP 142 sync; sync; sync 143 if [ "$ULTRASPARC" = "1" ]; then 144 vecho ${INSTALLBOOT} -u ${VERBOSE:+-v} ${MDEC}/bootblk $DEV 145 $DOIT ${INSTALLBOOT} -u ${VERBOSE:+-v} ${MDEC}/bootblk $DEV 146 else 147 vecho ${INSTALLBOOT} ${VERBOSE:+-v} $TARGET ${MDEC}/bootxx $DEV 148 $DOIT ${INSTALLBOOT} ${VERBOSE:+-v} $TARGET ${MDEC}/bootxx $DEV 149 fi 150 ;; 151 152 "net") 153 TARGET=$DEST/$nettarg 154 vecho Target: $TARGET 155 $DOIT cp -f ${MDEC}/$netboot $TARGET 156 ;; 157 158 *) 159 echo "$WHAT: not recognised" 160 exit 1 161 ;; 162 esac 163 164 exit $? 165