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