upgrade.sh revision 1.2.4.1
1#!/bin/sh
2#	$NetBSD: upgrade.sh,v 1.2.4.1 1996/06/20 20:30:29 pk 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 REGENTS OR CONTRIBUTORS BE
30# 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
43ROOTDISK=""				# filled in below
44RELDIR=""				# Path searched for sets by install_sets
45export RELDIR				# on the local filesystems
46
47trap "umount -a > /dev/null 2>&1" 0
48
49MODE="upgrade"
50
51# include machine-dependent functions
52# The following functions must be provided:
53#	md_copy_kernel()	- copy a kernel to the installed disk
54#	md_get_diskdevs()	- return available disk devices
55#	md_get_cddevs()		- return available CD-ROM devices
56#	md_get_ifdevs()		- return available network interfaces
57#	md_get_partition_range() - return range of valid partition letters
58#	md_installboot()	- install boot-blocks on disk
59#	md_checkfordisklabel()	- check for valid disklabel
60#	md_labeldisk()		- put label on a disk
61#	md_welcome_banner()	- display friendly message
62#	md_not_going_to_install() - display friendly message
63#	md_congrats()		- display friendly message
64
65# include machine dependent subroutines
66. install.md
67
68# include common subroutines
69. install.sub
70
71get_reldir() {
72	while : ; do
73	    echo -n "Enter the pathname where the sets are stored [$RELDIR] "
74	    getresp "$RELDIR"
75	    RELDIR=$resp
76
77	    # Allow break-out with empty response
78	    if [ -z "$RELDIR" ]; then
79		echo -n "Are you sure you don't want to set the pathname? [n] "
80		getresp "n"
81		case "$resp" in
82			y*|Y*)
83				break
84				;;
85			*)
86				continue
87				;;
88		esac
89	    fi
90	    if dir_has_sets "/mnt/$RELDIR" $UPGRSETS
91	    then
92		break
93	    else
94		cat << \__get_reldir_1
95The directory $RELDIR does not exist, or does not hold any of the
96upgrade sets."
97__get_reldir_1
98		echo -n "Re-enter pathname? [y] "
99		getresp "y"
100		case "$resp" in
101			y*|Y*)
102				;;
103			*)
104				break
105				;;
106		esac
107	    fi
108	done
109}
110
111# Good {morning,afternoon,evening,night}.
112md_welcome_banner
113echo -n "Proceed with upgrade? [n] "
114getresp "n"
115case "$resp" in
116	y*|Y*)
117		echo	"Cool!  Let's get to it..."
118		;;
119	*)
120		md_not_going_to_install
121		exit
122		;;
123esac
124
125# Deal with terminal issues
126md_set_term
127
128# XXX Work around vnode aliasing bug (thanks for the tip, Chris...)
129ls -l /dev > /dev/null 2>&1
130
131# We don't like it, but it sure makes a few things a lot easier.
132do_mfs_mount "/tmp" "2048"
133
134while [ "X${ROOTDISK}" = "X" ]; do
135	getrootdisk
136done
137
138# Make sure there's a disklabel there.  If there isn't, puke after
139# disklabel prints the error message.
140md_checkfordisklabel ${ROOTDISK}
141case $rval in
142	1)
143		cat << \__disklabel_not_present_1
144
145FATAL ERROR: There is no disklabel present on the root disk!  You must
146label the disk with SYS_INST before continuing.
147
148__disklabel_not_present_1
149		exit
150		;;
151
152	2)
153		cat << \__disklabel_corrupted_1
154
155FATAL ERROR: The disklabel on the root disk is corrupted!  You must
156re-label the disk with SYS_INST before continuing.
157
158__disklabel_corrupted_1
159		exit
160		;;
161
162	*)
163		;;
164esac
165
166# Assume partition 'a' of $ROOTDISK is for the root filesystem.  Confirm
167# this with the user.  Check and mount the root filesystem.
168resp=""			# force one iteration
169while [ "X${resp}" = "X" ]; do
170	echo -n	"Root filesystem? [${ROOTDISK}a] "
171	getresp "${ROOTDISK}a"
172	_root_filesystem="/dev/`basename $resp`"
173	if [ ! -b ${_root_filesystem} ]; then
174		echo "Sorry, ${resp} is not a block device."
175		resp=""	# force loop to repeat
176	fi
177done
178
179echo	"Checking root filesystem..."
180if ! fsck -pf ${_root_filesystem}; then
181	echo	"ERROR: can't check root filesystem!"
182	exit 1
183fi
184
185echo	"Mounting root filesystem..."
186if ! mount -o ro ${_root_filesystem} /mnt; then
187	echo	"ERROR: can't mount root filesystem!"
188	exit 1
189fi
190
191# Grab the fstab so we can munge it for our own use.
192if [ ! -f /mnt/etc/fstab ]; then
193	echo	"ERROR: no /etc/fstab!"
194	exit 1
195fi
196cp /mnt/etc/fstab /tmp/fstab
197
198# Grab the hosts table so we can use it.
199if [ ! -f /mnt/etc/hosts ]; then
200	echo	"ERROR: no /etc/hosts!"
201	exit 1
202fi
203cp /mnt/etc/hosts /tmp/hosts
204
205# Start up the network in same/similar configuration as the installed system
206# uses.
207cat << \__network_config_1
208
209The upgrade program would now like to enable the network.  It will use the
210configuration already stored on the root filesystem.  This is required
211if you wish to use the network installation capabilities of this program.
212
213__network_config_1
214echo -n	"Enable network? [y] "
215getresp "y"
216case "$resp" in
217	y*|Y*)
218		if ! enable_network; then
219			echo "ERROR: can't enable network!"
220			exit 1
221		fi
222
223		cat << \__network_config_2
224
225You will now be given the opportunity to escape to the command shell to
226do any additional network configuration you may need.  This may include
227adding additional routes, if needed.  In addition, you might take this
228opportunity to redo the default route in the event that it failed above.
229
230__network_config_2
231		echo -n "Escape to shell? [n] "
232		getresp "n"
233		case "$resp" in
234			y*|Y*)
235				echo "Type 'exit' to return to upgrade."
236				sh
237				;;
238
239			*)
240				;;
241		esac
242		;;
243	*)
244		;;
245esac
246
247# Now that the network has been configured, it is safe to configure the
248# fstab.  We remove all but ufs/ffs/nfs.
249(
250	> /tmp/fstab.new
251	while read _dev _mp _fstype _rest ; do
252		if [ "X${_fstype}" = X"ufs" -o \
253		    "X${_fstype}" = X"ffs" -o \
254		    "X${_fstype}" = X"nfs" ]; then
255			if [ "X${_fstype}" = X"ufs" ]; then
256				# Convert ufs to ffs.
257				_fstype=ffs
258			fi
259			echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab.new
260		fi
261	done
262) < /tmp/fstab
263
264if [ ! -f /tmp/fstab.new ]; then
265	echo	"ERROR: strange fstab!"
266	exit 1
267fi
268
269rm -f /tmp/fstab.new
270
271echo	"The fstab is configured as follows:"
272echo	""
273cat /tmp/fstab
274cat << \__fstab_config_1
275
276You may wish to edit the fstab.  For example, you may need to resolve
277dependencies in the order which the filesystems are mounted.  Note that
278this fstab is only for installation purposes, and will not be copied into
279the root filesystem.
280
281__fstab_config_1
282echo -n	"Edit the fstab? [n] "
283getresp "n"
284case "$resp" in
285	y*|Y*)
286		${EDITOR} /tmp/fstab
287		;;
288
289	*)
290		;;
291esac
292
293echo	""
294munge_fstab /tmp/fstab /tmp/fstab.shadow
295
296if ! umount /mnt; then
297	echo	"ERROR: can't unmount previously mounted root!"
298	exit 1
299fi
300
301# Check all of the filesystems.
302check_fs /tmp/fstab.shadow
303
304# Mount filesystems.
305mount_fs /tmp/fstab.shadow
306
307
308echo -n	"Are the upgrade sets on one of your normally mounted filesystems? [y] "
309getresp "y"
310case "$resp" in
311	y*|Y*)
312		get_reldir
313		;;
314	*)
315		;;
316esac
317
318# Install sets.
319install_sets $UPGRSETS
320
321# Get timezone info
322get_timezone
323
324# Fix up the fstab.
325echo -n	"Converting ufs to ffs in /etc/fstab..."
326(
327	> /tmp/fstab
328	while read _dev _mp _fstype _rest ; do
329		if [ "X${_fstype}" = X"ufs" -o \
330		    "X${_fstype}" = X"ffs" -o \
331		    "X${_fstype}" = X"nfs" ]; then
332			if [ "X${_fstype}" = X"ufs" ]; then
333				# Convert ufs to ffs.
334				_fstype=ffs
335			fi
336			echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab
337		fi
338	done
339) < /mnt/etc/fstab
340echo	"done."
341echo -n	"Would you like to edit the resulting fstab? [y] "
342getresp "y"
343case "$resp" in
344	y*|Y*)
345		${EDITOR} /tmp/fstab
346		;;
347
348	*)
349		;;
350esac
351
352# Copy in configuration information and make devices in target root.
353(
354	cd /tmp
355	for file in fstab; do
356		if [ -f $file ]; then
357			echo -n "Copying $file..."
358			cp $file /mnt/etc/$file
359			echo "done."
360		fi
361	done
362
363	echo -n "Installing timezone link..."
364	rm -f /mnt/etc/localtime
365	ln -s /usr/share/zoneinfo/$TZ /mnt/etc/localtime
366	echo "done."
367
368	echo -n "Making devices..."
369	pid=`twiddle`
370	cd /mnt/dev
371	sh MAKEDEV all
372	kill $pid
373	echo "done."
374
375	md_copy_kernel
376
377	md_installboot ${ROOTDISK}
378)
379
380unmount_fs /tmp/fstab.shadow
381
382# Pat on the back.
383md_congrats
384
385# ALL DONE!
386exit 0
387