1 | #!/bin/sh |
---|
2 | # $Id: update_ws.sh,v 1.40 1999-08-10 20:22:52 ghudson Exp $ |
---|
3 | |
---|
4 | # Copyright 1996 by the Massachusetts Institute of Technology. |
---|
5 | # |
---|
6 | # Permission to use, copy, modify, and distribute this |
---|
7 | # software and its documentation for any purpose and without |
---|
8 | # fee is hereby granted, provided that the above copyright |
---|
9 | # notice appear in all copies and that both that copyright |
---|
10 | # notice and this permission notice appear in supporting |
---|
11 | # documentation, and that the name of M.I.T. not be used in |
---|
12 | # advertising or publicity pertaining to distribution of the |
---|
13 | # software without specific, written prior permission. |
---|
14 | # M.I.T. makes no representations about the suitability of |
---|
15 | # this software for any purpose. It is provided "as is" |
---|
16 | # without express or implied warranty. |
---|
17 | |
---|
18 | # update_ws (also known as auto_update) |
---|
19 | # |
---|
20 | # Check that an update is needed, and make sure the conditions necessary |
---|
21 | # for a successful update are met. Then prepare the machine for update, |
---|
22 | # and run do-update. |
---|
23 | |
---|
24 | # "tee" doesn't work reliably across OS versions (since it's not local on |
---|
25 | # Solaris), so emulate it in the shell. |
---|
26 | shelltee() { |
---|
27 | exec 3>$1 |
---|
28 | while IFS="" read line; do |
---|
29 | echo "$line" |
---|
30 | echo "$line" 1>&3 |
---|
31 | done |
---|
32 | } |
---|
33 | |
---|
34 | trap "" 1 15 |
---|
35 | |
---|
36 | export CONFDIR LIBDIR PATH HOSTTYPE |
---|
37 | CONFDIR=/etc/athena |
---|
38 | LIBDIR=/srvd/usr/athena/lib/update |
---|
39 | PATH=/bin:/etc:/usr/bin:/usr/ucb:/usr/bsd:/os/bin:/os/etc:/etc/athena:/bin/athena:/os/usr/bin:/usr/athena/sbin:/os/usr/ucb:/os/usr/bsd:$LIBDIR |
---|
40 | HOSTTYPE=`/bin/athena/machtype` |
---|
41 | |
---|
42 | case "$0" in |
---|
43 | *auto_update) |
---|
44 | method=Auto |
---|
45 | ;; |
---|
46 | *) |
---|
47 | method=Manual |
---|
48 | ;; |
---|
49 | esac |
---|
50 | |
---|
51 | # The -r option specifies that the update is remote and that we shouldn't |
---|
52 | # give the user a shell after the reboot. |
---|
53 | while getopts r opt; do |
---|
54 | case "$opt" in |
---|
55 | r) |
---|
56 | method=Remote |
---|
57 | ;; |
---|
58 | \?) |
---|
59 | echo "$0 [-r] [reactivate|rc]" 1>&2 |
---|
60 | exit 1 |
---|
61 | ;; |
---|
62 | esac |
---|
63 | done |
---|
64 | shift `expr $OPTIND - 1` |
---|
65 | why="$1" |
---|
66 | |
---|
67 | case `id` in |
---|
68 | "uid=0("*) |
---|
69 | ;; |
---|
70 | *) |
---|
71 | echo "You are not root. This update script must be run as root." |
---|
72 | exit 1 |
---|
73 | ;; |
---|
74 | esac |
---|
75 | |
---|
76 | # If /srvd is not mounted, quit. |
---|
77 | if [ ! -d /srvd/bin ]; then |
---|
78 | exit 1 |
---|
79 | fi |
---|
80 | |
---|
81 | if [ ! -f "$CONFDIR/version" ]; then |
---|
82 | echo "Athena Update (???) Version 0.0A Mon Jan 1 00:00:00 EDT 0000" \ |
---|
83 | > "$CONFDIR/version" |
---|
84 | fi |
---|
85 | |
---|
86 | newvers=`awk '{a=$5}; END{print a}' /srvd/.rvdinfo` |
---|
87 | version=`awk '{a=$5}; END{print a}' "$CONFDIR/version"` |
---|
88 | |
---|
89 | # A temporary backward compatibility hack, necessary as long as there are |
---|
90 | # 7.7 and 8.0 machines upgrading to the new release. |
---|
91 | case "$version" in |
---|
92 | [0-9].[0-9][A-Z]) |
---|
93 | version=`echo $version | awk '{ print substr($1, 1, 3) "." \ |
---|
94 | index("ABCDEFGHIJKLMNOPQRSTUVWXYZ", substr($1, 4, 1)) - 1; }'` |
---|
95 | ;; |
---|
96 | esac |
---|
97 | |
---|
98 | if [ -f "$CONFDIR/rc.conf" ]; then |
---|
99 | . "$CONFDIR/rc.conf" |
---|
100 | else |
---|
101 | export PUBLIC AUTOUPDATE HOST |
---|
102 | PUBLIC=true |
---|
103 | AUTOUPDATE=true |
---|
104 | HOST=`hostname` |
---|
105 | fi |
---|
106 | |
---|
107 | # Make sure /var/athena exists (it was introduced in 8.1.0) so we have a |
---|
108 | # place to put the temporary clusterinfo file and the desync state file |
---|
109 | # and the update log. |
---|
110 | if [ ! -d /var/athena ]; then |
---|
111 | mkdir -m 755 /var/athena |
---|
112 | fi |
---|
113 | |
---|
114 | # Get and read cluster information, to set one or both of |
---|
115 | # NEW_TESTING_RELEASE and NEW_PRODUCTION_RELEASE if there are new |
---|
116 | # releases available. |
---|
117 | /etc/athena/save_cluster_info |
---|
118 | if [ -f /var/athena/clusterinfo.bsh ]; then |
---|
119 | . /var/athena/clusterinfo.bsh |
---|
120 | fi |
---|
121 | |
---|
122 | # Check if we're already in the middle of an update. |
---|
123 | case "$version" in |
---|
124 | [0-9]*) |
---|
125 | # If this field starts with a digit, we're running a proper |
---|
126 | # release. Otherwise... |
---|
127 | ;; |
---|
128 | *) |
---|
129 | if [ ! -f /var/tmp/update.check ]; then |
---|
130 | logger -t $HOST -p user.notice at revision $version |
---|
131 | touch /var/tmp/update.check |
---|
132 | fi |
---|
133 | |
---|
134 | echo "This system is in the middle of an update. Please contact" |
---|
135 | echo "Athena Cluster Services at x3-1410. Thank you. -Athena Operations" |
---|
136 | exit 1 |
---|
137 | ;; |
---|
138 | esac |
---|
139 | |
---|
140 | # Find out if the version in /srvd/.rvdinfo is newer than |
---|
141 | # /etc/athena/version. Distinguish between major, minor, and patch |
---|
142 | # releases so that we can desynchronize patch releases. |
---|
143 | packsnewer=`echo "$newvers $version" | awk '{ |
---|
144 | split($1, v1, "."); |
---|
145 | split($2, v2, "."); |
---|
146 | if (v1[1] + 0 > v2[1] + 0) |
---|
147 | print "major"; |
---|
148 | else if (v1[1] + 0 == v2[1] + 0 && v1[2] + 0 > v2[2] + 0) |
---|
149 | print "minor"; |
---|
150 | else if (v1[1] == v2[1] && v1[2] == v2[2] && v1[3] + 0 > v2[3] + 0) |
---|
151 | print "patch"; }'` |
---|
152 | |
---|
153 | # If the packs aren't any newer, print an appropriate message and exit. |
---|
154 | if [ -z "$packsnewer" ]; then |
---|
155 | if [ "$method" != Auto ]; then |
---|
156 | # User ran update_ws; display something appropriate. |
---|
157 | if [ -n "$NEW_PRODUCTION_RELEASE" -o \ |
---|
158 | -n "$NEW_TESTING_RELEASE" ]; then |
---|
159 | echo "Your workstation software already matches the" |
---|
160 | echo "version on the system packs. You must manually" |
---|
161 | echo "attach a newer version of the system packs to" |
---|
162 | echo "update beyond this point." |
---|
163 | else |
---|
164 | echo "It appears you already have this update." |
---|
165 | fi |
---|
166 | else |
---|
167 | # System ran auto_update; point out new releases if available. |
---|
168 | if [ -n "$NEW_PRODUCTION_RELEASE" ]; then |
---|
169 | /bin/cat <<EOF |
---|
170 | |
---|
171 | A new Athena release ($NEW_PRODUCTION_RELEASE) is available. Since it may be |
---|
172 | incompatible with your workstation software, your workstation |
---|
173 | is still using the old system packs. Please contact Athena |
---|
174 | Cluster Services (x3-1410) to have your workstation updated. |
---|
175 | EOF |
---|
176 | fi |
---|
177 | if [ -n "$NEW_TESTING_RELEASE" ]; then |
---|
178 | /bin/cat << EOF |
---|
179 | |
---|
180 | A new Athena release ($NEW_TESTING_RELEASE) is now in testing. You are |
---|
181 | theoretically interested in this phase of testing, but |
---|
182 | because there may be bugs which would inconvenience |
---|
183 | your work, you must update to this release manually. |
---|
184 | Please contact Athena Cluster Services (x3-1410) if |
---|
185 | you have not received instructions on how to do so. |
---|
186 | EOF |
---|
187 | fi |
---|
188 | fi |
---|
189 | exit 0 |
---|
190 | fi |
---|
191 | |
---|
192 | # The packs are newer, but if we were run as auto_update, we don't want to do |
---|
193 | # an update unless the machine is autoupdate (or public). |
---|
194 | if [ "$method" = Auto -a "$AUTOUPDATE" != true -a "$PUBLIC" != true ]; then |
---|
195 | cat <<EOF |
---|
196 | |
---|
197 | A new version of Athena software is now available. |
---|
198 | Please contact Athena Cluster Services (x3-1410) to |
---|
199 | get more information on how to update your workstation |
---|
200 | yourself, or to schedule us to do it for you. |
---|
201 | Thank you. -Athena Operations |
---|
202 | EOF |
---|
203 | if [ ! -f /var/tmp/update.check ]; then |
---|
204 | logger -t $HOST -p user.notice at revision $version |
---|
205 | cp /dev/null /var/tmp/update.check |
---|
206 | fi |
---|
207 | |
---|
208 | exit 1 |
---|
209 | fi |
---|
210 | |
---|
211 | if [ "$method" = Auto -a "$packsnewer" = patch ]; then |
---|
212 | # There is a patch release available and we want to take the |
---|
213 | # update, but not necessarily right now. Use desync to |
---|
214 | # stagger the update over a four-hour period. (Use the |
---|
215 | # version from /srvd for now to make sure the -t option works, |
---|
216 | # since that option was not introduced until 8.1.) Note |
---|
217 | # that we only do desynchronization here for patch releases. |
---|
218 | # Desynchronization for major or minor releases is handled in |
---|
219 | # getcluster, since we don't want the workstation to run with |
---|
220 | # a new, possibly incompatible version of the packs. |
---|
221 | |
---|
222 | /srvd/etc/athena/desync -t /var/athena/update.desync 14400 |
---|
223 | if [ $? -ne 0 ]; then |
---|
224 | exit 0 |
---|
225 | fi |
---|
226 | fi |
---|
227 | |
---|
228 | # The 8.1 -> 8.2 update consumes about 1.7MB on the /usr partition and |
---|
229 | # about 3.9MB on the root partition. Since the smallest-sized Solaris |
---|
230 | # partitions only have 5.7MB free on /usr and 8.1MB free on the root |
---|
231 | # filesystem under 8.1, it's important to make sure that neither |
---|
232 | # filesystem fills up. Some day the version scripts should take care |
---|
233 | # of setting the numbers for this check, but that requires adding |
---|
234 | # multiple phases to the version scripts. |
---|
235 | case "$HOSTTYPE,$version" in |
---|
236 | sun4,8.[01].*|sun4,7.*) |
---|
237 | if [ "`df -k /usr | awk '/\/usr$/ { print $4; }'`" -lt 3072 ]; then |
---|
238 | echo "/usr partition low on space (less than 3MB); not" |
---|
239 | echo "performing update. Please reinstall or clean local" |
---|
240 | echo "files off /usr partition." |
---|
241 | exit 1 |
---|
242 | fi |
---|
243 | if [ "`df -k / | awk '/\/$/ { print $4; }'`" -lt 5120 ]; then |
---|
244 | echo "Root partition low on space (less than 5MB); not" |
---|
245 | echo "performing update. Please reinstall or clean local" |
---|
246 | echo "files off root partition." |
---|
247 | exit 1 |
---|
248 | fi |
---|
249 | ;; |
---|
250 | esac |
---|
251 | |
---|
252 | # The Indy 6.2 -> 6.5 update consumes an additional 100MB of the |
---|
253 | # root partition; the O2 6.3 -> 6.5 update adds 40MB to root. |
---|
254 | # We also require a minimum of 64MB of memory on all SGI's. |
---|
255 | case "$HOSTTYPE" in |
---|
256 | sgi) |
---|
257 | case "`uname -r`" in |
---|
258 | 6.2) |
---|
259 | rootneeded=100 |
---|
260 | ;; |
---|
261 | 6.3) |
---|
262 | rootneeded=40 |
---|
263 | ;; |
---|
264 | *) |
---|
265 | rootneeded=0 |
---|
266 | ;; |
---|
267 | esac |
---|
268 | |
---|
269 | rootfree=`df -k / | awk '$NF == "/" { print int($5 / 1024); }'` |
---|
270 | if [ "$rootfree" -lt "$rootneeded" ]; then |
---|
271 | echo "Root partition low on space (less than ${rootneeded}MB);" |
---|
272 | echo "not performing update. Please reinstall or" |
---|
273 | echo "clean local files off root partition." |
---|
274 | exit 1 |
---|
275 | fi |
---|
276 | |
---|
277 | if [ "`hinv -t memory | awk '{ print $4; }'`" -lt 64 ]; then |
---|
278 | echo "Insufficient memory (less than 64MB); not" |
---|
279 | echo "performing update. Please add more memory" |
---|
280 | echo "or reinstall." |
---|
281 | exit 1 |
---|
282 | fi |
---|
283 | ;; |
---|
284 | esac |
---|
285 | |
---|
286 | # If this is a private workstation, make sure we can recreate the mkserv |
---|
287 | # state of the machine after the update. |
---|
288 | if [ -d /var/server ] ; then |
---|
289 | /srvd/usr/athena/bin/mkserv updatetest |
---|
290 | if [ $? -ne 0 ]; then |
---|
291 | echo "mkserv services cannot be found for all services." |
---|
292 | echo "Update cannot be performed." |
---|
293 | exit 1 |
---|
294 | fi |
---|
295 | fi |
---|
296 | |
---|
297 | # Tell dm to shut down everything and sleep forever during the update. |
---|
298 | if [ "$method" = Auto -a "$why" = reactivate ]; then |
---|
299 | if [ -f /var/athena/dm.pid ]; then |
---|
300 | kill -FPE `cat /var/athena/dm.pid` |
---|
301 | fi |
---|
302 | # 8.0 and prior machines still have /etc/athena/dm.pid. |
---|
303 | if [ -f /etc/athena/dm.pid ]; then |
---|
304 | kill -FPE `cat /etc/athena/dm.pid` |
---|
305 | fi |
---|
306 | |
---|
307 | if [ -f /etc/init.d/axdm ]; then |
---|
308 | /etc/init.d/axdm stop |
---|
309 | fi |
---|
310 | |
---|
311 | sleep 2 |
---|
312 | if [ "$HOSTTYPE" = sgi ]; then |
---|
313 | exec 1>/dev/tport 2>&1 |
---|
314 | fi |
---|
315 | fi |
---|
316 | |
---|
317 | # Everything is all set; do the actual update. |
---|
318 | rm -f /var/athena/update.log |
---|
319 | if [ "$method" = Auto ]; then |
---|
320 | echo |
---|
321 | echo THIS WORKSTATION IS ABOUT TO UNDERGO AN AUTOMATIC SOFTWARE UPDATE. |
---|
322 | echo THIS PROCEDURE MAY TAKE SOME TIME. |
---|
323 | echo |
---|
324 | echo PLEASE DO NOT DISTURB IT WHILE THIS IS IN PROGRESS. |
---|
325 | echo |
---|
326 | exec sh "$LIBDIR/do-update" "$method" "$version" "$newvers" \ |
---|
327 | < /dev/null 2>&1 | shelltee /var/athena/update.log |
---|
328 | else |
---|
329 | exec sh "$LIBDIR/do-update" "$method" "$version" "$newvers" \ |
---|
330 | 2>&1 | shelltee /var/athena/update.log |
---|
331 | fi |
---|