upgrade.sh revision 1.20.12.1
1#!/bin/sh
2#	$NetBSD: upgrade.sh,v 1.20.12.1 2006/01/27 22:45:49 tron Exp $
3#
4# Copyright (c) 1996-2000,2006 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
43ROOTDISK=""				# filled in below
44
45trap "unmount_fs -fast /tmp/fstab.shadow > /dev/null 2>&1; rm -f /tmp/fstab.shadow" 0
46
47MODE="upgrade"
48
49# include machine-dependent functions
50# The following functions must be provided:
51#	md_copy_kernel()	- copy a kernel to the installed disk
52#	md_get_diskdevs()	- return available disk devices
53#	md_get_cddevs()		- return available CD-ROM devices
54#	md_get_ifdevs()		- return available network interfaces
55#	md_get_partition_range() - return range of valid partition letters
56#	md_installboot()	- install boot-blocks on disk
57#	md_labeldisk()		- put label on a disk
58#	md_welcome_banner()	- display friendly message
59#	md_not_going_to_install() - display friendly message
60#	md_congrats()		- display friendly message
61#	md_set_term		- set terminal type
62#	md_makerootwritable	- what it says
63# optional:
64#	md_upgrade_prep_needed	- variable: set if you md_prepare_upgrade()
65#	md_prepare_upgrade	- any machine dependent preparations
66#	md_view_labels_possible	- variable: md_view_labels defined
67#	md_view_labels		- peek at preexisting disk labels, to 
68#				  better identify disks
69
70# we need to make sure .'s below work if this directory is not in $PATH
71# dirname may not be available but expr is
72Mydir=`expr $0 : '^\(.*\)/[^/]*$'`
73Mydir=`cd ${Mydir:-.}; pwd`
74
75# this is the most likely place to find the binary sets
76# so save them having to type it in
77Default_sets_dir=$Mydir/../../binary/sets
78
79# include machine dependent subroutines
80. $Mydir/install.md
81
82# include common subroutines
83. $Mydir/install.sub
84
85# which sets?
86THESETS="$UPGRSETS $MDSETS"
87
88# Files that moved between 1.2 and 1.3
89RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/dumpfs /usr/sbin/dumpfs"
90RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/dumplfs /usr/sbin/dumplfs"
91RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/nfsd /usr/sbin/nfsd"
92RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/nfsiod /usr/sbin/nfsiod"
93RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/mountd /usr/sbin/mountd"
94RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/quotacheck /usr/sbin/quotacheck"
95RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/rtquery /usr/sbin/rtquery"
96
97# Files that moved between 1.3 and 1.4
98RELOCATED_FILES_14="${RELOCATED_FILES_14} /sbin/newlfs /sbin/newfs_lfs"
99RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/games/chess /usr/games/chess"
100RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/games/hide/chess /usr/games/hide/chess"
101RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/share/games/gnuchess.book /usr/share/games/gnuchess.book"
102RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/share/games/atc/ATC_scores /usr/share/games/atc/ATC_scores"
103RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/share/games/atc/ATC_scores /usr/share/games/atc/ATC_scores"
104RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libamu.a /usr/lib/libamu.a"
105RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libamu_p.a /usr/lib/libamu_p.a"
106RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libamu_pic.a /usr/lib/libamu_pic.a"
107RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libbfd.a /usr/lib/libbfd.a"
108RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libbfd_pic.a /usr/lib/libbfd_pic.a"
109RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libg++.a /usr/lib/libg++.a"
110RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libg++_p.a /usr/lib/libg++_p.a"
111RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libg++_pic.a /usr/lib/libg++_pic.a"
112
113RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/gettable /usr/sbin/gettable"
114RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/dig /usr/bin/dig"
115RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/dnsquery /usr/bin/dnsquery"
116RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/htable /usr/bin/htable"
117RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/htable /usr/sbin/htable"
118RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/nslookup /usr/sbin/nslookup"
119
120rm_relocated_files()
121{
122	# ($n, $(n+1)): pairs of (old,new) locations of relocated files
123	while [ $# -ge 2 ]; do
124		if [ -f "$2" ]; then
125			echo Removing "$1";
126			rm -f "$1"
127		fi
128		shift 2
129	done
130}
131
132# Good {morning,afternoon,evening,night}.
133md_welcome_banner
134echo -n "Proceed with upgrade? [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# Deal with terminal issues
147md_set_term
148
149# XXX Work around vnode aliasing bug (thanks for the tip, Chris...)
150ls -l /dev > /dev/null 2>&1
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
157test "$md_view_labels_possible" && md_view_labels
158
159while [ "X${ROOTDISK}" = "X" ]; do
160	getrootdisk
161done
162
163# Assume partition 'a' of $ROOTDISK is for the root filesystem.  Confirm
164# this with the user.  Check and mount the root filesystem.
165resp=""			# force one iteration
166while [ "X${resp}" = "X" ]; do
167	echo -n	"Root filesystem? [${ROOTDISK}a] "
168	getresp "${ROOTDISK}a"
169	_root_filesystem="/dev/`basename $resp`"
170	if [ ! -b ${_root_filesystem} ]; then
171		echo "Sorry, ${resp} is not a block device."
172		resp=""	# force loop to repeat
173	fi
174done
175
176echo	"Checking root filesystem..."
177if ! fsck -pf ${_root_filesystem}; then
178	echo	"ERROR: can't check root filesystem!"
179	exit 1
180fi
181
182echo	"Mounting root filesystem..."
183if ! mount -o ro ${_root_filesystem} /mnt; then
184	echo	"ERROR: can't mount root filesystem!"
185	exit 1
186fi
187
188# Grab the fstab so we can munge it for our own use.
189if [ ! -f /mnt/etc/fstab ]; then
190	echo	"ERROR: no /etc/fstab!"
191	exit 1
192fi
193
194# Grab the hosts table so we can use it.
195if [ ! -f /mnt/etc/hosts ]; then
196	echo	"ERROR: no /etc/hosts!"
197	exit 1
198fi
199cp /mnt/etc/hosts /tmp/hosts
200
201# Start up the network in same/similar configuration as the installed system
202# uses.
203cat << \__network_config_1
204
205The upgrade program would now like to enable the network.  It will use the
206configuration already stored on the root filesystem.  This is required
207if you wish to use the network installation capabilities of this program.
208
209__network_config_1
210echo -n	"Enable network? [y] "
211getresp "y"
212case "$resp" in
213	y*|Y*)
214		if ! enable_network; then
215			echo "ERROR: can't enable network!"
216			exit 1
217		fi
218
219		cat << \__network_config_2
220
221You will now be given the opportunity to escape to the command shell to
222do any additional network configuration you may need.  This may include
223adding additional routes, if needed.  In addition, you might take this
224opportunity to redo the default route in the event that it failed above.
225
226__network_config_2
227		echo -n "Escape to shell? [n] "
228		getresp "n"
229		case "$resp" in
230			y*|Y*)
231				echo "Type 'exit' to return to upgrade."
232				sh
233				;;
234
235			*)
236				;;
237		esac
238		;;
239	*)
240		;;
241esac
242
243# Now that the network has been configured, it is safe to configure the
244# fstab.  We remove all but ufs/ffs.
245(
246	> /tmp/fstab
247	while read _dev _mp _fstype _rest ; do
248		if [ "X${_fstype}" = X"ufs" -o \
249		     "X${_fstype}" = X"ffs" ]; then
250			if [ "X${_fstype}" = X"ufs" ]; then
251				# Convert ufs to ffs.
252				_fstype=ffs
253			fi
254			echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab
255		fi
256	done
257) < /mnt/etc/fstab
258
259echo	"The fstab is configured as follows:"
260echo	""
261cat /tmp/fstab
262cat << \__fstab_config_1
263
264You may wish to edit the fstab.  For example, you may need to resolve
265dependencies in the order which the filesystems are mounted.  Note that
266this fstab is only for installation purposes, and will not be copied into
267the root filesystem.
268
269__fstab_config_1
270echo -n	"Edit the fstab? [n] "
271getresp "n"
272case "$resp" in
273	y*|Y*)
274		${EDITOR} /tmp/fstab
275		;;
276
277	*)
278		;;
279esac
280
281echo	""
282munge_fstab /tmp/fstab /tmp/fstab.shadow
283
284if ! umount /mnt; then
285	echo	"ERROR: can't unmount previously mounted root!"
286	exit 1
287fi
288
289# Check all of the filesystems.
290check_fs /tmp/fstab.shadow
291
292# Mount filesystems.
293mount_fs /tmp/fstab.shadow
294
295# Machine dependent preparation.
296test "$md_upgrade_prep_needed" && {
297	md_prepare_upgrade || {
298		cat << 'EOF'
299The preparations for upgrading your machine did not complete successfully.
300
301EOF
302		echo -n "Continue anyway? [n]"
303		getresp "n"
304		case "$resp" in
305			y*|Y*)
306				;;
307			*)
308				exit 1
309				;;
310		esac
311	}
312}
313
314
315echo -n	"Are the upgrade sets on one of your normally mounted (local) filesystems? [y] "
316getresp "y"
317case "$resp" in
318	y*|Y*)
319		get_localdir /mnt
320		;;
321	*)
322		;;
323esac
324
325# Install sets.
326install_sets
327
328# Remove files that have just been installed in a new location
329# from the old location
330rm_relocated_files `eval echo \\$RELOCATED_FILES_${VERSION}`
331
332# Get timezone info
333get_timezone
334
335# Fix up the fstab.
336echo -n	"Converting ufs to ffs in /etc/fstab..."
337(
338	> /tmp/fstab
339	while read _dev _mp _fstype _rest ; do
340		if [ "X${_fstype}" = X"ufs" ]; then
341			# Convert ufs to ffs.
342			_fstype=ffs
343		fi
344		echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab
345	done
346) < /mnt/etc/fstab
347echo	"done."
348echo -n	"Would you like to edit the resulting fstab? [y] "
349getresp "y"
350case "$resp" in
351	y*|Y*)
352		${EDITOR} /tmp/fstab
353		;;
354
355	*)
356		;;
357esac
358
359# Copy in configuration information and make devices in target root.
360(
361	cd /tmp
362	for file in fstab; do
363		if [ -f $file ]; then
364			echo -n "Copying $file..."
365			cp $file /mnt/etc/$file
366			echo "done."
367		fi
368	done
369
370	echo -n "Installing timezone link..."
371	rm -f /mnt/etc/localtime
372	ln -s /usr/share/zoneinfo/$TZ /mnt/etc/localtime
373	echo "done."
374
375	echo -n "Making devices..."
376	_pid=`twiddle`
377	cd /mnt/dev
378	sh MAKEDEV all
379	kill $_pid
380	echo "done."
381
382	md_copy_kernel
383
384	md_installboot ${ROOTDISK}
385)
386
387unmount_fs /tmp/fstab.shadow
388
389# Pat on the back.
390md_congrats
391
392# ALL DONE!
393exit 0
394