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