upgrade.sh revision 1.21 1 #!/bin/sh
2 # $NetBSD: upgrade.sh,v 1.21 2006/01/18 13:39:05 is 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
43 ROOTDISK="" # filled in below
44
45 trap "unmount_fs -fast /tmp/fstab.shadow > /dev/null 2>&1; rm -f /tmp/fstab.shadow" 0
46
47 MODE="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
72 Mydir=`expr $0 : '^\(.*\)/[^/]*$'`
73 Mydir=`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
77 Default_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?
86 THESETS="$UPGRSETS $MDSETS"
87
88 # Files that moved between 1.2 and 1.3
89 RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/dumpfs /usr/sbin/dumpfs"
90 RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/dumplfs /usr/sbin/dumplfs"
91 RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/nfsd /usr/sbin/nfsd"
92 RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/nfsiod /usr/sbin/nfsiod"
93 RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/mountd /usr/sbin/mountd"
94 RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/quotacheck /usr/sbin/quotacheck"
95 RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/rtquery /usr/sbin/rtquery"
96
97 # Files that moved between 1.3 and 1.4
98 RELOCATED_FILES_14="${RELOCATED_FILES_14} /sbin/newlfs /sbin/newfs_lfs"
99 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/games/chess /usr/games/chess"
100 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/games/hide/chess /usr/games/hide/chess"
101 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/share/games/gnuchess.book /usr/share/games/gnuchess.book"
102 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/share/games/atc/ATC_scores /usr/share/games/atc/ATC_scores"
103 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/share/games/atc/ATC_scores /usr/share/games/atc/ATC_scores"
104 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libamu.a /usr/lib/libamu.a"
105 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libamu_p.a /usr/lib/libamu_p.a"
106 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libamu_pic.a /usr/lib/libamu_pic.a"
107 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libbfd.a /usr/lib/libbfd.a"
108 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libbfd_pic.a /usr/lib/libbfd_pic.a"
109 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libg++.a /usr/lib/libg++.a"
110 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libg++_p.a /usr/lib/libg++_p.a"
111 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libg++_pic.a /usr/lib/libg++_pic.a"
112
113 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/gettable /usr/sbin/gettable"
114 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/dig /usr/bin/dig"
115 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/dnsquery /usr/bin/dnsquery"
116 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/htable /usr/bin/htable"
117 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/htable /usr/sbin/htable"
118 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/nslookup /usr/sbin/nslookup"
119
120 rm_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}.
133 md_welcome_banner
134 echo -n "Proceed with upgrade? [n] "
135 getresp "n"
136 case "$resp" in
137 y*|Y*)
138 echo "Cool! Let's get to it..."
139 ;;
140 *)
141 md_not_going_to_install
142 exit
143 ;;
144 esac
145
146 # Deal with terminal issues
147 md_set_term
148
149 # XXX Work around vnode aliasing bug (thanks for the tip, Chris...)
150 ls -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.
155 md_makerootwritable
156
157 test "$md_view_labels_possible" && md_view_labels
158
159 while [ "X${ROOTDISK}" = "X" ]; do
160 getrootdisk
161 done
162
163 # Assume partition 'a' of $ROOTDISK is for the root filesystem. Confirm
164 # this with the user. Check and mount the root filesystem.
165 resp="" # force one iteration
166 while [ "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
174 done
175
176 echo "Checking root filesystem..."
177 if ! fsck -pf ${_root_filesystem}; then
178 echo "ERROR: can't check root filesystem!"
179 exit 1
180 fi
181
182 echo "Mounting root filesystem..."
183 if ! mount -o ro ${_root_filesystem} /mnt; then
184 echo "ERROR: can't mount root filesystem!"
185 exit 1
186 fi
187
188 # Grab the fstab so we can munge it for our own use.
189 if [ ! -f /mnt/etc/fstab ]; then
190 echo "ERROR: no /etc/fstab!"
191 exit 1
192 fi
193
194 # Grab the hosts table so we can use it.
195 if [ ! -f /mnt/etc/hosts ]; then
196 echo "ERROR: no /etc/hosts!"
197 exit 1
198 fi
199 cp /mnt/etc/hosts /tmp/hosts
200
201 # Start up the network in same/similar configuration as the installed system
202 # uses.
203 cat << \__network_config_1
204
205 The upgrade program would now like to enable the network. It will use the
206 configuration already stored on the root filesystem. This is required
207 if you wish to use the network installation capabilities of this program.
208
209 __network_config_1
210 echo -n "Enable network? [y] "
211 getresp "y"
212 case "$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
221 You will now be given the opportunity to escape to the command shell to
222 do any additional network configuration you may need. This may include
223 adding additional routes, if needed. In addition, you might take this
224 opportunity 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 ;;
241 esac
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
259 echo "The fstab is configured as follows:"
260 echo ""
261 cat /tmp/fstab
262 cat << \__fstab_config_1
263
264 You may wish to edit the fstab. For example, you may need to resolve
265 dependencies in the order which the filesystems are mounted. Note that
266 this fstab is only for installation purposes, and will not be copied into
267 the root filesystem.
268
269 __fstab_config_1
270 echo -n "Edit the fstab? [n] "
271 getresp "n"
272 case "$resp" in
273 y*|Y*)
274 ${EDITOR} /tmp/fstab
275 ;;
276
277 *)
278 ;;
279 esac
280
281 echo ""
282 munge_fstab /tmp/fstab /tmp/fstab.shadow
283
284 if ! umount /mnt; then
285 echo "ERROR: can't unmount previously mounted root!"
286 exit 1
287 fi
288
289 # Check all of the filesystems.
290 check_fs /tmp/fstab.shadow
291
292 # Mount filesystems.
293 mount_fs /tmp/fstab.shadow
294
295 # Machine dependent preparation.
296 test "$md_upgrade_prep_needed" && {
297 md_prepare_upgrade || {
298 cat << 'EOF'
299 The preparations for upgrading your machine did not complete successfully.
300
301 EOF
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
315 echo -n "Are the upgrade sets on one of your normally mounted (local) filesystems? [y] "
316 getresp "y"
317 case "$resp" in
318 y*|Y*)
319 get_localdir /mnt
320 ;;
321 *)
322 ;;
323 esac
324
325 # Install sets.
326 install_sets
327
328 # Remove files that have just been installed in a new location
329 # from the old location
330 rm_relocated_files `eval echo \\$RELOCATED_FILES_${VERSION}`
331
332 # Get timezone info
333 get_timezone
334
335 # Fix up the fstab.
336 echo -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
347 echo "done."
348 echo -n "Would you like to edit the resulting fstab? [y] "
349 getresp "y"
350 case "$resp" in
351 y*|Y*)
352 ${EDITOR} /tmp/fstab
353 ;;
354
355 *)
356 ;;
357 esac
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
387 unmount_fs /tmp/fstab.shadow
388
389 # Pat on the back.
390 md_congrats
391
392 # ALL DONE!
393 exit 0
394