Annotation of src/distrib/miniroot/upgrade.sh, Revision 1.20
1.1 pk 1: #!/bin/sh
1.20 ! pk 2: # $NetBSD: upgrade.sh,v 1.19 1999/11/02 06:11:25 sjg Exp $
1.1 pk 3: #
1.2 thorpej 4: # Copyright (c) 1996 The NetBSD Foundation, Inc.
1.1 pk 5: # All rights reserved.
6: #
1.2 thorpej 7: # This code is derived from software contributed to The NetBSD Foundation
8: # by Jason R. Thorpe.
9: #
1.1 pk 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:
1.2 thorpej 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.
1.1 pk 25: #
1.2 thorpej 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
1.12 jtc 29: # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30: # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1.2 thorpej 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.
1.1 pk 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:
1.6 pk 45: trap "unmount_fs -fast /tmp/fstab.shadow > /dev/null 2>&1; rm -f /tmp/fstab.shadow" 0
1.1 pk 46:
47: MODE="upgrade"
48:
49: # include machine-dependent functions
50: # The following functions must be provided:
1.3 leo 51: # md_copy_kernel() - copy a kernel to the installed disk
1.1 pk 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
1.3 leo 55: # md_get_partition_range() - return range of valid partition letters
1.1 pk 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
1.20 ! pk 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
1.3 leo 66:
1.19 sjg 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
69: Mydir=`expr $0 : '^\(.*\)/[^/]*$'`
70: Mydir=`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
74: Default_sets_dir=$Mydir/../../binary/sets
75:
1.3 leo 76: # include machine dependent subroutines
1.19 sjg 77: . $Mydir/install.md
1.1 pk 78:
79: # include common subroutines
1.19 sjg 80: . $Mydir/install.sub
1.1 pk 81:
1.8 jtc 82: # which sets?
1.17 is 83: THESETS="$UPGRSETS $MDSETS"
1.8 jtc 84:
1.9 pk 85: # Files that moved between 1.2 and 1.3
1.13 pk 86: RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/dumpfs /usr/sbin/dumpfs"
87: RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/dumplfs /usr/sbin/dumplfs"
88: RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/nfsd /usr/sbin/nfsd"
89: RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/nfsiod /usr/sbin/nfsiod"
1.11 pk 90: RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/mountd /usr/sbin/mountd"
1.13 pk 91: RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/quotacheck /usr/sbin/quotacheck"
1.14 pk 92: RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/rtquery /usr/sbin/rtquery"
1.18 pk 93:
94: # Files that moved between 1.3 and 1.4
95: RELOCATED_FILES_14="${RELOCATED_FILES_14} /sbin/newlfs /sbin/newfs_lfs"
96: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/games/chess /usr/games/chess"
97: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/games/hide/chess /usr/games/hide/chess"
98: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/share/games/gnuchess.book /usr/share/games/gnuchess.book"
99: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/share/games/atc/ATC_scores /usr/share/games/atc/ATC_scores"
100: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/share/games/atc/ATC_scores /usr/share/games/atc/ATC_scores"
101: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libamu.a /usr/lib/libamu.a"
102: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libamu_p.a /usr/lib/libamu_p.a"
103: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libamu_pic.a /usr/lib/libamu_pic.a"
104: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libbfd.a /usr/lib/libbfd.a"
105: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libbfd_pic.a /usr/lib/libbfd_pic.a"
106: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libg++.a /usr/lib/libg++.a"
107: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libg++_p.a /usr/lib/libg++_p.a"
108: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/lib/libg++_pic.a /usr/lib/libg++_pic.a"
109:
110: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/gettable /usr/sbin/gettable"
111: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/dig /usr/bin/dig"
112: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/dnsquery /usr/bin/dnsquery"
113: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/htable /usr/bin/htable"
114: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/htable /usr/sbin/htable"
115: RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/nslookup /usr/sbin/nslookup"
1.9 pk 116:
117: rm_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:
1.1 pk 129: # Good {morning,afternoon,evening,night}.
130: md_welcome_banner
131: echo -n "Proceed with upgrade? [n] "
132: getresp "n"
133: case "$resp" in
134: y*|Y*)
135: echo "Cool! Let's get to it..."
136: ;;
137: *)
138: md_not_going_to_install
139: exit
140: ;;
141: esac
142:
143: # Deal with terminal issues
144: md_set_term
145:
146: # XXX Work around vnode aliasing bug (thanks for the tip, Chris...)
147: ls -l /dev > /dev/null 2>&1
148:
1.8 jtc 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.
152: md_makerootwritable
1.1 pk 153:
154: while [ "X${ROOTDISK}" = "X" ]; do
155: getrootdisk
156: done
157:
158: # Assume partition 'a' of $ROOTDISK is for the root filesystem. Confirm
159: # this with the user. Check and mount the root filesystem.
160: resp="" # force one iteration
161: while [ "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
169: done
170:
171: echo "Checking root filesystem..."
172: if ! fsck -pf ${_root_filesystem}; then
173: echo "ERROR: can't check root filesystem!"
174: exit 1
175: fi
176:
177: echo "Mounting root filesystem..."
178: if ! mount -o ro ${_root_filesystem} /mnt; then
179: echo "ERROR: can't mount root filesystem!"
180: exit 1
181: fi
182:
183: # Grab the fstab so we can munge it for our own use.
184: if [ ! -f /mnt/etc/fstab ]; then
185: echo "ERROR: no /etc/fstab!"
186: exit 1
187: fi
188:
189: # Grab the hosts table so we can use it.
190: if [ ! -f /mnt/etc/hosts ]; then
191: echo "ERROR: no /etc/hosts!"
192: exit 1
193: fi
194: cp /mnt/etc/hosts /tmp/hosts
195:
196: # Start up the network in same/similar configuration as the installed system
197: # uses.
198: cat << \__network_config_1
199:
200: The upgrade program would now like to enable the network. It will use the
201: configuration already stored on the root filesystem. This is required
202: if you wish to use the network installation capabilities of this program.
203:
204: __network_config_1
205: echo -n "Enable network? [y] "
206: getresp "y"
207: case "$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:
216: You will now be given the opportunity to escape to the command shell to
217: do any additional network configuration you may need. This may include
218: adding additional routes, if needed. In addition, you might take this
219: opportunity 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: ;;
236: esac
237:
238: # Now that the network has been configured, it is safe to configure the
1.7 pk 239: # fstab. We remove all but ufs/ffs.
1.1 pk 240: (
1.7 pk 241: > /tmp/fstab
1.4 pk 242: while read _dev _mp _fstype _rest ; do
1.1 pk 243: if [ "X${_fstype}" = X"ufs" -o \
1.7 pk 244: "X${_fstype}" = X"ffs" ]; then
1.4 pk 245: if [ "X${_fstype}" = X"ufs" ]; then
246: # Convert ufs to ffs.
247: _fstype=ffs
248: fi
1.7 pk 249: echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab
1.1 pk 250: fi
251: done
1.7 pk 252: ) < /mnt/etc/fstab
1.1 pk 253:
254: echo "The fstab is configured as follows:"
255: echo ""
256: cat /tmp/fstab
257: cat << \__fstab_config_1
258:
259: You may wish to edit the fstab. For example, you may need to resolve
260: dependencies in the order which the filesystems are mounted. Note that
261: this fstab is only for installation purposes, and will not be copied into
262: the root filesystem.
263:
264: __fstab_config_1
265: echo -n "Edit the fstab? [n] "
266: getresp "n"
267: case "$resp" in
268: y*|Y*)
1.3 leo 269: ${EDITOR} /tmp/fstab
1.1 pk 270: ;;
271:
272: *)
273: ;;
274: esac
275:
276: echo ""
277: munge_fstab /tmp/fstab /tmp/fstab.shadow
278:
279: if ! umount /mnt; then
280: echo "ERROR: can't unmount previously mounted root!"
281: exit 1
282: fi
283:
284: # Check all of the filesystems.
285: check_fs /tmp/fstab.shadow
286:
287: # Mount filesystems.
288: mount_fs /tmp/fstab.shadow
1.20 ! pk 289:
! 290: # Machine dependent preparation.
! 291: test "$md_upgrade_prep_needed" && {
! 292: md_prepare_upgrade || {
! 293: cat << 'EOF'
! 294: The preparations for upgrading your machine did not complete successfully.
! 295:
! 296: EOF
! 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:
1.1 pk 309:
1.6 pk 310: echo -n "Are the upgrade sets on one of your normally mounted (local) filesystems? [y] "
1.3 leo 311: getresp "y"
312: case "$resp" in
313: y*|Y*)
1.6 pk 314: get_localdir /mnt
1.3 leo 315: ;;
316: *)
317: ;;
318: esac
319:
1.1 pk 320: # Install sets.
1.6 pk 321: install_sets
1.9 pk 322:
323: # Remove files that have just been installed in a new location
324: # from the old location
325: rm_relocated_files `eval echo \\$RELOCATED_FILES_${VERSION}`
1.1 pk 326:
327: # Get timezone info
328: get_timezone
329:
330: # Fix up the fstab.
331: echo -n "Converting ufs to ffs in /etc/fstab..."
1.4 pk 332: (
333: > /tmp/fstab
334: while read _dev _mp _fstype _rest ; do
1.7 pk 335: if [ "X${_fstype}" = X"ufs" ]; then
336: # Convert ufs to ffs.
337: _fstype=ffs
1.4 pk 338: fi
1.7 pk 339: echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab
1.4 pk 340: done
341: ) < /mnt/etc/fstab
1.1 pk 342: echo "done."
343: echo -n "Would you like to edit the resulting fstab? [y] "
344: getresp "y"
345: case "$resp" in
346: y*|Y*)
1.3 leo 347: ${EDITOR} /tmp/fstab
1.1 pk 348: ;;
349:
350: *)
351: ;;
352: esac
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..."
1.6 pk 371: _pid=`twiddle`
1.1 pk 372: cd /mnt/dev
373: sh MAKEDEV all
1.6 pk 374: kill $_pid
1.1 pk 375: echo "done."
376:
1.3 leo 377: md_copy_kernel
1.1 pk 378:
379: md_installboot ${ROOTDISK}
380: )
381:
382: unmount_fs /tmp/fstab.shadow
383:
384: # Pat on the back.
385: md_congrats
386:
387: # ALL DONE!
388: exit 0
CVSweb <webmaster@jp.NetBSD.org>