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