~evergreen-bugs/evergreen/rel_3_11

« back to all changes in this revision

Viewing changes to Open-ILS/xul/staff_client/external/make_updates.sh

  • Committer: phasefx
  • Date: 2010-08-24 19:04:20 UTC
  • Revision ID: git-v1:53a0bd89fe11176c309b6bcf7f812e3bb60b1283
Staff Client Build/Update Enhancements patch from Thomas Berezansky

Among other things, allows cross-compilation of Windows installers from Unix environments via NSIS, and enables Mozilla's upgrade mechanism for performing upgrades without needing to download and execute external files.

See https://bugs.launchpad.net/evergreen/+bug/616452/ for more details.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@17330 dcc99617-32d9-48b4-a31d-7c20da2025e4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
# ***** BEGIN LICENSE BLOCK *****
 
4
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
5
#
 
6
# The contents of this file are subject to the Mozilla Public License Version
 
7
# 1.1 (the "License"); you may not use this file except in compliance with
 
8
# the License. You may obtain a copy of the License at
 
9
# http://www.mozilla.org/MPL/
 
10
#
 
11
# Software distributed under the License is distributed on an "AS IS" basis,
 
12
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
13
# for the specific language governing rights and limitations under the
 
14
# License.
 
15
#
 
16
# The Original Code is Mozilla Update Packaging.
 
17
#
 
18
# The Initial Developer of the Original Code is
 
19
# Merrimack Valley Library Consortium.
 
20
# Portions created by the Initial Developer are Copyright (C) 2010
 
21
# the Initial Developer. All Rights Reserved.
 
22
#
 
23
# Contributor(s):
 
24
#  Thomas Berezansky <tsbere@mvlc.org>
 
25
#
 
26
# Alternatively, the contents of this file may be used under the terms of
 
27
# either the GNU General Public License Version 2 or later (the "GPL"), or
 
28
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
29
# in which case the provisions of the GPL or the LGPL are applicable instead
 
30
# of those above. If you wish to allow use of your version of this file only
 
31
# under the terms of either the GPL or the LGPL, and not to allow others to
 
32
# use your version of this file under the terms of the MPL, indicate your
 
33
# decision by deleting the provisions above and replace them with the notice
 
34
# and other provisions required by the GPL or the LGPL. If you do not delete
 
35
# the provisions above, a recipient may use your version of this file under
 
36
# the terms of any one of the MPL, the GPL or the LGPL.
 
37
#
 
38
# ***** END LICENSE BLOCK *****
 
39
 
 
40
# Portions of this code were based on code by Darin Fisher found here:
 
41
# http://mxr.mozilla.org/mozilla/source/tools/update-packaging/
 
42
 
 
43
prefix=${1:-/openils/var/updates}
 
44
BZIP2=${BZIP2:-bzip2}
 
45
 
 
46
GEN_UPDATES=0
 
47
WIN_UPDATES=0
 
48
LINUX_UPDATES=0
 
49
EXT_UPDATES=0
 
50
CLIENTS=0
 
51
case "$2" in
 
52
        generic-updates*)
 
53
        echo "Building Generic Updates only"
 
54
        GEN_UPDATES=1
 
55
        ;;
 
56
        win-updates*)
 
57
        echo "Building Windows Updates only"
 
58
        WIN_UPDATES=1
 
59
        ;;
 
60
        linux-updates*)
 
61
        echo "Building Linux Updates only"
 
62
        LINUX_UPDATES=1
 
63
        ;;
 
64
        extension-updates*)
 
65
        echo "Building Extension Updates only"
 
66
        EXT_UPDATES=1
 
67
        ;;
 
68
        *)
 
69
        echo "Building All Updates"
 
70
        GEN_UPDATES=1
 
71
        WIN_UPDATES=1
 
72
        LINUX_UPDATES=1
 
73
        EXT_UPDATES=1
 
74
        ;;
 
75
esac
 
76
case "$2" in
 
77
        extension-updates*)
 
78
        echo "Extension only - No client"
 
79
        ;;
 
80
        *-client)
 
81
        echo "Building Client(s)"
 
82
        CLIENTS=1
 
83
        ;;
 
84
        *)
 
85
        echo "Not Building Client(s)"
 
86
        ;;
 
87
esac
 
88
 
 
89
function unwrap_update
 
