-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-webobjects
executable file
·351 lines (268 loc) · 11.2 KB
/
update-webobjects
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/bin/sh
# Copyright (C) 2006-2012 Bart Martens <bartm@knars.be>
# Modified for WebObjects by Bastian Triller <bastian.triller@gmail.com>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -e
return_0() {
return 0
}
trap "return_0" 0
die_hard() {
echo "ERROR: $1" >&2
echo "More information might be available at:" >&2
echo " http://wiki.wocommunity.org" >&2
exit 1
}
[ `whoami` = "root" ] || die_hard "must be root"
show_usage() {
echo "Usage:"
echo " update-webobjects --install"
echo " update-webobjects --uninstall"
echo " update-webobjects --status"
echo "Additional options:"
echo " --verbose"
echo " --quiet"
exit 1
}
getopt_temp=`getopt -o iusfvq --long install,uninstall,status,fast,verbose,quiet -n 'update-webobjects' -- "$@"` || show_usage
eval set -- "$getopt_temp" || show_usage
ACTION=none
fast=no
verbose=no
quiet=no
wo_version=5.4.3
while [ true ]
do
case "$1" in
-i|--install)
ACTION="--install"
shift
;;
-u|--uninstall)
ACTION="--uninstall"
shift
;;
-s|--status)
ACTION="--status"
shift
;;
-f|--fast)
fast=yes
shift
;;
-v|--verbose)
verbose=yes
shift
;;
-q|--quiet)
quiet=yes
shift
;;
--)
shift
break
;;
*)
echo "Internal error!"
exit 1
;;
esac
done
[ "$ACTION" != "none" -a $# -eq 0 ] || show_usage
[ "$quiet" != "yes" ] || verbose=no
[ "$wo_version" = "5.4.3" ] || die_hard "version $wo_version not supported"
[ "$verbose" != "yes" ] || echo "options : $getopt_temp"
UNPACKDIR=`mktemp -d /tmp/webobjects.XXXXXXXXXX` || die_hard "mktemp failed"
echo "$UNPACKDIR" | grep -q "^/tmp/webobjects\." || die_hard "paranoia"
cd "$UNPACKDIR" || die_hard "cd failed"
mkdir mnt || die_hard "creating mnt directory failed"
[ "$verbose" != "yes" ] || echo "temporary directory: $UNPACKDIR"
do_cleanup() {
[ "$verbose" != "yes" ] || echo "cleaning up temporary directory $UNPACKDIR ..."
cd /
echo "$UNPACKDIR" | grep -q "^/tmp/webobjects\." || die_hard "paranoia"
mountpoint -q "$UNPACKDIR/mnt" && umount "$UNPACKDIR/mnt"
[ -n "$LOOP" ] && losetup -d "$LOOP"
rm -rf "$UNPACKDIR"
}
die_hard_with_a_cleanup() {
return_0
do_cleanup
die_hard "$1"
}
trap "die_hard_with_a_cleanup interrupted" INT
fix_missing_symlink() {
LANG=C update-alternatives --display $1 > /dev/null 2>&1 \
|| return 0
LANG=C update-alternatives --display $1 \
| grep -q "link currently absent" \
|| return 0
[ "$verbose" != "yes" ] || echo "$1 link currently absent, trying to fix"
update-alternatives --auto $1 > /dev/null 2>&1 || true
}
cachedir=/var/cache/webobjects
wgetquiet=' -q '
wgetfast='-t 3 -T 15 '
wgetalways=' -nd -P . '
wgetprogress=' -v '
get_installed_version() {
version_plist="/usr/share/webobjects/Library/Frameworks/JavaWebObjects.framework/Resources/Info.plist"
installed=
[ -f "$version_plist" ] && \
installed=`python -c "import plistlib;print plistlib.readPlist('$version_plist')['CFBundleShortVersionString']"` \
|| true
}
case "$ACTION" in
--install)
[ "$verbose" != "yes" ] || echo "selected action = $ACTION"
get_installed_version
[ "$verbose" != "yes" ] || echo "installed version = $installed"
if [ "$installed" != "" -a "$wo_version" != "" -a "$installed" = "$wo_version" ]
then
[ "$verbose" != "yes" ] || echo "WebObjects version $wo_version is already installed"
else
cp /usr/lib/webobjects/webobjects543.sha512.txt checksums.txt
downloadfile="WebObjects543.dmg"
downloaddir="http://supportdownload.apple.com/download.info.apple.com/Apple_Support_Area/Apple_Software_Updates/Mac_OS_X/downloads/061-4634.20080915.3ijd0"
. /etc/default/webobjects
[ -n "$WEBOBJECTS_URL" ] && downloaddir="$WEBOBJECTS_URL"
[ "$verbose" != "yes" ] || [ ! -f $cachedir/$downloadfile ] || echo "copying $cachedir/$downloadfile ..."
[ ! -f $cachedir/$downloadfile ] || cp -p $cachedir/$downloadfile .
ln -s mnt/Packages
modprobe -q loop || true
LOOP=`losetup -o 33280 --sizelimit 166126592 -f --show $downloadfile 2>/dev/null || true`
if [ -n "$LOOP" ] && mount -t hfsplus -o ro "$LOOP" mnt 2>/dev/null ; then
grep " Packages/" checksums.txt | sha512sum -c - > /dev/null 2>&1 \
|| { umount -d mnt ; rm -f $cachedir/$downloadfile $downloadfile ; LOOP="" ; }
else
LOOP=
rm -f $cachedir/$downloadfile $downloadfile
fi
downloadurl=$downloaddir/$downloadfile
wgetoptions="$wgetalways $wgetprogress"
[ "$quiet" != "yes" ] || wgetoptions="$wgetquiet $wgetalways"
[ "$fast" != "yes" ] || wgetoptions="$wgetoptions $wgetfast"
wgetoptions="$wgetoptions -O $UNPACKDIR/$downloadfile" # to change wget's message "Saving to: ..."
[ "$verbose" != "yes" ] || echo "wgetoptions=$wgetoptions"
[ "$verbose" != "yes" ] || [ -f $downloadfile ] || echo "downloading $downloadurl ..."
[ -f $downloadfile ] || \
HOME=/root \
wget $wgetoptions $downloadurl \
|| die_hard_with_a_cleanup "wget failed to download $downloadurl"
[ "$verbose" != "yes" ] || [ -n "$LOOP" ] || echo "mounting $downloadfile ..."
[ -n "$LOOP" ] || LOOP=`losetup -o 33280 --sizelimit 166126592 -f --show "$downloadfile" 2>/dev/null` \
|| die_hard_with_a_cleanup "could not setup loop device"
mountpoint -q mnt || mount -t hfsplus -o ro $LOOP mnt \
|| die_hard_with_a_cleanup "could not mount image"
[ "$verbose" != "yes" ] || echo "verifying checksum contents of Packages ..."
grep " Packages/" checksums.txt | sha512sum -c - > /dev/null 2>&1 \
|| die_hard_with_a_cleanup "sha512sum rejected a part of Packages"
[ "$verbose" != "yes" ] || [ ! -f "$cachedir/$downloadfile" ] \
|| echo "copying $downloadfile to $cachedir ..."
[ -f $cachedir/$downloadfile ] || cp -p $downloadfile $cachedir
[ "$verbose" != "yes" ] || echo "extracting runtime ..."
RUNTIME=`/usr/lib/webobjects/xarextract.py -x Packages/WebObjectsRuntime.pkg || die_hard_with_a_cleanup "couldn't extract runtime"`
mv -f $RUNTIME .
RUNTIME="$PWD/`basename $RUNTIME`"
copied_files=`mktemp /tmp/files.XXXXXXXXXX`
targetdir=/var/lib/webobjects
[ "$verbose" != "yes" ] || echo "moving webserver resources to $targetdir ..."
tar --owner=$WEBOBJECTS_USER --group=$WEBOBJECTS_GROUP -C $RUNTIME/System/Library/WebObjects/WODocumentRoot -c WebObjects \
| tar -C $targetdir/htdocs -xv | sed "s,^,${targetdir#/}/htdocs/," >> $copied_files
rm -rf $RUNTIME/System/Library/WebObjects/WODocumentRoot
tar --owner=$WEBOBJECTS_USER --group=$WEBOBJECTS_GROUP -C $RUNTIME/Library/WebServer/Documents -c WebObjects \
| tar -C $targetdir/htdocs -xv | sed "s,^,${targetdir#/}/htdocs/," >> $copied_files
mv $targetdir/htdocs/WebObjects/JavaMonitor.woa $targetdir/htdocs/WebObjects/JavaMonitor.woa.apple
[ "$verbose" != "yes" ] || echo "moving local libraries to $targetdir ..."
tar --owner=$WEBOBJECTS_USER --group=$WEBOBJECTS_GROUP -C $RUNTIME/ -c Library/Frameworks Library/WebObjects/Applications \
| tar -C $targetdir -xv | sed "s,^,${targetdir#/}/," >> $copied_files
targetdir=/usr/share/webobjects
[ "$verbose" != "yes" ] || echo "removing OSX adaptors ..."
rm -rf $RUNTIME/System/Library/WebObjects/Adaptors
[ "$verbose" != "yes" ] || echo "moving system libraries to $targetdir ..."
tar --owner=root --group=root -hC $RUNTIME/System -c Library \
| tar -C $targetdir -xv | sed "s,^,${targetdir#/}/," >> $copied_files
targetdir=/usr/share/doc/webobjects
[ "$verbose" != "yes" ] || echo "moving examples to $targetdir ..."
tar --owner=root --group=root -C $RUNTIME/Developer/Examples -c WebObjects JavaWebObjects \
| tar -C $targetdir/examples -xv | sed "s,^,${targetdir#/}/examples/," >> $copied_files
[ "$verbose" != "yes" ] || ( get_installed_version && echo "WebObjects version: $installed" )
fix_missing_symlink wotaskd || true
fix_missing_symlink javamonitor || true
[ "$verbose" != "yes" ] || \
update-alternatives --display wotaskd || true
[ "$verbose" != "yes" ] || \
update-alternatives --display javamonitor || true
[ "$verbose" != "yes" ] || echo "calling update-alternatives for wotaskd ..."
update-alternatives --quiet --install \
/usr/share/webobjects/bin/wotaskd wotaskd \
/usr/share/webobjects/Library/WebObjects/JavaApplications/wotaskd.woa/wotaskd 5 \
|| die_hard_with_a_cleanup "update-alternatives failed to install wotaskd"
[ "$verbose" != "yes" ] || echo "calling update-alternatives for JavaMonitor ..."
update-alternatives --quiet --install \
/usr/share/webobjects/bin/javamonitor javamonitor \
/usr/share/webobjects/Library/WebObjects/JavaApplications/JavaMonitor.woa/JavaMonitor 5 \
--slave /var/lib/webobjects/htdocs/WebObjects/JavaMonitor.woa JavaMonitor.woa \
/var/lib/webobjects/htdocs/WebObjects/JavaMonitor.woa.apple \
|| die_hard_with_a_cleanup "update-alternatives failed to install javamonitor"
[ "$verbose" != "yes" ] || \
update-alternatives --display wotaskd || true
[ "$verbose" != "yes" ] || \
update-alternatives --display javamonitor || true
( cd / ; grep -v "/$" $copied_files | sort -u | xargs md5sum > /var/lib/webobjects/extrafiles.md5sums )
grep "/$" $copied_files | sort -u > /var/lib/webobjects/extradirs.list
fi # end if installed != upstream
[ "$verbose" != "yes" ] || echo "end of action $ACTION"
;;
--uninstall)
[ "$verbose" != "yes" ] || echo "selected action = $ACTION"
update-alternatives --remove wotaskd /usr/share/webobjects/Library/WebObjects/JavaApplications/wotaskd.woa/wotaskd
update-alternatives --remove javamonitor /usr/share/webobjects/Library/WebObjects/JavaApplications/JavaMonitor.woa/JavaMonitor
[ "$verbose" != "yes" ] || echo "removing files ..."
[ -e /var/lib/webobjects/extrafiles.md5sums ] || touch /var/lib/webobjects/extrafiles.md5sums
(
IFS=":"
cd /
LANG=C md5sum -c < /var/lib/webobjects/extrafiles.md5sums \
| while read file status ; do
targetfile="/$file"
if [ ! -e $targetfile ] ; then
echo "not found: $targetfile"
elif [ "$status" = " OK" ] ; then
[ "$verbose" != "yes" ] || echo "removing $targetfile"
rm -f $targetfile
else
echo "not removing modified $targetfile"
fi
done
)
rm -f /var/lib/webobjects/extrafiles.md5sums
( cd / ; tac /var/lib/webobjects/extradirs.list | xargs -r rmdir --ignore-fail-on-non-empty )
rm -f /var/lib/webobjects/extradirs.list
[ "$verbose" != "yes" ] || echo "end of action $ACTION"
;;
--status)
[ "$verbose" != "yes" ] || echo "selected action = $ACTION"
get_installed_version
echo "WebObjects version installed on this system : $installed"
#LANG=C update-alternatives --display flash-mozilla.so || true
[ "$verbose" != "yes" ] || echo "end of action $ACTION"
;;
*)
do_cleanup
show_usage
;;
esac
do_cleanup
[ "$verbose" != "yes" ] || echo "end of update-webobjects"