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