90
{
 
91
        SOURCE="$1"
 
92
        DEST="$2"
 
93
        $MAR -C "$2" -x "$1"
 
94
        find "$2" -type f -exec mv {} {}.bz2 \;
 
95
        find "$2" -type f -name '*.bz2' -exec $BZIP2 -d {} \;
 
96
}
 
97
 
 
98
function prep_update
 
99
{
 
100
        NEW="$1"
 
101
        OLD="$2"
 
102
        WORK="$3"
 
103
        MANIFEST="$WORK/update.manifest"
 
104
        ARCHIVEFILES="update.manifest"
 
105
        rm -rf "$WORK"
 
106
        mkdir -p "$WORK"
 
107
        rm -f "$MANIFEST"
 
108
        for FILE in `find "$NEW" -type f`; do
 
109
                check_file $FILE
 
110
        done
 
111
        for FILE in `find "$OLD" -type f`; do
 
112
                remove_file $FILE
 
113
        done
 
114
        $BZIP2 -z9 "$MANIFEST"
 
115
        mv "$MANIFEST.bz2" "$MANIFEST"
 
116
        rm -rf "$OLD"
 
117
}
 
118
 
 
119
function check_file
 
120
{
 
121
        CHECK_FILE="${1#$NEW/}"
 
122
        if [ $CHECK_FILE == "update.manifest" ]; then
 
123
                return;
 
124
        fi
 
125
        DIR=$(dirname "$WORK/$CHECK_FILE")
 
126
        if [ ! -f "$OLD/$CHECK_FILE" ]; then
 
127
                echo "add \"$CHECK_FILE\"" >> "$MANIFEST"
 
128
                mkdir -p "$DIR"
 
129
                $BZIP2 -cz9 "$NEW/$CHECK_FILE" > "$WORK/$CHECK_FILE"
 
130
                if [ -x "$NEW/$CHECK_FILE" ]; then
 
131
                        chmod 0755 "$WORK/$CHECK_FILE"
 
132
                else
 
133
                        chmod 0644 "$WORK/$CHECK_FILE"
 
134
                fi
 
135
                ARCHIVEFILES="$ARCHIVEFILES \"$CHECK_FILE\""
 
136
                return
 
137
        elif ! diff "$OLD/$CHECK_FILE" "$NEW/$CHECK_FILE" > /dev/null; then
 
138
                mkdir -p "$DIR"
 
139
                $MBSDIFF "$OLD/$CHECK_FILE" "$NEW/$CHECK_FILE" "$WORK/$CHECK_FILE.patch"
 
140
                $BZIP2 -z9 "$WORK/$CHECK_FILE.patch"
 
141
                $BZIP2 -cz9 "$NEW/$CHECK_FILE" > "$WORK/$CHECK_FILE"
 
142
                PATCHSIZE=`du -b "$WORK/$CHECK_FILE.patch.bz2"`
 
143
                FULLSIZE=`du -b "$WORK/$CHECK_FILE"`
 
144
                PATCHSIZE="${PATCHSIZE%%        *}"
 
145
                FULLSIZE="${FULLSIZE%%  *}"
 
146
                if [ $PATCHSIZE -lt $FULLSIZE ]; then
 
147
                        rm -f "$WORK/$CHECK_FILE"
 
148
                        mv "$WORK/$CHECK_FILE.patch.bz2" "$WORK/$CHECK_FILE.patch"
 
149
                        echo "patch \"$CHECK_FILE.patch\" \"$CHECK_FILE\"" >> "$MANIFEST"
 
150
                        ARCHIVEFILES="$ARCHIVEFILES \"$CHECK_FILE.patch\""
 
151
                else
 
152
                        rm -f "$WORK/$CHECK_FILE.patch.bz2"
 
153
                        if [ -x "$NEW/$CHECK_FILE" ]; then
 
154
                                chmod 0755 "$WORK/$CHECK_FILE"
 
155
                        else
 
156
                                chmod 0644 "$WORK/$CHECK_FILE"
 
157
                        fi
 
158
                        echo "add \"$CHECK_FILE\"" >> "$MANIFEST"
 
159
                        ARCHIVEFILES="$ARCHIVEFILES \"$CHECK_FILE\""
 
160
                fi
 
161
        fi
 
162
        rm -f "$OLD/$CHECK_FILE"
 
163
}
 
164
 
 
165
function remove_file
 
166
{
 
167
        RM_FILE="${1#$OLD/}"
 
168
        if [ $RM_FILE != "update.manifest" ]; then
 
169
                echo "remove \"$RM_FILE\"" >> "$MANIFEST"
 
170
        fi
 
171
}
 
