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