upgrade.sh revision 1.15 1 #!/bin/sh
2 # $NetBSD: upgrade.sh,v 1.15 1998/01/23 22:36:39 veego Exp $
3 #
4 # Copyright (c) 1996 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
62 # include machine dependent subroutines
63 . install.md
64
65 # include common subroutines
66 . install.sub
67
68 # which sets?
69 THESETS="$UPGRSETS"
70
71 # Files that moved between 1.2 and 1.3
72 RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/dumpfs /usr/sbin/dumpfs"
73 RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/dumplfs /usr/sbin/dumplfs"
74 RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/nfsd /usr/sbin/nfsd"
75 RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/nfsiod /usr/sbin/nfsiod"
76 RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/mountd /usr/sbin/mountd"
77 RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/quotacheck /usr/sbin/quotacheck"
78 RELOCATED_FILES_13="${RELOCATED_FILES_13} /sbin/rtquery /usr/sbin/rtquery"
79
80 # Files that moved between 1.3 and 1.4
81 RELOCATED_FILES_14="${RELOCATED_FILES_14} /usr/sbin/ipnat /sbin/ipnat"
82
83 rm_relocated_files()
84 {
85 # ($n, $(n+1)): pairs of (old,new) locations of relocated files
86 while [ $# -ge 2 ]; do
87 if [ -f "$2" ]; then
88 echo Removing "$1";
89 rm -f "$1"
90 fi
91 shift 2
92 done
93 }
94
95 # Good {morning,afternoon,evening,night}.
96 md_welcome_banner
97 echo -n "Proceed with upgrade? [n] "
98 getresp "n"
99 case "$resp" in
100 y*|Y*)
101 echo "Cool! Let's get to it..."
102 ;;
103 *)
104 md_not_going_to_install
105 exit
106 ;;
107 esac
108
109 # Deal with terminal issues
110 md_set_term
111
112 # XXX Work around vnode aliasing bug (thanks for the tip, Chris...)
113 ls -l /dev > /dev/null 2>&1
114
115 # Make sure we can write files (at least in /tmp)
116 # This might make an MFS mount on /tmp, or it may
117 # just re-mount the root with read-write enabled.
118 md_makerootwritable
119
120 while [ "X${ROOTDISK}" = "X" ]; do
121 getrootdisk
122 done
123
124 # Assume partition 'a' of $ROOTDISK is for the root filesystem. Confirm
125 # this with the user. Check and mount the root filesystem.
126 resp="" # force one iteration
127 while [ "X${resp}" = "X" ]; do
128 echo -n "Root filesystem? [${ROOTDISK}a] "
129 getresp "${ROOTDISK}a"
130 _root_filesystem="/dev/`basename $resp`"
131 if [ ! -b ${_root_filesystem} ]; then
132 echo "Sorry, ${resp} is not a block device."
133 resp="" # force loop to repeat
134 fi
135 done
136
137 echo "Checking root filesystem..."
138 if ! fsck -pf ${_root_filesystem}; then
139 echo "ERROR: can't check root filesystem!"
140 exit 1
141 fi
142
143 echo "Mounting root filesystem..."
144 if ! mount -o ro ${_root_filesystem} /mnt; then
145 echo "ERROR: can't mount root filesystem!"
146 exit 1
147 fi
148
149 # Grab the fstab so we can munge it for our own use.
150 if [ ! -f /mnt/etc/fstab ]; then
151 echo "ERROR: no /etc/fstab!"
152 exit 1
153 fi
154
155 # Grab the hosts table so we can use it.
156 if [ ! -f /mnt/etc/hosts ]; then
157 echo "ERROR: no /etc/hosts!"
158 exit 1
159 fi
160 cp /mnt/etc/hosts /tmp/hosts
161
162 # Start up the network in same/similar configuration as the installed system
163 # uses.
164 cat << \__network_config_1
165
166 The upgrade program would now like to enable the network. It will use the
167 configuration already stored on the root filesystem. This is required
168 if you wish to use the network installation capabilities of this program.
169
170 __network_config_1
171 echo -n "Enable network? [y] "
172 getresp "y"
173 case "$resp" in
174 y*|Y*)
175 if ! enable_network; then
176 echo "ERROR: can't enable network!"
177 exit 1
178 fi
179
180 cat << \__network_config_2
181
182 You will now be given the opportunity to escape to the command shell to
183 do any additional network configuration you may need. This may include
184 adding additional routes, if needed. In addition, you might take this
185 opportunity to redo the default route in the event that it failed above.
186
187 __network_config_2
188 echo -n "Escape to shell? [n] "
189 getresp "n"
190 case "$resp" in
191 y*|Y*)
192 echo "Type 'exit' to return to upgrade."
193 sh
194 ;;
195
196 *)
197 ;;
198 esac
199 ;;
200 *)
201 ;;
202 esac
203
204 # Now that the network has been configured, it is safe to configure the
205 # fstab. We remove all but ufs/ffs.
206 (
207 > /tmp/fstab
208 while read _dev _mp _fstype _rest ; do
209 if [ "X${_fstype}" = X"ufs" -o \
210 "X${_fstype}" = X"ffs" ]; then
211 if [ "X${_fstype}" = X"ufs" ]; then
212 # Convert ufs to ffs.
213 _fstype=ffs
214 fi
215 echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab
216 fi
217 done
218 ) < /mnt/etc/fstab
219
220 echo "The fstab is configured as follows:"
221 echo ""
222 cat /tmp/fstab
223 cat << \__fstab_config_1
224
225 You may wish to edit the fstab. For example, you may need to resolve
226 dependencies in the order which the filesystems are mounted. Note that
227 this fstab is only for installation purposes, and will not be copied into
228 the root filesystem.
229
230 __fstab_config_1
231 echo -n "Edit the fstab? [n] "
232 getresp "n"
233 case "$resp" in
234 y*|Y*)
235 ${EDITOR} /tmp/fstab
236 ;;
237
238 *)
239 ;;
240 esac
241
242 echo ""
243 munge_fstab /tmp/fstab /tmp/fstab.shadow
244
245 if ! umount /mnt; then
246 echo "ERROR: can't unmount previously mounted root!"
247 exit 1
248 fi
249
250 # Check all of the filesystems.
251 check_fs /tmp/fstab.shadow
252
253 # Mount filesystems.
254 mount_fs /tmp/fstab.shadow
255
256 echo -n "Are the upgrade sets on one of your normally mounted (local) filesystems? [y] "
257 getresp "y"
258 case "$resp" in
259 y*|Y*)
260 get_localdir /mnt
261 ;;
262 *)
263 ;;
264 esac
265
266 # Install sets.
267 install_sets
268
269 # Remove files that have just been installed in a new location
270 # from the old location
271 rm_relocated_files `eval echo \\$RELOCATED_FILES_${VERSION}`
272
273 # Get timezone info
274 get_timezone
275
276 # Fix up the fstab.
277 echo -n "Converting ufs to ffs in /etc/fstab..."
278 (
279 > /tmp/fstab
280 while read _dev _mp _fstype _rest ; do
281 if [ "X${_fstype}" = X"ufs" ]; then
282 # Convert ufs to ffs.
283 _fstype=ffs
284 fi
285 echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab
286 done
287 ) < /mnt/etc/fstab
288 echo "done."
289 echo -n "Would you like to edit the resulting fstab? [y] "
290 getresp "y"
291 case "$resp" in
292 y*|Y*)
293 ${EDITOR} /tmp/fstab
294 ;;
295
296 *)
297 ;;
298 esac
299
300 # Copy in configuration information and make devices in target root.
301 (
302 cd /tmp
303 for file in fstab; do
304 if [ -f $file ]; then
305 echo -n "Copying $file..."
306 cp $file /mnt/etc/$file
307 echo "done."
308 fi
309 done
310
311 echo -n "Installing timezone link..."
312 rm -f /mnt/etc/localtime
313 ln -s /usr/share/zoneinfo/$TZ /mnt/etc/localtime
314 echo "done."
315
316 echo -n "Making devices..."
317 _pid=`twiddle`
318 cd /mnt/dev
319 sh MAKEDEV all
320 kill $_pid
321 echo "done."
322
323 md_copy_kernel
324
325 md_installboot ${ROOTDISK}
326 )
327
328 unmount_fs /tmp/fstab.shadow
329
330 # Pat on the back.
331 md_congrats
332
333 # ALL DONE!
334 exit 0
335