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