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