1 #!/bin/sh 2 # $NetBSD: install.sh,v 1.10 2018/09/16 22:22:44 kre Exp $ 3 # 4 # Copyright (c) 1994 Christopher G. Demetriou 5 # All rights reserved. 6 # 7 # Redistribution and use in source and binary forms, with or without 8 # modification, are permitted provided that the following conditions 9 # are met: 10 # 1. Redistributions of source code must retain the above copyright 11 # notice, this list of conditions and the following disclaimer. 12 # 2. Redistributions in binary form must reproduce the above copyright 13 # notice, this list of conditions and the following disclaimer in the 14 # documentation and/or other materials provided with the distribution. 15 # 3. All advertising materials mentioning features or use of this software 16 # must display the following acknowledgement: 17 # This product includes software developed for the 18 # NetBSD Project. See http://www.NetBSD.org/ for 19 # information about NetBSD. 20 # 4. The name of the author may not be used to endorse or promote products 21 # derived from this software without specific prior written permission. 22 # 23 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 # 34 # <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> 35 36 # NetBSD installation script. 37 # In a perfect world, this would be a nice C program, with a reasonable 38 # user interface. 39 40 FSTABDIR=/mnt/etc # /mnt/etc 41 #DONTDOIT==echo 42 43 VERSION=1.2 44 FSTAB=${FSTABDIR}/fstab 45 46 getresp() { 47 read resp 48 if [ -z "$resp" ]; then 49 resp=$1 50 fi 51 } 52 53 getvar() { 54 echo $(eval $(echo "echo \$$1")) 55 } 56 57 shiftvar() { 58 local var 59 var="$1" 60 list="$(getvar $var)" 61 set -- $list 62 shift 63 setvar $var "$*" 64 } 65 66 getparts() { 67 disklabel $1 2>/dev/null | sed -e '/^[ ][ ][ad-p]/!d' | 68 sed -e 's,^[ ]*\([a-p]\):[ ]*[0-9]*[ ]*[0-9]*[ ][ ]*\([a-zA-Z0-9.]*\).*,\1 \2,' | 69 sed -e ':a 70 N;${s/\n/ /g;p;d;} 71 ba' 72 } 73 74 getdrives() { 75 local du thispart 76 for du in /dev/r${drivetype}?a; do 77 dd if=$du of=/dev/null bs=1b count=1 >/dev/null 2>&1 78 if [ $? -eq 0 ]; then 79 thisunit=$( echo $du | sed -e 's,/dev/r\(...\)a,\1,g' ) 80 driveunits="$driveunits $thisunit" 81 else 82 continue; 83 fi 84 setvar $thisunit "$(getparts $thisunit)" 85 export $thisunit 86 done 87 export drivenunits 88 } 89 90 prepdrive() { 91 echo "which drive would you like to prepare next?" 92 echo "choices are: ${driveunits}" 93 echo "" 94 getresp 95 case $resp in 96 *) ;; 97 esac 98 } 99 100 echo "Welcome to the NetBSD ${VERSION} installation program." 101 echo "" 102 echo "This program is designed to help you put NetBSD on your hard disk," 103 echo "in a simple and rational way. Its main objective is to format," 104 echo "mount and create an fstab for your root (/) and user (/usr)" 105 echo "partitions." 106 echo "" 107 echo "As with anything which modifies your hard drive's contents, this" 108 echo "program can cause SIGNIFICANT data loss, and you are advised" 109 echo "to make sure your hard drive is backed up before beginning the" 110 echo "installation process." 111 echo "" 112 echo "Default answers are displayed in brackets after the questions." 113 echo "You can hit Control-C at any time to quit, but if you do so at a" 114 echo "prompt, you may have to hit return. Also, quitting in the middle of" 115 echo "installation may leave your system in an inconsistent state." 116 echo "" 117 echo -n "Proceed with installation? [n] " 118 getresp "n" 119 case "$resp" in 120 y*|Y*) 121 echo "scanning for the root device" 122 ;; 123 *) 124 echo "" 125 echo "OK, then. Enter 'halt' at the prompt to halt the" 126 echo "machine. Once the machine has halted, remove the" 127 echo "floppy and press any key to reboot." 128 exit 129 ;; 130 esac 131 132 drivetype=sd 133 sect_fwd="" 134 135 # find out what units are possible for that disk, and query the user. 136 getdrives 137 for du in $driveunits; do 138 set -- $(getvar $du) 139 if [ $# -ge 2 ] && 140 [ "$1" = a ] && 141 [ "$( echo "$2" | sed -e 's,.*BSD.*,BSD,' )" = BSD ]; then 142 rdev=$du 143 fi 144 done 145 146 echo "" 147 echo "The following root devices are available on your machine:" 148 echo " "${driveunits} 149 echo "" 150 prefdev=${rdev} 151 rdev="" 152 while [ -z "${rdev}" ]; do 153 echo -n "Which device would you like to install on ? [${prefdev}] " 154 getresp ${prefdev} 155 otherdrives=$( echo "${driveunits}" | sed -e "s,${resp},," ) 156 if [ "X${driveunits}" = "X${otherdrives}" ]; then 157 echo "" 158 echo "\"${resp}\" is an invalid drive name. Valid choices" 159 echo "are: "${driveunits} 160 else 161 rdev=${resp} 162 fi 163 done 164 165 echo "" 166 echo "The root device you have chosen is on: ${rdev}" 167 echo "" 168 # driveunits=$( ls /dev/${drivetype}?a | sed -e 's,/dev/\(...\)a,\1,g' ) 169 if [ -z "${driveunits}" ]; then 170 echo "FATAL ERROR:" 171 echo "No devices for disks of type '${drivetype}'." 172 echo "This is probably a bug in the install disks." 173 echo "Exiting install program." 174 exit 175 fi 176 177 echo "" 178 echo "THIS IS YOUR LAST CHANCE!!!" 179 echo "" 180 echo "(answering yes will format your root partition on $rdev)" 181 echo -n "Are you SURE you want NetBSD installed on your hard drive? (yes/no) " 182 answer="" 183 while [ -z "$answer" ]; do 184 getresp 185 case "$resp" in 186 yes|YES) 187 echo "" 188 answer=yes 189 ;; 190 no|NO) 191 echo "" 192 echo -n "OK, then. enter 'halt' to halt the machine. " 193 echo "Once the machine has halted," 194 echo -n "remove the floppy, and press any key to " 195 echo "reboot." 196 exit 197 ;; 198 *) 199 echo -n "I want a yes or no answer... well? " 200 ;; 201 esac 202 done 203 echo "Initializing / (root) filesystem, and mounting..." 204 $DONTDOIT newfs /dev/r${rdev}a $name 205 $DONTDOIT mount -v /dev/${rdev}a /mnt 206 echo "" 207 echo -n "Creating a fstab..." 208 mkdir -p $FSTABDIR 209 echo "/dev/${rdev}a / ffs rw 1 1" > $FSTAB 210 211 # get rid of this partition 212 shiftvar $rdev 213 shiftvar $rdev 214 215 echo "" 216 echo "Now lets setup your /usr file system" 217 echo "(Once a valid input for drive and partition is seen" 218 echo "it will be FORMATTED and inserted in the fstab.)" 219 while [ -z "$usrpart" ]; do 220 resp="" 221 drivename="" 222 while [ -z "$resp" ]; do 223 echo "choices: $driveunits" 224 echo "which drive do you want /usr on?" 225 getresp 226 set -- $driveunits 227 while [ $# -gt 0 ]; do 228 if [ "X$resp" = "X$1" ]; then 229 drivename=$1 230 break; 231 else 232 shift 233 fi 234 done 235 if [ "X$drivename" != "X" ]; then 236 break 237 fi 238 done 239 240 usrpart="" 241 echo "You have selected $drivename" 242 echo "here is a list of partitions on $drivename" 243 disklabel $drivename 2>/dev/null | 244 sed -e '/^[ ][ ][ad-p]:/p;/^#[ \t]*size/p;d' 245 echo "which partition would you like to format and have" 246 echo -n "mounted as /usr? (supply the letter): " 247 getresp 248 if [ -z "$resp" ]; then 249 continue; 250 fi 251 252 list=$(getvar $drivename) 253 set -- $list 254 while [ $# -gt 0 ]; do 255 if [ "$resp" = "$1" ]; then 256 if [ "$( echo $2 | sed -e 's,.*BSD.*,BSD,' )" != "BSD" ] 257 then 258 echo "" 259 echo -n "$drivename$resp is of type $2 which" 260 echo " is not a BSD filesystem type" 261 break 262 fi 263 usrpart=$drivename$resp 264 break 265 else 266 shift 267 shift 268 fi 269 done 270 if [ -z "$usrpart" ]; then 271 echo "$resp is not a valid input." 272 echo "" 273 fi 274 done 275 276 echo "" 277 echo "Initializing /usr filesystem, and mounting..." 278 $DONTDOIT newfs /dev/r${usrpart} $name 279 $DONTDOIT mkdir -p /mnt/usr 280 $DONTDOIT mount -v /dev/${usrpart} /mnt/usr 281 echo "" 282 echo -n "Adding to fstab..." 283 echo "/dev/${usrpart} /usr ffs rw 1 2" >> $FSTAB 284 sync 285 echo " done." 286 287 echo "" 288 echo "OK! The preliminary work of setting up your disk is now complete," 289 echo "and you can install the actual NetBSD software." 290 echo "" 291 echo "Right now, your root is mounted on /mnt and your usr on /mnt/usr." 292 echo "You should consult the installation notes to determine how to load" 293 echo "and install the NetBSD distribution sets, and how to configure your" 294 echo "system when you are done." 295 echo "" 296 echo "GOOD LUCK!" 297 echo "" 298