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