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