172
 
 
173
function build_update
 
174
{
 
175
        eval "$MAR -C \"$WORK\" -c output.mar $ARCHIVEFILES"
 
176
        mv "$WORK/output.mar" "$1"
 
177
        rm -rf "$WORK"
 
178
}
 
179
 
 
180
function check_mar
 
181
{
 
182
        if which mar; then
 
183
                MAR=${MAR:-mar}
 
184
        fi
 
185
        if which mbsdiff; then
 
186
                MBSDIFF=${MBSDIFF:-mbsdiff}
 
187
        fi
 
188
        if [ ! -x "$MAR" -o ! -x "$MBSDIFF" ]; then
 
189
                if [ ! -f "external/mar" -o ! -f "external/mbsdiff" ]; then
 
190
                        wget ftp://ftp.mozilla.org/pub/mozilla.org/xulrunner/mar-generation-tools/mar-generation-tools-linux.zip
 
191
                        unzip mar-generation-tools-linux.zip -d external
 
192
                fi
 
193
                MAR="$PWD/external/mar"
 
194
                MBSDIFF="$PWD/external/mbsdiff"
 
195
        fi
 
196
}
 
197
 
 
198
function make_full_update
 
199
{
 
200
        echo "Making full update"
 
201
        rm -rf "oldclient"
 
202
        mkdir -p "oldclient"
 
203
        prep_update client oldclient client.working
 
204
        build_update "full_update.mar"
 
205
        mkdir -p "$PUBPATH"
 
206
        mv full_update.mar "$PUBPATH/$VERSION.mar"
 
207
        echo "Making full update patch def"
 
208
        mkdir -p "$PATCHPATH"
 
209
        HASH=$(sha512sum "$PUBPATH/$VERSION.mar")
 
210
        SIZE=$(du -b "$PUBPATH/$VERSION.mar")
 
211
        echo "<patch type=\"complete\" URL=\"$VERSION.mar\" hashFunction=\"sha512\" hashValue=\"${HASH%% *}\" size=\"${SIZE%%   *}\"/>" > "$PATCHPATH/$VERSION.patchline"
 
212
}
 
213
 
 
214
function make_partial_update
 
215
{
 
216
        PREV_VERSION="${1%.mar}"
 
217
        if [ "$VERSION" == "$PREV_VERSION" ]; then
 
218
                echo "Skipping partial update for same version"
 
219
                return
 
220
        fi
 
221
        echo "Making partial update from $PREV_VERSION"
 
222
        rm -rf "oldclient"
 
223
        mkdir -p "oldclient"
 
224
        unwrap_update "$ARCHIVEPATH/$1" oldclient
 
225
        prep_update client oldclient client.working
 
226
        build_update "partial_update.mar"
 
227
        mv partial_update.mar "$PUBPATH/$PREV_VERSION-$VERSION.mar"
 
228
        echo "Making partial update patch def"
 
229
        mkdir -p "$PATCHPATH"
 
230
        HASH=$(sha512sum "$PUBPATH/$PREV_VERSION-$VERSION.mar")
 
231
        SIZE=$(du -b "$PUBPATH/$PREV_VERSION-$VERSION.mar")
 
232
        echo "<patch type=\"partial\" URL=\"$PREV_VERSION-$VERSION.mar\" hashFunction=\"sha512\" hashValue=\"${HASH%% *}\" size=\"${SIZE%%      *}\"/>" > "$PATCHPATH/$PREV_VERSION-$VERSION.patchline"
 
233
}
 
234
 
 
235
function make_partial_updates
 
236
{
 
237
        echo "Checking for partial update source files"
 
238
        if [ -d "$ARCHIVEPATH" ]; then
 
239
                for OLDVER in `find "$ARCHIVEPATH" -maxdepth 1 -name '*.mar'`; do
 
240
                        make_partial_update "${OLDVER##*/}"
 
241
                done
 
242
        fi
 
243
        mkdir -p "$ARCHIVEPATH"
 
244
        echo "Copying full update to archive"
 
245
        cp "$PUBPATH/$VERSION.mar" "$ARCHIVEPATH"
 
246
        echo "Updating current version file"
 
247
        echo "$VERSION" > "$PATCHPATH/VERSION"
 
248
}
 
249
 
 
250
function cleanup_files
 
