Home | History | Annotate | Line # | Download | only in inst
install.sh revision 1.7
      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 
     36 FSTABDIR=/mnt/etc			# /mnt/etc
     37 #DONTDOIT==echo
     38 
     39 VERSION=1.2
     40 FSTAB=${FSTABDIR}/fstab
     41 
     42 getresp() {
     43 	read resp
     44 	if [ "X$resp" = "X" ]; then
     45 		resp=$1
     46 	fi
     47 }
     48 
     49 getvar() {
     50 	echo $(eval $(echo "echo \$$1"))
     51 }
     52 
     53 shiftvar() {
     54 	local - var
     55 	var="$1"
     56 	list="$(getvar $var)"
     57 	set -- $list
     58 	shift
     59 	setvar $var "$*"
     60 }
     61 
     62 getparts() {
     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 
     70 getdrives() {
     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 
     86 prepdrive() {
     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 
     96 echo	"Welcome to the NetBSD ${VERSION} installation program."
     97 echo	""
     98 echo	"This program is designed to help you put NetBSD on your hard disk,"
     99 echo	"in a simple and rational way.  Its main objective is to format,"
    100 echo	"mount and create an fstab for your root (/) and user (/usr)"
    101 echo	"partitions."
    102 echo	""
    103 echo	"As with anything which modifies your hard drive's contents, this"
    104 echo	"program can cause SIGNIFICANT data loss, and you are advised"
    105 echo	"to make sure your hard drive is backed up before beginning the"
    106 echo	"installation process."
    107 echo	""
    108 echo	"Default answers are displayed in brackets after the questions."
    109 echo	"You can hit Control-C at any time to quit, but if you do so at a"
    110 echo	"prompt, you may have to hit return.  Also, quitting in the middle of"
    111 echo	"installation may leave your system in an inconsistent state."
    112 echo	""
    113 echo -n "Proceed with installation? [n] "
    114 getresp "n"
    115 case "$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 		;;
    126 esac
    127 
    128 drivetype=sd
    129 sect_fwd=""
    130 
    131 # find out what units are possible for that disk, and query the user.
    132 getdrives
    133 for 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
    138 done
    139 
    140 echo	""
    141 echo	"The following root devices are available on your machine:"
    142 echo	"      "${driveunits}
    143 echo	""
    144 prefdev=${rdev}
    145 rdev=""
    146 while [ "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
    157 done
    158 
    159 echo	""
    160 echo	"The root device you have chosen is on: ${rdev}"
    161 echo	""
    162 # driveunits=`ls /dev/${drivetype}?a | sed -e 's,/dev/\(...\)a,\1,g'`
    163 if [ "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
    169 fi
    170 
    171 echo	""
    172 echo	"THIS IS YOUR LAST CHANCE!!!"
    173 echo	""
    174 echo	"(answering yes will format your root partition on $rdev)"
    175 echo -n	"Are you SURE you want NetBSD installed on your hard drive? (yes/no) "
    176 answer=""
    177 while [ "$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
    196 done
    197 echo	"Initializing / (root) filesystem, and mounting..."
    198 $DONTDOIT newfs /dev/r${rdev}a $name
    199 $DONTDOIT mount -v /dev/${rdev}a /mnt
    200 echo	""
    201 echo -n	"Creating a fstab..."
    202 mkdir -p $FSTABDIR
    203 echo "/dev/${rdev}a	/	ffs	rw	1	1" > $FSTAB
    204 
    205 # get rid of this partition
    206 shiftvar $rdev
    207 shiftvar $rdev
    208 
    209 echo	""
    210 echo	"Now lets setup your /usr file system"
    211 echo	"(Once a valid input for drive and partition is seen"
    212 echo	"it will be FORMATTED and inserted in the fstab.)"
    213 while [ "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
    266 done
    267 
    268 echo	""
    269 echo	"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
    273 echo	""
    274 echo -n	"Adding to fstab..."
    275 echo "/dev/${usrpart}	/usr	ffs	rw	1	2" >> $FSTAB
    276 sync
    277 echo	" done."
    278 
    279 echo	""
    280 echo	"OK!  The preliminary work of setting up your disk is now complete,"
    281 echo	"and you can install the actual NetBSD software."
    282 echo	""
    283 echo	"Right now, your root is mounted on /mnt and your usr on /mnt/usr."
    284 echo	"You should consult the installation notes to determine how to load"
    285 echo	"and install the NetBSD distribution sets, and how to configure your"
    286 echo	"system when you are done."
    287 echo	""
    288 echo	"GOOD LUCK!"
    289 echo	""
    290