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