2 # $NetBSD: upgrade.sh,v 1.21 2006/01/18 13:39:05 is Exp $
4 # Copyright (c) 1996-2000,2006 The NetBSD Foundation, Inc.
7 # This code is derived from software contributed to The NetBSD Foundation
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
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.
19 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
32 # NetBSD installation script.
33 # In a perfect world, this would be a nice C program, with a reasonable
36 ROOTDISK
="" # filled in below
38 trap "unmount_fs -fast /tmp/fstab.shadow > /dev/null 2>&1; rm -f /tmp/fstab.shadow" 0
42 # include machine-dependent functions
43 # The following functions must be provided:
44 # md_copy_kernel() - copy a kernel to the installed disk
45 # md_get_diskdevs() - return available disk devices
46 # md_get_cddevs() - return available CD-ROM devices
47 # md_get_ifdevs() - return available network interfaces
48 # md_get_partition_range() - return range of valid partition letters
49 # md_installboot() - install boot-blocks on disk
50 # md_labeldisk() - put label on a disk
51 # md_welcome_banner() - display friendly message
52 # md_not_going_to_install() - display friendly message
53 # md_congrats() - display friendly message
54 # md_set_term - set terminal type
55 # md_makerootwritable - what it says
57 # md_upgrade_prep_needed - variable: set if you md_prepare_upgrade()
58 # md_prepare_upgrade - any machine dependent preparations
59 # md_view_labels_possible - variable: md_view_labels defined
60 # md_view_labels - peek at preexisting disk labels, to
61 # better identify disks
63 # we need to make sure .'s below work if this directory is not in $PATH
64 # dirname may not be available but expr is
65 Mydir
=`expr $0 : '^\(.*\)/[^/]*$'`
66 Mydir
=`cd ${Mydir:-.}; pwd`
68 # this is the most likely place to find the binary sets
69 # so save them having to type it in
70 Default_sets_dir
=$Mydir/..
/..
/binary
/sets
72 # include machine dependent subroutines
75 # include common subroutines
79 THESETS
="$UPGRSETS $MDSETS"
81 # Files that moved between 1.2 and 1.3
82 RELOCATED_FILES_13
="${RELOCATED_FILES_13} /sbin/dumpfs /usr/sbin/dumpfs"
83 RELOCATED_FILES_13
="${RELOCATED_FILES_13} /sbin/dumplfs /usr/sbin/dumplfs"
84 RELOCATED_FILES_13
="${RELOCATED_FILES_13} /sbin/nfsd /usr/sbin/nfsd"
85 RELOCATED_FILES_13
="${RELOCATED_FILES_13} /sbin/nfsiod /usr/sbin/nfsiod"
86 RELOCATED_FILES_13
="${RELOCATED_FILES_13} /sbin/mountd /usr/sbin/mountd"
87 RELOCATED_FILES_13
="${RELOCATED_FILES_13} /sbin/quotacheck /usr/sbin/quotacheck"
88 RELOCATED_FILES_13
="${RELOCATED_FILES_13} /sbin/rtquery /usr/sbin/rtquery"
90 # Files that moved between 1.3 and 1.4
91 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /sbin/newlfs /sbin/newfs_lfs"
92 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/games/chess /usr/games/chess"
93 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/games/hide/chess /usr/games/hide/chess"
94 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/share/games/gnuchess.book /usr/share/games/gnuchess.book"
95 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/share/games/atc/ATC_scores /usr/share/games/atc/ATC_scores"
96 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/share/games/atc/ATC_scores /usr/share/games/atc/ATC_scores"
97 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/lib/libamu.a /usr/lib/libamu.a"
98 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/lib/libamu_p.a /usr/lib/libamu_p.a"
99 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/lib/libamu_pic.a /usr/lib/libamu_pic.a"
100 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/lib/libbfd.a /usr/lib/libbfd.a"
101 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/lib/libbfd_pic.a /usr/lib/libbfd_pic.a"
102 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/lib/libg++.a /usr/lib/libg++.a"
103 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/lib/libg++_p.a /usr/lib/libg++_p.a"
104 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/lib/libg++_pic.a /usr/lib/libg++_pic.a"
106 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/sbin/gettable /usr/sbin/gettable"
107 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/sbin/dig /usr/bin/dig"
108 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/sbin/dnsquery /usr/bin/dnsquery"
109 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/sbin/htable /usr/bin/htable"
110 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/sbin/htable /usr/sbin/htable"
111 RELOCATED_FILES_14
="${RELOCATED_FILES_14} /usr/sbin/nslookup /usr/sbin/nslookup"
115 # ($n, $(n+1)): pairs of (old,new) locations of relocated files
116 while [ $# -ge 2 ]; do
125 # Good {morning,afternoon,evening,night}.
127 echo -n "Proceed with upgrade? [n] "
131 echo "Cool! Let's get to it..."
134 md_not_going_to_install
139 # Deal with terminal issues
142 # XXX Work around vnode aliasing bug (thanks for the tip, Chris...)
143 ls -l /dev
> /dev
/null
2>&1
145 # Make sure we can write files (at least in /tmp)
146 # This might make an MFS mount on /tmp, or it may
147 # just re-mount the root with read-write enabled.
150 test "$md_view_labels_possible" && md_view_labels
152 while [ "X${ROOTDISK}" = "X" ]; do
156 # Assume partition 'a' of $ROOTDISK is for the root filesystem. Confirm
157 # this with the user. Check and mount the root filesystem.
158 resp
="" # force one iteration
159 while [ "X${resp}" = "X" ]; do
160 echo -n "Root filesystem? [${ROOTDISK}a] "
161 getresp
"${ROOTDISK}a"
162 _root_filesystem
="/dev/`basename $resp`"
163 if [ ! -b ${_root_filesystem} ]; then
164 echo "Sorry, ${resp} is not a block device."
165 resp
="" # force loop to repeat
169 echo "Checking root filesystem..."
170 if ! fsck
-pf ${_root_filesystem}; then
171 echo "ERROR: can't check root filesystem!"
175 echo "Mounting root filesystem..."
176 if ! mount
-o ro
${_root_filesystem} /mnt
; then
177 echo "ERROR: can't mount root filesystem!"
181 # Grab the fstab so we can munge it for our own use.
182 if [ ! -f /mnt
/etc
/fstab
]; then
183 echo "ERROR: no /etc/fstab!"
187 # Grab the hosts table so we can use it.
188 if [ ! -f /mnt
/etc
/hosts
]; then
189 echo "ERROR: no /etc/hosts!"
192 cp /mnt
/etc
/hosts
/tmp
/hosts
194 # Start up the network in same/similar configuration as the installed system
196 cat << \__network_config_1
198 The upgrade program would now like to
enable the network. It will use the
199 configuration already stored on the root filesystem. This is required
200 if you wish to use the network installation capabilities of this program.
203 echo -n "Enable network? [y] "
207 if ! enable_network
; then
208 echo "ERROR: can't enable network!"
212 cat << \__network_config_2
214 You will now be given the opportunity to escape to the
command shell to
215 do any additional network configuration you may need. This may include
216 adding additional routes
, if needed. In addition
, you might take this
217 opportunity to redo the default route
in the event that it failed above.
220 echo -n "Escape to shell? [n] "
224 echo "Type 'exit' to return to upgrade."
236 # Now that the network has been configured, it is safe to configure the
237 # fstab. We remove all but ufs/ffs.
240 while read _dev _mp _fstype _rest
; do
241 if [ "X${_fstype}" = X
"ufs" -o \
242 "X${_fstype}" = X
"ffs" ]; then
243 if [ "X${_fstype}" = X
"ufs" ]; then
244 # Convert ufs to ffs.
247 echo "$_dev $_mp $_fstype $_rest" >> /tmp
/fstab
252 echo "The fstab is configured as follows:"
255 cat << \__fstab_config_1
257 You may wish to edit the fstab. For example
, you may need to resolve
258 dependencies
in the order
which the filesystems are mounted. Note that
259 this fstab is only
for installation purposes
, and will not be copied into
263 echo -n "Edit the fstab? [n] "
275 munge_fstab
/tmp
/fstab
/tmp
/fstab.shadow
277 if ! umount
/mnt
; then
278 echo "ERROR: can't unmount previously mounted root!"
282 # Check all of the filesystems.
283 check_fs
/tmp
/fstab.shadow
286 mount_fs
/tmp
/fstab.shadow
288 # Machine dependent preparation.
289 test "$md_upgrade_prep_needed" && {
290 md_prepare_upgrade ||
{
292 The preparations
for upgrading your machine did not complete successfully.
295 echo -n "Continue anyway? [n]"
308 echo -n "Are the upgrade sets on one of your normally mounted (local) filesystems? [y] "
321 # Remove files that have just been installed in a new location
322 # from the old location
323 rm_relocated_files
`eval echo \\$RELOCATED_FILES_${VERSION}`
329 echo -n "Converting ufs to ffs in /etc/fstab..."
332 while read _dev _mp _fstype _rest
; do
333 if [ "X${_fstype}" = X
"ufs" ]; then
334 # Convert ufs to ffs.
337 echo "$_dev $_mp $_fstype $_rest" >> /tmp
/fstab
341 echo -n "Would you like to edit the resulting fstab? [y] "
352 # Copy in configuration information and make devices in target root.
355 for file in fstab
; do
356 if [ -f $file ]; then
357 echo -n "Copying $file..."
358 cp $file /mnt
/etc
/$file
363 echo -n "Installing timezone link..."
364 rm -f /mnt
/etc
/localtime
365 ln -s /usr
/share
/zoneinfo
/$TZ /mnt
/etc
/localtime
368 echo -n "Making devices..."
377 md_installboot
${ROOTDISK}
380 unmount_fs
/tmp
/fstab.shadow