upgrade.sh revision 1.5 1 1.1 pk #!/bin/sh
2 1.5 leo # $NetBSD: upgrade.sh,v 1.5 1996/05/30 06:57:17 leo Exp $
3 1.1 pk #
4 1.2 thorpej # Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.1 pk # All rights reserved.
6 1.1 pk #
7 1.2 thorpej # This code is derived from software contributed to The NetBSD Foundation
8 1.2 thorpej # by Jason R. Thorpe.
9 1.2 thorpej #
10 1.1 pk # Redistribution and use in source and binary forms, with or without
11 1.1 pk # modification, are permitted provided that the following conditions
12 1.1 pk # are met:
13 1.1 pk # 1. Redistributions of source code must retain the above copyright
14 1.1 pk # notice, this list of conditions and the following disclaimer.
15 1.1 pk # 2. Redistributions in binary form must reproduce the above copyright
16 1.1 pk # notice, this list of conditions and the following disclaimer in the
17 1.1 pk # documentation and/or other materials provided with the distribution.
18 1.1 pk # 3. All advertising materials mentioning features or use of this software
19 1.1 pk # must display the following acknowledgement:
20 1.2 thorpej # This product includes software developed by the NetBSD
21 1.2 thorpej # Foundation, Inc. and its contributors.
22 1.2 thorpej # 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2 thorpej # contributors may be used to endorse or promote products derived
24 1.2 thorpej # from this software without specific prior written permission.
25 1.1 pk #
26 1.2 thorpej # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2 thorpej # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2 thorpej # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2 thorpej # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
30 1.2 thorpej # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2 thorpej # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2 thorpej # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2 thorpej # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2 thorpej # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2 thorpej # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2 thorpej # POSSIBILITY OF SUCH DAMAGE.
37 1.1 pk #
38 1.1 pk
39 1.1 pk # NetBSD installation script.
40 1.1 pk # In a perfect world, this would be a nice C program, with a reasonable
41 1.1 pk # user interface.
42 1.1 pk
43 1.1 pk ROOTDISK="" # filled in below
44 1.3 leo RELDIR="" # Path searched for sets by install_sets
45 1.3 leo export RELDIR # on the local filesystems
46 1.1 pk
47 1.3 leo trap "umount -a > /dev/null 2>&1" 0
48 1.1 pk
49 1.1 pk MODE="upgrade"
50 1.1 pk
51 1.1 pk # include machine-dependent functions
52 1.1 pk # The following functions must be provided:
53 1.3 leo # md_copy_kernel() - copy a kernel to the installed disk
54 1.1 pk # md_get_diskdevs() - return available disk devices
55 1.1 pk # md_get_cddevs() - return available CD-ROM devices
56 1.1 pk # md_get_ifdevs() - return available network interfaces
57 1.3 leo # md_get_partition_range() - return range of valid partition letters
58 1.1 pk # md_installboot() - install boot-blocks on disk
59 1.1 pk # md_checkfordisklabel() - check for valid disklabel
60 1.1 pk # md_labeldisk() - put label on a disk
61 1.1 pk # md_welcome_banner() - display friendly message
62 1.1 pk # md_not_going_to_install() - display friendly message
63 1.1 pk # md_congrats() - display friendly message
64 1.3 leo
65 1.3 leo # include machine dependent subroutines
66 1.1 pk . install.md
67 1.1 pk
68 1.1 pk # include common subroutines
69 1.1 pk . install.sub
70 1.1 pk
71 1.3 leo get_reldir() {
72 1.3 leo while : ; do
73 1.3 leo echo -n "Enter the pathname where the sets are stored [$RELDIR] "
74 1.3 leo getresp "$RELDIR"
75 1.3 leo RELDIR=$resp
76 1.3 leo
77 1.3 leo # Allow break-out with empty response
78 1.3 leo if [ -z "$RELDIR" ]; then
79 1.3 leo echo -n "Are you sure you don't want to set the pathname? [n] "
80 1.3 leo getresp "n"
81 1.3 leo case "$resp" in
82 1.3 leo y*|Y*)
83 1.3 leo break
84 1.3 leo ;;
85 1.3 leo *)
86 1.3 leo continue
87 1.3 leo ;;
88 1.3 leo esac
89 1.3 leo fi
90 1.5 leo if dir_has_sets "/mnt/$RELDIR" $UPGRSETS
91 1.5 leo then
92 1.3 leo break
93 1.3 leo else
94 1.5 leo cat << \__get_reldir_1
95 1.5 leo The directory $RELDIR does not exist, or does not hold any of the
96 1.5 leo upgrade sets."
97 1.5 leo __get_reldir_1
98 1.5 leo echo -n "Re-enter pathname? [y] "
99 1.3 leo getresp "y"
100 1.3 leo case "$resp" in
101 1.3 leo y*|Y*)
102 1.3 leo ;;
103 1.3 leo *)
104 1.3 leo break
105 1.3 leo ;;
106 1.3 leo esac
107 1.3 leo fi
108 1.3 leo done
109 1.3 leo }
110 1.3 leo
111 1.1 pk # Good {morning,afternoon,evening,night}.
112 1.1 pk md_welcome_banner
113 1.1 pk echo -n "Proceed with upgrade? [n] "
114 1.1 pk getresp "n"
115 1.1 pk case "$resp" in
116 1.1 pk y*|Y*)
117 1.1 pk echo "Cool! Let's get to it..."
118 1.1 pk ;;
119 1.1 pk *)
120 1.1 pk md_not_going_to_install
121 1.1 pk exit
122 1.1 pk ;;
123 1.1 pk esac
124 1.1 pk
125 1.1 pk # Deal with terminal issues
126 1.1 pk md_set_term
127 1.1 pk
128 1.1 pk # XXX Work around vnode aliasing bug (thanks for the tip, Chris...)
129 1.1 pk ls -l /dev > /dev/null 2>&1
130 1.1 pk
131 1.1 pk # We don't like it, but it sure makes a few things a lot easier.
132 1.1 pk do_mfs_mount "/tmp" "2048"
133 1.1 pk
134 1.1 pk while [ "X${ROOTDISK}" = "X" ]; do
135 1.1 pk getrootdisk
136 1.1 pk done
137 1.1 pk
138 1.1 pk # Make sure there's a disklabel there. If there isn't, puke after
139 1.1 pk # disklabel prints the error message.
140 1.1 pk md_checkfordisklabel ${ROOTDISK}
141 1.1 pk case $rval in
142 1.1 pk 1)
143 1.1 pk cat << \__disklabel_not_present_1
144 1.1 pk
145 1.1 pk FATAL ERROR: There is no disklabel present on the root disk! You must
146 1.1 pk label the disk with SYS_INST before continuing.
147 1.1 pk
148 1.1 pk __disklabel_not_present_1
149 1.1 pk exit
150 1.1 pk ;;
151 1.1 pk
152 1.1 pk 2)
153 1.1 pk cat << \__disklabel_corrupted_1
154 1.1 pk
155 1.1 pk FATAL ERROR: The disklabel on the root disk is corrupted! You must
156 1.1 pk re-label the disk with SYS_INST before continuing.
157 1.1 pk
158 1.1 pk __disklabel_corrupted_1
159 1.1 pk exit
160 1.1 pk ;;
161 1.1 pk
162 1.1 pk *)
163 1.1 pk ;;
164 1.1 pk esac
165 1.1 pk
166 1.1 pk # Assume partition 'a' of $ROOTDISK is for the root filesystem. Confirm
167 1.1 pk # this with the user. Check and mount the root filesystem.
168 1.1 pk resp="" # force one iteration
169 1.1 pk while [ "X${resp}" = "X" ]; do
170 1.1 pk echo -n "Root filesystem? [${ROOTDISK}a] "
171 1.1 pk getresp "${ROOTDISK}a"
172 1.1 pk _root_filesystem="/dev/`basename $resp`"
173 1.1 pk if [ ! -b ${_root_filesystem} ]; then
174 1.1 pk echo "Sorry, ${resp} is not a block device."
175 1.1 pk resp="" # force loop to repeat
176 1.1 pk fi
177 1.1 pk done
178 1.1 pk
179 1.1 pk echo "Checking root filesystem..."
180 1.1 pk if ! fsck -pf ${_root_filesystem}; then
181 1.1 pk echo "ERROR: can't check root filesystem!"
182 1.1 pk exit 1
183 1.1 pk fi
184 1.1 pk
185 1.1 pk echo "Mounting root filesystem..."
186 1.1 pk if ! mount -o ro ${_root_filesystem} /mnt; then
187 1.1 pk echo "ERROR: can't mount root filesystem!"
188 1.1 pk exit 1
189 1.1 pk fi
190 1.1 pk
191 1.1 pk # Grab the fstab so we can munge it for our own use.
192 1.1 pk if [ ! -f /mnt/etc/fstab ]; then
193 1.1 pk echo "ERROR: no /etc/fstab!"
194 1.1 pk exit 1
195 1.1 pk fi
196 1.1 pk cp /mnt/etc/fstab /tmp/fstab
197 1.1 pk
198 1.1 pk # Grab the hosts table so we can use it.
199 1.1 pk if [ ! -f /mnt/etc/hosts ]; then
200 1.1 pk echo "ERROR: no /etc/hosts!"
201 1.1 pk exit 1
202 1.1 pk fi
203 1.1 pk cp /mnt/etc/hosts /tmp/hosts
204 1.1 pk
205 1.1 pk # Start up the network in same/similar configuration as the installed system
206 1.1 pk # uses.
207 1.1 pk cat << \__network_config_1
208 1.1 pk
209 1.1 pk The upgrade program would now like to enable the network. It will use the
210 1.1 pk configuration already stored on the root filesystem. This is required
211 1.1 pk if you wish to use the network installation capabilities of this program.
212 1.1 pk
213 1.1 pk __network_config_1
214 1.1 pk echo -n "Enable network? [y] "
215 1.1 pk getresp "y"
216 1.1 pk case "$resp" in
217 1.1 pk y*|Y*)
218 1.1 pk if ! enable_network; then
219 1.1 pk echo "ERROR: can't enable network!"
220 1.1 pk exit 1
221 1.1 pk fi
222 1.1 pk
223 1.1 pk cat << \__network_config_2
224 1.1 pk
225 1.1 pk You will now be given the opportunity to escape to the command shell to
226 1.1 pk do any additional network configuration you may need. This may include
227 1.1 pk adding additional routes, if needed. In addition, you might take this
228 1.1 pk opportunity to redo the default route in the event that it failed above.
229 1.1 pk
230 1.1 pk __network_config_2
231 1.1 pk echo -n "Escape to shell? [n] "
232 1.1 pk getresp "n"
233 1.1 pk case "$resp" in
234 1.1 pk y*|Y*)
235 1.1 pk echo "Type 'exit' to return to upgrade."
236 1.1 pk sh
237 1.1 pk ;;
238 1.1 pk
239 1.1 pk *)
240 1.1 pk ;;
241 1.1 pk esac
242 1.1 pk ;;
243 1.1 pk *)
244 1.1 pk ;;
245 1.1 pk esac
246 1.1 pk
247 1.1 pk # Now that the network has been configured, it is safe to configure the
248 1.1 pk # fstab. We remove all but ufs/ffs/nfs.
249 1.1 pk (
250 1.4 pk > /tmp/fstab.new
251 1.4 pk while read _dev _mp _fstype _rest ; do
252 1.1 pk if [ "X${_fstype}" = X"ufs" -o \
253 1.1 pk "X${_fstype}" = X"ffs" -o \
254 1.1 pk "X${_fstype}" = X"nfs" ]; then
255 1.4 pk if [ "X${_fstype}" = X"ufs" ]; then
256 1.4 pk # Convert ufs to ffs.
257 1.4 pk _fstype=ffs
258 1.4 pk fi
259 1.4 pk echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab.new
260 1.1 pk fi
261 1.1 pk done
262 1.1 pk ) < /tmp/fstab
263 1.1 pk
264 1.1 pk if [ ! -f /tmp/fstab.new ]; then
265 1.1 pk echo "ERROR: strange fstab!"
266 1.1 pk exit 1
267 1.1 pk fi
268 1.1 pk
269 1.1 pk rm -f /tmp/fstab.new
270 1.1 pk
271 1.1 pk echo "The fstab is configured as follows:"
272 1.1 pk echo ""
273 1.1 pk cat /tmp/fstab
274 1.1 pk cat << \__fstab_config_1
275 1.1 pk
276 1.1 pk You may wish to edit the fstab. For example, you may need to resolve
277 1.1 pk dependencies in the order which the filesystems are mounted. Note that
278 1.1 pk this fstab is only for installation purposes, and will not be copied into
279 1.1 pk the root filesystem.
280 1.1 pk
281 1.1 pk __fstab_config_1
282 1.1 pk echo -n "Edit the fstab? [n] "
283 1.1 pk getresp "n"
284 1.1 pk case "$resp" in
285 1.1 pk y*|Y*)
286 1.3 leo ${EDITOR} /tmp/fstab
287 1.1 pk ;;
288 1.1 pk
289 1.1 pk *)
290 1.1 pk ;;
291 1.1 pk esac
292 1.1 pk
293 1.1 pk echo ""
294 1.1 pk munge_fstab /tmp/fstab /tmp/fstab.shadow
295 1.1 pk
296 1.1 pk if ! umount /mnt; then
297 1.1 pk echo "ERROR: can't unmount previously mounted root!"
298 1.1 pk exit 1
299 1.1 pk fi
300 1.1 pk
301 1.1 pk # Check all of the filesystems.
302 1.1 pk check_fs /tmp/fstab.shadow
303 1.1 pk
304 1.1 pk # Mount filesystems.
305 1.1 pk mount_fs /tmp/fstab.shadow
306 1.1 pk
307 1.3 leo
308 1.3 leo echo -n "Are the upgrade sets on one of your normally mounted filesystems? [y] "
309 1.3 leo getresp "y"
310 1.3 leo case "$resp" in
311 1.3 leo y*|Y*)
312 1.3 leo get_reldir
313 1.3 leo ;;
314 1.3 leo *)
315 1.3 leo ;;
316 1.3 leo esac
317 1.3 leo
318 1.1 pk # Install sets.
319 1.1 pk install_sets $UPGRSETS
320 1.1 pk
321 1.1 pk # Get timezone info
322 1.1 pk get_timezone
323 1.1 pk
324 1.1 pk # Fix up the fstab.
325 1.1 pk echo -n "Converting ufs to ffs in /etc/fstab..."
326 1.4 pk (
327 1.4 pk > /tmp/fstab
328 1.4 pk while read _dev _mp _fstype _rest ; do
329 1.4 pk if [ "X${_fstype}" = X"ufs" -o \
330 1.4 pk "X${_fstype}" = X"ffs" -o \
331 1.4 pk "X${_fstype}" = X"nfs" ]; then
332 1.4 pk if [ "X${_fstype}" = X"ufs" ]; then
333 1.4 pk # Convert ufs to ffs.
334 1.4 pk _fstype=ffs
335 1.4 pk fi
336 1.4 pk echo "$_dev $_mp $_fstype $_rest" >> /tmp/fstab
337 1.4 pk fi
338 1.4 pk done
339 1.4 pk ) < /mnt/etc/fstab
340 1.1 pk echo "done."
341 1.1 pk echo -n "Would you like to edit the resulting fstab? [y] "
342 1.1 pk getresp "y"
343 1.1 pk case "$resp" in
344 1.1 pk y*|Y*)
345 1.3 leo ${EDITOR} /tmp/fstab
346 1.1 pk ;;
347 1.1 pk
348 1.1 pk *)
349 1.1 pk ;;
350 1.1 pk esac
351 1.1 pk
352 1.1 pk # Copy in configuration information and make devices in target root.
353 1.1 pk (
354 1.1 pk cd /tmp
355 1.1 pk for file in fstab; do
356 1.1 pk if [ -f $file ]; then
357 1.1 pk echo -n "Copying $file..."
358 1.1 pk cp $file /mnt/etc/$file
359 1.1 pk echo "done."
360 1.1 pk fi
361 1.1 pk done
362 1.1 pk
363 1.1 pk echo -n "Installing timezone link..."
364 1.1 pk rm -f /mnt/etc/localtime
365 1.1 pk ln -s /usr/share/zoneinfo/$TZ /mnt/etc/localtime
366 1.1 pk echo "done."
367 1.1 pk
368 1.1 pk echo -n "Making devices..."
369 1.1 pk pid=`twiddle`
370 1.1 pk cd /mnt/dev
371 1.1 pk sh MAKEDEV all
372 1.1 pk kill $pid
373 1.1 pk echo "done."
374 1.1 pk
375 1.3 leo md_copy_kernel
376 1.1 pk
377 1.1 pk md_installboot ${ROOTDISK}
378 1.1 pk )
379 1.1 pk
380 1.1 pk unmount_fs /tmp/fstab.shadow
381 1.1 pk
382 1.1 pk # Pat on the back.
383 1.1 pk md_congrats
384 1.1 pk
385 1.1 pk # ALL DONE!
386 1.1 pk exit 0
387