upgrade.sh revision 1.3
1#!/bin/sh
2# $NetBSD: upgrade.sh,v 1.3 2003/07/26 17:06:26 salo Exp $
3#
4# Copyright (c) 1997 Perry E. Metzger
5# Copyright (c) 1994 Christopher G. Demetriou
6# All rights reserved.
7# 
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16# 3. All advertising materials mentioning features or use of this software
17#    must display the following acknowledgement:
18#          This product includes software developed for the
19#          NetBSD Project.  See http://www.NetBSD.org/ for
20#          information about NetBSD.
21# 4. The name of the author may not be used to endorse or promote products
22#    derived from this software without specific prior written permission.
23# 
24# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34# 
35# <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
36
37#	NetBSD upgrade script.
38#	In a perfect world, this would be a nice C program, with a reasonable
39#	user interface.
40
41DT=/etc/disktab				# /etc/disktab
42FSTABDIR=/mnt/etc			# /mnt/etc
43#DONTDOIT=echo
44UARGS="-c 2"
45
46FSTAB=${FSTABDIR}/fstab
47
48getresp() {
49	read resp
50	if [ "X$resp" = "X" ]; then
51		resp=$1
52	fi
53}
54
55echo	"Welcome to the original NetBSD/alpha upgrade program."
56getresp
57echo	"This version of the program has been largely replaced by the new
58echo	"sysinst utility. Both programs are on this installation media set.
59echo -n "Type the return key to continue..."
60echo	""
61echo	"This program is designed to help you put the new version of NetBSD"
62echo	"on your hard disk, in a simple and rational way.  To upgrade, you"
63echo	"must have plenty of free space on all partitions which will be"
64echo	"upgraded.  If you have at least 1MB free on your root partition,"
65echo	"and several free on your /usr patition, you should be fine."
66echo	""
67echo	"As with anything which modifies your hard drive's contents, this"
68echo	"program can cause SIGNIFICANT data loss, and you are advised"
69echo	"to make sure your hard drive is backed up before beginning the"
70echo	"upgrade process."
71echo	""
72echo	"Default answers are displyed in brackets after the questions."
73echo	"You can hit Control-C at any time to quit, but if you do so at a"
74echo	"prompt, you may have to hit return.  Also, quitting in the middle of"
75echo	"the upgrade may leave your system in an inconsistent (and unusable)"
76echo	"state."
77echo	""
78echo -n "Proceed with upgrade? [n] "
79getresp "n"
80case "$resp" in
81	y*|Y*)
82		echo	"Cool!  Let's get to it..."
83		;;
84	*)
85		echo	""
86		echo	"OK, then.  Enter 'halt' at the prompt to halt the"
87		echo	"machine.  Once the machine has halted, remove the"
88		echo	"floppy and press any key to reboot."
89		exit
90		;;
91esac
92
93# find out what units are possible, and query the user.
94driveunits=`echo /dev/[sw]d?a | sed -e 's,/dev/\(...\)a,\1,g'`
95if [ "X${driveunits}" = "X" ]; then
96	echo	"FATAL ERROR:"
97	echo	"No disk devices."
98	echo	"This is probably a bug in the install disks."
99	echo	"Exiting install program."
100	exit
101fi
102
103echo	""
104echo	"The following disks are supported by this upgrade procedure:"
105echo	"	"${driveunits}
106echo	"If your system was previously completely contained within the"
107echo	"disks listed above (i.e. if your system didn't occupy any space"
108echo	"on disks NOT listed above), this upgrade disk can upgrade your"
109echo	"system.  If it cannot, hit Control-C at the prompt."
110echo	""
111while [ "X${drivename}" = "X" ]; do
112	echo -n	"Which disk contains your root partition? "
113	getresp
114	otherdrives=`echo "${driveunits}" | sed -e s,${resp},,`
115	if [ "X${driveunits}" = "X${otherdrives}" ]; then
116		echo	""
117		echo	"\"${resp}\" is an invalid drive name.  Valid choices"
118		echo	"are: "${driveunits}
119		echo	""
120	else
121		drivename=${resp}
122	fi
123done
124
125echo	""
126echo	"Root partition is on ${drivename}a."
127
128echo	""
129echo	"If (and only if!) you are upgrading from NetBSD 0.9 or below,"
130echo	"you should upgrade to the new file system format. Do not answer"
131echo	"yes if you are upgrading from NetBSD 1.0 or above."
132echo	"Would you like to upgrade your file systems to the new file system"
133echo -n	"format? [y] "
134getresp "y"
135case "$resp" in
136	n*|N*)
137		echo	""
138		echo	"If you are upgrading from NetBSD 0.9 or below,"
139		echo	"you should upgrade your file systems with 'fsck -c 2'"
140		echo	"as soon as is feasible, because the new file system"
141		echo	"code is better-tested and more performant."
142		upgrargs=""
143		upgradefs=NO
144		;;
145	*)
146		upgrargs=$UARGS
147		upgradefs=YES
148		;;
149esac
150
151if [ $upgradefs = YES ]; then
152	echo	""
153	echo	"your file systems will be upgraded while they are checked"
154fi
155
156echo	"checking the file system on ${drivename}a..."
157	
158fsck -f -p $upgrargs /dev/r${drivename}a
159if [ $? != 0 ]; then
160	echo	"FATAL ERROR: FILE SYSTEM UPGRADE FAILED."
161	echo	"You should probably reboot the machine, fsck your"
162	echo	"disk(s), and try the upgrade procedure again."
163	exit 1
164fi
165
166echo	""
167echo	"Mounting root partition on /mnt..."
168mount /dev/${drivename}a /mnt
169if [ $? != 0 ]; then
170	echo	"FATAL ERROR: MOUNT FAILED."
171	echo	"You should verify that your system is set up as you"
172	echo	"described, and re-attempt the upgrade procedure."
173	exit 1
174fi
175echo	"Done."
176
177echo	""
178echo -n	"Copying new fsck binary to your hard disk..."
179if [ ! -d /mnt/sbin ]; then
180	mkdir /mnt/sbin
181fi
182cp /sbin/fsck /mnt/sbin/fsck
183if [ $? != 0 ]; then
184	echo	"FATAL ERROR: COPY FAILED."
185	echo	"It in unclear why this error would occur.  It looks"
186	echo	"like you may end up having to upgrade by hand."
187	exit 1
188fi
189echo	" Done."
190
191echo	""
192echo    "Re-mounting root partition read-only..."
193mount -u -o ro /dev/${drivename}a /mnt
194if [ $? != 0 ]; then
195	echo	"FATAL ERROR: RE-MOUNT FAILED."
196	echo	"It in unclear why this error would occur.  It looks"
197	echo	"like you may end up having to upgrade by hand."
198	exit 1
199fi
200echo	"Done."
201
202echo	""
203echo	"checking the rest of your file systems..."
204chroot /mnt fsck -f -p $upgrargs
205if [ $? != 0 ]; then
206	echo	"FATAL ERROR: FILE SYSTEM UPGRADE(S) FAILED."
207	echo	"You should probably reboot the machine, fsck your"
208	echo	"file system(s), and try the upgrade procedure"
209	echo	"again."
210	exit 1
211fi
212	echo	"Done."
213
214echo	""
215echo    "Re-mounting root partition read-write..."
216mount -u -o rw /dev/${drivename}a /mnt
217if [ $? != 0 ]; then
218	echo	"FATAL ERROR: RE-MOUNT FAILED."
219	echo	"It in unclear why this error would occur.  It looks"
220	echo	"like you may end up having to upgrade by hand."
221	exit 1
222fi
223echo	"Done."
224
225echo	""
226echo	"Updating boot blocks on ${drivename}..."
227# shouldn't be needed, but...
228$DONTDOIT rm -f /mnt/boot
229$DONTDOIT cp /usr/mdec/boot /mnt/boot
230$DONTDOIT /usr/sbin/installboot /dev/r${drivename}c /usr/mdec/bootxx_ffs
231if [ $? != 0 ]; then
232	echo	"FATAL ERROR: UPDATE OF DISK LABEL FAILED."
233	echo	"It in unclear why this error would occur.  It looks"
234	echo	"like you may end up having to upgrade by hand."
235	exit 1
236fi
237echo	"Done."
238
239echo	""
240echo	"Copying bootstrapping binaries and config files to the hard drive..."
241$DONTDOIT cp /mnt/.profile /mnt/.profile.bak
242$DONTDOIT pax -s '#^\./etc/.*##' -Xrwpe . /mnt
243$DONTDOIT mv /mnt/etc/rc /mnt/etc/rc.bak
244$DONTDOIT cp /tmp/.hdprofile /mnt/.profile
245
246echo	""
247echo	"Mounting remaining partitions..."
248chroot /mnt mount -at ffs > /dev/null 2>&1
249echo	"Done."
250
251echo    ""
252echo    ""
253echo	"OK!  The preliminary work of setting up your disk is now complete,"
254echo	"and you can now upgrade the actual NetBSD software."
255echo	""
256echo	"Right now, your hard disk is mounted on /mnt.  You should consult"
257echo	"the installation notes to determine how to load and install the new"
258echo	"NetBSD distribution sets, and how to clean up after the upgrade"
259echo	"software, when you are done."
260echo	""
261echo	"GOOD LUCK!"
262echo	""
263