251
{
 
252
        echo "Cleaning up previous update mar files and update patch files"
 
253
        find "$PUBPATH" -maxdepth 1 -name "*.mar" ! -name "*$VERSION.mar" -delete -print
 
254
        find "$PATCHPATH" -maxdepth 1 -name "*.patch" ! -name "*$VERSION.patch" -delete -print
 
255
}
 
256
 
 
257
# First, do we have the mar and mbsdiff tools?
 
258
check_mar
 
259
VERSION=`cat build/VERSION`
 
260
 
 
261
# Generic Updates - No XULRunner packaged, channel of "release"
 
262
# NOTE: Generic updates CAN update Windows/Linux builds, and will do so if you don't build platform specific ones
 
263
if [ $GEN_UPDATES -eq 1 ]; then
 
264
        PATCHPATH="$prefix/patch"
 
265
        PUBPATH="$prefix/pub"
 
266
        ARCHIVEPATH="$prefix/archives"
 
267
        if [ $CLIENTS -eq 1 ]; then
 
268
                make generic-client
 
269
                mkdir -p "$prefix/pub/clients/"
 
270
                find "$prefix/pub/clients/" -name '*_client.xpi' -delete
 
271
                mv evergreen_staff_client.xpi "$prefix/pub/clients/${VERSION}_client.xpi"
 
272
        else
 
273
                make client_app
 
274
        fi
 
275
        make_full_update
 
276
        make_partial_updates
 
277
        cleanup_files
 
278
fi
 
279
 
 
280
# Windows Updates - Windows XULRunner, update channel of "win"
 
281
if [ $WIN_UPDATES -eq 1 ]; then
 
282
        PATCHPATH="$prefix/patch/win"
 
283
        PUBPATH="$prefix/pub/win"
 
284
        ARCHIVEPATH="$prefix/archives/win"
 
285
        if [ $CLIENTS -eq 1 ]; then
 
286
                make win-client
 
287
                mkdir -p "$prefix/pub/clients/"
 
288
                find "$prefix/pub/clients/" -name '*_setup.exe' -delete
 
289
                mv evergreen_staff_client_setup.exe "$prefix/pub/clients/${VERSION}_setup.exe"
 
290
        else
 
291
                make win-xulrunner
 
292
        fi
 
293
        make_full_update
 
294
        make_partial_updates
 
295
        cleanup_files
 
296
fi
 
297
 
 
298
# Linux Updates - Linux XULRunner, update channel of "lin'
 
299
if [ $LINUX_UPDATES -eq 1 ]; then
 
300
        PATCHPATH="$prefix/patch/lin"
 
301
        PUBPATH="$prefix/pub/lin"
 
302
        ARCHIVEPATH="$prefix/archives/lin"
 
303
        if [ $CLIENTS -eq 1 ]; then
 
304
                make linux-client
 
305
                mkdir -p "$prefix/pub/clients/"
 
306
                find "$prefix/pub/clients/" -name '*.tar.bz2' -delete
 
307
                mv evergreen_staff_client.tar.bz2 "$prefix/pub/clients/${VERSION}.tar.bz2"
 
308
        else
 
309
                make linux-xulrunner
 
310
        fi
 
311
        make_full_update
 
312
        make_partial_updates
 
313
        cleanup_files
 
314
fi
 
315
 
 
316
# Extension Updates
 
317
# Not really "Updates" so much as "Update", plural for consistency in command.
 
318
# Extensions don't do partial updates. Or at least not that I found docs for.
 
319
if [ $EXT_UPDATES -eq 1 ]; then
 
320
        make extension
 
321
        mkdir -p "$prefix/pub/"
 
322
        find "$prefix/pub/" -maxdepth 1 -name '*_extension.xpi' -delete
 
323
        mv evergreen.xpi "$prefix/pub/${VERSION}_extension.xpi" 
 
324
        SHA512=$(sha512sum "$prefix/pub/${VERSION}_extension.xpi")
 
325
        SHA512=${SHA512%% *}
 
326
        sed -e "s|<em:version>.*</em:version>|<em:version>$VERSION</em:version>|" -e "s|<em:updateLink>.*</em:updateLink>|<em:updateLink>https://::HOSTNAME::/updates/${VERSION}_extension.xpi</em:updateLink>|" -e "s|<em:updateHash>.*</em:updateHash>|<em:updateHash>sha512:$SHA512</em:updateHash>|" update.rdf > "$prefix/patch/update.rdf"
 
327
fi