1#!/bin/sh
2#	$NetBSD: install.sh,v 1.1.1.1 2002/04/12 21:11:46 leo Exp $
3#
4# Copyright (c) 1996 The NetBSD Foundation, Inc.
5# All rights reserved.
6#
7# This code is derived from software contributed to The NetBSD Foundation
8# by Jason R. Thorpe.
9#
10# Redistribution and use in source and binary forms, with or without
11# modification, are permitted provided that the following conditions
12# are met:
13# 1. Redistributions of source code must retain the above copyright
14#    notice, this list of conditions and the following disclaimer.
15# 2. Redistributions in binary form must reproduce the above copyright
16#    notice, this list of conditions and the following disclaimer in the
17#    documentation and/or other materials provided with the distribution.
18# 3. All advertising materials mentioning features or use of this software
19#    must display the following acknowledgement:
20#        This product includes software developed by the NetBSD
21#        Foundation, Inc. and its contributors.
22# 4. Neither the name of The NetBSD Foundation nor the names of its
23#    contributors may be used to endorse or promote products derived
24#    from this software without specific prior written permission.
25#
26# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36# POSSIBILITY OF SUCH DAMAGE.
37#
38
39#	NetBSD installation script.
40#	In a perfect world, this would be a nice C program, with a reasonable
41#	user interface.
42
43FILESYSTEMS="/tmp/filesystems"		# used thoughout
44MODE="install"
45
46# include machine-dependent functions
47# The following functions must be provided:
48#	md_prep_disklabel()	- label the root disk
49#	md_welcome_banner()	- display friendly message
50#	md_congrats()		- display friendly message
51#	md_makerootwritable()	- make root writable (at least /tmp)
52
53# we need to make sure .'s below work if this directory is not in $PATH
54# dirname may not be available but expr is
55Mydir=`expr $0 : '^\(.*\)/[^/]*$'`
56Mydir=`cd ${Mydir:-.}; pwd`
57
58#
59# Sub-parts
60#
61getresp() {
62	read resp
63	if [ "X$resp" = "X" ]; then
64		resp=$1
65	fi
66}
67
68isin() {
69# test the first argument against the remaining ones, return succes on a match
70	_a=$1; shift
71	while [ $# != 0 ]; do
72		if [ "$_a" = "$1" ]; then return 0; fi
73		shift
74	done
75	return 1
76}
77
78getrootdisk() {
79	cat << \__getrootdisk_1
80
81The installation program needs to know which disk to consider
82the root disk.  Note the unit number may be different than
83the unit number you used in the standalone installation
84program.
85
86Available disks are:
87
88__getrootdisk_1
89	_DKDEVS=`md_get_diskdevs`
90	echo	"$_DKDEVS"
91	echo	""
92	echo -n	"Which disk is the root disk? "
93	getresp ""
94	if isin $resp $_DKDEVS ; then
95		ROOTDISK="$resp"
96	else
97		echo ""
98		echo "The disk $resp does not exist."
99		ROOTDISK=""
100	fi
101}
102
103labelmoredisks() {
104	cat << \__labelmoredisks_1
105
106You may label the following disks:
107
108__labelmoredisks_1
109	echo "$_DKDEVS"
110	echo	""
111	echo -n	"Label which disk? [done] "
112	getresp "done"
113	case "$resp" in
114		"done")
115			;;
116
117		*)
118			if isin $resp $_DKDEVS ; then
119				md_labeldisk $resp
120			else
121				echo ""
122				echo "The disk $resp does not exist."
123			fi
124			;;
125	esac
126}
127
128#
129# include machine dependent subroutines
130. $Mydir/install.md
131
132# Good {morning,afternoon,evening,night}.
133md_welcome_banner
134echo -n "Proceed? [n] "
135getresp "n"
136case "$resp" in
137	y*|Y*)
138		echo	"Cool!  Let's get to it..."
139		;;
140	*)
141		md_not_going_to_install
142		exit
143		;;
144esac
145
146# XXX Work around vnode aliasing bug (thanks for the tip, Chris...)
147ls -l /dev > /dev/null 2>&1
148
149# Deal with terminal issues
150md_set_term
151
152# Make sure we can write files (at least in /tmp)
153# This might make an MFS mount on /tmp, or it may
154# just re-mount the root with read-write enabled.
155md_makerootwritable
156
157while [ "X${ROOTDISK}" = "X" ]; do
158	getrootdisk
159done
160
161# Deal with disklabels, including editing the root disklabel
162# and labeling additional disks.  This is machine-dependent since
163# some platforms may not be able to provide this functionality.
164md_prep_disklabel ${ROOTDISK}
165
166# Pat on the back.
167md_congrats
168
169# ALL DONE!
170exit 0
171