Sync usage with man page.
[netbsd-mini2440.git] / distrib / bebox / floppies / ramdisk / upgrade.tmpl
blobfe41a7dc115ff9b2147a3349e4082b4b9dd79361
1 #!/bin/sh
2 # $NetBSD: upgrade.tmpl,v 1.5 2000/06/14 22:52:42 cgd Exp $
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.
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.
35 # <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
37 # NetBSD upgrade script.
38 # In a perfect world, this would be a nice C program, with a reasonable
39 # user interface.
41 DT=/etc/disktab # /etc/disktab
42 FSTABDIR=/mnt/etc # /mnt/etc
43 #DONTDOIT=echo
44 UARGS="-c 2"
46 FSTAB=${FSTABDIR}/fstab
48 getresp() {
49 read resp
50 if [ "X$resp" = "X" ]; then
51 resp=$1
55 echo "Welcome to the NetBSD @@VERSION@@ upgrade program."
56 echo ""
57 echo "This program is designed to help you put the new version of NetBSD"
58 echo "on your hard disk, in a simple and rational way. To upgrade, you"
59 echo "must have plenty of free space on all partitions which will be"
60 echo "upgraded. If you have at least 1MB free on your root partition,"
61 echo "and several free on your /usr patition, you should be fine."
62 echo ""
63 echo "As with anything which modifies your hard drive's contents, this"
64 echo "program can cause SIGNIFICANT data loss, and you are advised"
65 echo "to make sure your hard drive is backed up before beginning the"
66 echo "upgrade process."
67 echo ""
68 echo "Default answers are displyed in brackets after the questions."
69 echo "You can hit Control-C at any time to quit, but if you do so at a"
70 echo "prompt, you may have to hit return. Also, quitting in the middle of"
71 echo "the upgrade may leave your system in an inconsistent (and unusable)"
72 echo "state."
73 echo ""
74 echo -n "Proceed with upgrade? [n] "
75 getresp "n"
76 case "$resp" in
77 y*|Y*)
78 echo "Cool! Let's get to it..."
81 echo ""
82 echo "OK, then. Enter 'halt' at the prompt to halt the"
83 echo "machine. Once the machine has halted, remove the"
84 echo "floppy and press any key to reboot."
85 exit
87 esac
89 # find out what units are possible, and query the user.
90 driveunits=`ls /dev/[sw]d?a | sed -e 's,/dev/\(...\)a,\1,g'`
91 if [ "X${driveunits}" = "X" ]; then
92 echo "FATAL ERROR:"
93 echo "No disk devices."
94 echo "This is probably a bug in the install disks."
95 echo "Exiting install program."
96 exit
99 echo ""
100 echo "The following disks are supported by this upgrade procedure:"
101 echo " "${driveunits}
102 echo "If your system was previously completely contained within the"
103 echo "disks listed above (i.e. if your system didn't occupy any space"
104 echo "on disks NOT listed above), this upgrade disk can upgrade your"
105 echo "system. If it cannot, hit Control-C at the prompt."
106 echo ""
107 while [ "X${drivename}" = "X" ]; do
108 echo -n "Which disk contains your root partition? "
109 getresp
110 otherdrives=`echo "${driveunits}" | sed -e s,${resp},,`
111 if [ "X${driveunits}" = "X${otherdrives}" ]; then
112 echo ""
113 echo "\"${resp}\" is an invalid drive name. Valid choices"
114 echo "are: "${driveunits}
115 echo ""
116 else
117 drivename=${resp}
119 done
121 echo ""
122 echo "Root partition is on ${drivename}a."
124 echo ""
125 echo "If (and only if!) you are upgrading from NetBSD 0.9 or below,"
126 echo "you should upgrade to the new file system format. Do not answer"
127 echo "yes if you are upgrading from NetBSD 1.0 or above."
128 echo "Would you like to upgrade your file systems to the new file system"
129 echo -n "format? [y] "
130 getresp "y"
131 case "$resp" in
132 n*|N*)
133 echo ""
134 echo "If you are upgrading from NetBSD 0.9 or below,"
135 echo "you should upgrade your file systems with 'fsck -c 2'"
136 echo "as soon as is feasible, because the new file system"
137 echo "code is better-tested and more performant."
138 upgrargs=""
139 upgradefs=NO
142 upgrargs=$UARGS
143 upgradefs=YES
145 esac
147 if [ $upgradefs = YES ]; then
148 echo ""
149 echo "your file systems will be upgraded while they are checked"
152 echo "checking the file system on ${drivename}a..."
154 fsck -f -p $upgrargs /dev/r${drivename}a
155 if [ $? != 0 ]; then
156 echo "FATAL ERROR: FILE SYSTEM UPGRADE FAILED."
157 echo "You should probably reboot the machine, fsck your"
158 echo "disk(s), and try the upgrade procedure again."
159 exit 1
162 echo ""
163 echo "Mounting root partition on /mnt..."
164 mount /dev/${drivename}a /mnt
165 if [ $? != 0 ]; then
166 echo "FATAL ERROR: MOUNT FAILED."
167 echo "You should verify that your system is set up as you"
168 echo "described, and re-attempt the upgrade procedure."
169 exit 1
171 echo "Done."
173 echo ""
174 echo -n "Copying new fsck binary to your hard disk..."
175 if [ ! -d /mnt/sbin ]; then
176 mkdir /mnt/sbin
178 cp /sbin/fsck /mnt/sbin/fsck
179 if [ $? != 0 ]; then
180 echo "FATAL ERROR: COPY FAILED."
181 echo "It in unclear why this error would occur. It looks"
182 echo "like you may end up having to upgrade by hand."
183 exit 1
185 echo " Done."
187 echo ""
188 echo "Re-mounting root partition read-only..."
189 mount -u -o ro /dev/${drivename}a /mnt
190 if [ $? != 0 ]; then
191 echo "FATAL ERROR: RE-MOUNT FAILED."
192 echo "It in unclear why this error would occur. It looks"
193 echo "like you may end up having to upgrade by hand."
194 exit 1
196 echo "Done."
198 echo ""
199 echo "checking the rest of your file systems..."
200 chroot /mnt fsck -f -p $upgrargs
201 if [ $? != 0 ]; then
202 echo "FATAL ERROR: FILE SYSTEM UPGRADE(S) FAILED."
203 echo "You should probably reboot the machine, fsck your"
204 echo "file system(s), and try the upgrade procedure"
205 echo "again."
206 exit 1
208 echo "Done."
210 echo ""
211 echo "Re-mounting root partition read-write..."
212 mount -u -o rw /dev/${drivename}a /mnt
213 if [ $? != 0 ]; then
214 echo "FATAL ERROR: RE-MOUNT FAILED."
215 echo "It in unclear why this error would occur. It looks"
216 echo "like you may end up having to upgrade by hand."
217 exit 1
219 echo "Done."
221 echo ""
222 echo "Copying bootstrapping binaries and config files to the hard drive..."
223 $DONTDOIT cp /mnt/.profile /mnt/.profile.bak
224 $DONTDOIT pax -s '#^\./etc/.*##' -Xrwpe . /mnt
225 $DONTDOIT mv /mnt/etc/rc /mnt/etc/rc.bak
226 $DONTDOIT cp /tmp/.hdprofile /mnt/.profile
228 echo ""
229 echo "Mounting remaining partitions..."
230 chroot /mnt mount -at ffs > /dev/null 2>&1
231 echo "Done."
233 echo ""
234 echo ""
235 echo "OK! The preliminary work of setting up your disk is now complete,"
236 echo "and you can now upgrade the actual NetBSD software."
237 echo ""
238 echo "Right now, your hard disk is mounted on /mnt. You should consult"
239 echo "the installation notes to determine how to load and install the new"
240 echo "NetBSD distribution sets, and how to clean up after the upgrade"
241 echo "software, when you are done."
242 echo ""
243 echo "GOOD LUCK!"
244 echo ""