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