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