1#!/bin/sh 2# $NetBSD: install.sh,v 1.8 2000/06/14 17:24:11 cgd 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 40FSTABDIR=/mnt/etc # /mnt/etc 41#DONTDOIT==echo 42 43VERSION=1.2 44FSTAB=${FSTABDIR}/fstab 45 46getresp() { 47 read resp 48 if [ "X$resp" = "X" ]; then 49 resp=$1 50 fi 51} 52 53getvar() { 54 echo $(eval $(echo "echo \$$1")) 55} 56 57shiftvar() { 58 local - var 59 var="$1" 60 list="$(getvar $var)" 61 set -- $list 62 shift 63 setvar $var "$*" 64} 65 66getparts() { 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 74getdrives() { 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 90prepdrive() { 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 100echo "Welcome to the NetBSD ${VERSION} installation program." 101echo "" 102echo "This program is designed to help you put NetBSD on your hard disk," 103echo "in a simple and rational way. Its main objective is to format," 104echo "mount and create an fstab for your root (/) and user (/usr)" 105echo "partitions." 106echo "" 107echo "As with anything which modifies your hard drive's contents, this" 108echo "program can cause SIGNIFICANT data loss, and you are advised" 109echo "to make sure your hard drive is backed up before beginning the" 110echo "installation process." 111echo "" 112echo "Default answers are displayed in brackets after the questions." 113echo "You can hit Control-C at any time to quit, but if you do so at a" 114echo "prompt, you may have to hit return. Also, quitting in the middle of" 115echo "installation may leave your system in an inconsistent state." 116echo "" 117echo -n "Proceed with installation? [n] " 118getresp "n" 119case "$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 ;; 130esac 131 132drivetype=sd 133sect_fwd="" 134 135# find out what units are possible for that disk, and query the user. 136getdrives 137for du in $driveunits; do 138 set -- $(getvar $du) 139 if [ $# -ge 2 -a "$1" = "a" -a "`echo $2 | sed -e 's,.*BSD.*,BSD,'`" = "BSD" ]; then 140 rdev=$du 141 fi 142done 143 144echo "" 145echo "The following root devices are available on your machine:" 146echo " "${driveunits} 147echo "" 148prefdev=${rdev} 149rdev="" 150while [ "X${rdev}" = "X" ]; do 151 echo -n "Which device would you like to install on ? [${prefdev}] " 152 getresp ${prefdev} 153 otherdrives=`echo "${driveunits}" | sed -e s,${resp},,` 154 if [ "X${driveunits}" = "X${otherdrives}" ]; then 155 echo "" 156 echo "\"${resp}\" is an invalid drive name. Valid choices" 157 echo "are: "${driveunits} 158 else 159 rdev=${resp} 160 fi 161done 162 163echo "" 164echo "The root device you have chosen is on: ${rdev}" 165echo "" 166# driveunits=`ls /dev/${drivetype}?a | sed -e 's,/dev/\(...\)a,\1,g'` 167if [ "X${driveunits}" = "X" ]; then 168 echo "FATAL ERROR:" 169 echo "No devices for disks of type '${drivetype}'." 170 echo "This is probably a bug in the install disks." 171 echo "Exiting install program." 172 exit 173fi 174 175echo "" 176echo "THIS IS YOUR LAST CHANCE!!!" 177echo "" 178echo "(answering yes will format your root partition on $rdev)" 179echo -n "Are you SURE you want NetBSD installed on your hard drive? (yes/no) " 180answer="" 181while [ "$answer" = "" ]; do 182 getresp 183 case $resp in 184 yes|YES) 185 echo "" 186 answer=yes 187 ;; 188 no|NO) 189 echo "" 190 echo -n "OK, then. enter 'halt' to halt the machine. " 191 echo "Once the machine has halted," 192 echo -n "remove the floppy, and press any key to " 193 echo "reboot." 194 exit 195 ;; 196 *) 197 echo -n "I want a yes or no answer... well? " 198 ;; 199 esac 200done 201echo "Initializing / (root) filesystem, and mounting..." 202$DONTDOIT newfs /dev/r${rdev}a $name 203$DONTDOIT mount -v /dev/${rdev}a /mnt 204echo "" 205echo -n "Creating a fstab..." 206mkdir -p $FSTABDIR 207echo "/dev/${rdev}a / ffs rw 1 1" > $FSTAB 208 209# get rid of this partition 210shiftvar $rdev 211shiftvar $rdev 212 213echo "" 214echo "Now lets setup your /usr file system" 215echo "(Once a valid input for drive and partition is seen" 216echo "it will be FORMATTED and inserted in the fstab.)" 217while [ "X$usrpart" = "X" ]; do 218 resp="" 219 drivename="" 220 while [ "X$resp" = "X" ]; do 221 echo "choices: $driveunits" 222 echo "which drive do you want /usr on?" 223 getresp 224 set -- $driveunits 225 while [ $# -gt 0 ]; do 226 if [ "X$resp" = "X$1" ]; then 227 drivename=$1 228 break; 229 else 230 shift 231 fi 232 done 233 if [ "X$drivename" != "X" ]; then 234 break 235 fi 236 done 237 238 usrpart="" 239 echo "You have selected $drivename" 240 echo "here is a list of partitions on $drivename" 241 disklabel $drivename 2>/dev/null | sed -e '/^[ ][ ][ad-p]:/p;/^#[ \t]*size/p;d' 242 echo "which partition would you like to format and have" 243 echo -n "mounted as /usr? (supply the letter): " 244 getresp 245 if [ "X$resp" = "X" ]; then 246 continue; 247 fi 248 249 list=$(getvar $drivename) 250 set -- $list 251 while [ $# -gt 0 ]; do 252 if [ "$resp" = "$1" ]; then 253 if [ "`echo $2 | sed -e 's,.*BSD.*,BSD,'`" != "BSD" ]; then 254 echo "" 255 echo -n "$drivename$resp is of type $2 which is not" 256 echo " a BSD filesystem type" 257 break 258 fi 259 usrpart=$drivename$resp 260 break 261 else 262 shift 263 shift 264 fi 265 done 266 if [ "X$usrpart" = "X" ]; then 267 echo "$resp is not a valid input." 268 echo "" 269 fi 270done 271 272echo "" 273echo "Initializing /usr filesystem, and mounting..." 274$DONTDOIT newfs /dev/r${usrpart} $name 275$DONTDOIT mkdir -p /mnt/usr 276$DONTDOIT mount -v /dev/${usrpart} /mnt/usr 277echo "" 278echo -n "Adding to fstab..." 279echo "/dev/${usrpart} /usr ffs rw 1 2" >> $FSTAB 280sync 281echo " done." 282 283echo "" 284echo "OK! The preliminary work of setting up your disk is now complete," 285echo "and you can install the actual NetBSD software." 286echo "" 287echo "Right now, your root is mounted on /mnt and your usr on /mnt/usr." 288echo "You should consult the installation notes to determine how to load" 289echo "and install the NetBSD distribution sets, and how to configure your" 290echo "system when you are done." 291echo "" 292echo "GOOD LUCK!" 293echo "" 294