3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
16 # The Original Code is Mozilla Update Packaging.
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.
24 # Thomas Berezansky <tsbere@mvlc.org>
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.
38 # ***** END LICENSE BLOCK *****
40 # Portions of this code were based on code by Darin Fisher found here:
41 # http://mxr.mozilla.org/mozilla/source/tools/update-packaging/
43 prefix=${1:-/openils/var/updates}
53 echo "Building Generic Updates only"
57 echo "Building Windows Updates only"
61 echo "Building Linux Updates only"
65 echo "Building Extension Updates only"
69 echo "Building All Updates"
78 echo "Extension only - No client"
81 echo "Building Client(s)"
85 echo "Not Building Client(s)"
89 function unwrap_update
94 find "$2" -type f -exec mv {} {}.bz2 \;
95 find "$2" -type f -name '*.bz2' -exec $BZIP2 -d {} \;
103 MANIFEST="$WORK/update.manifest"
104 ARCHIVEFILES="update.manifest"
108 for FILE in `find "$NEW" -type f`; do
111 for FILE in `find "$OLD" -type f`; do
114 $BZIP2 -z9 "$MANIFEST"
115 mv "$MANIFEST.bz2" "$MANIFEST"
121 CHECK_FILE="${1#$NEW/}"
122 if [ $CHECK_FILE == "update.manifest" -o $CHECK_FILE == "defaults/preferences/developers.js" -o $CHECK_FILE == "defaults/preferences/aa_per_machine.js" ]; then
123 echo "Skipping $CHECK_FILE";
126 DIR=$(dirname "$WORK/$CHECK_FILE")
127 if [ ! -f "$OLD/$CHECK_FILE" ]; then
128 echo "add \"$CHECK_FILE\"" >> "$MANIFEST"
130 $BZIP2 -cz9 "$NEW/$CHECK_FILE" > "$WORK/$CHECK_FILE"
131 if [ -x "$NEW/$CHECK_FILE" ]; then
132 chmod 0755 "$WORK/$CHECK_FILE"
134 chmod 0644 "$WORK/$CHECK_FILE"
136 ARCHIVEFILES="$ARCHIVEFILES \"$CHECK_FILE\""
138 elif ! diff "$OLD/$CHECK_FILE" "$NEW/$CHECK_FILE" > /dev/null; then
140 $MBSDIFF "$OLD/$CHECK_FILE" "$NEW/$CHECK_FILE" "$WORK/$CHECK_FILE.patch"
141 $BZIP2 -z9 "$WORK/$CHECK_FILE.patch"
142 $BZIP2 -cz9 "$NEW/$CHECK_FILE" > "$WORK/$CHECK_FILE"
143 PATCHSIZE=`du -b "$WORK/$CHECK_FILE.patch.bz2"`
144 FULLSIZE=`du -b "$WORK/$CHECK_FILE"`
145 PATCHSIZE="${PATCHSIZE%% *}"
146 FULLSIZE="${FULLSIZE%% *}"
147 if [ $PATCHSIZE -lt $FULLSIZE ]; then
148 rm -f "$WORK/$CHECK_FILE"
149 mv "$WORK/$CHECK_FILE.patch.bz2" "$WORK/$CHECK_FILE.patch"
150 echo "patch \"$CHECK_FILE.patch\" \"$CHECK_FILE\"" >> "$MANIFEST"
151 ARCHIVEFILES="$ARCHIVEFILES \"$CHECK_FILE.patch\""
153 rm -f "$WORK/$CHECK_FILE.patch.bz2"
154 if [ -x "$NEW/$CHECK_FILE" ]; then
155 chmod 0755 "$WORK/$CHECK_FILE"
157 chmod 0644 "$WORK/$CHECK_FILE"
159 echo "add \"$CHECK_FILE\"" >> "$MANIFEST"
160 ARCHIVEFILES="$ARCHIVEFILES \"$CHECK_FILE\""
163 rm -f "$OLD/$CHECK_FILE"
169 if [ $RM_FILE != "update.manifest" -a $RM_FILE != "defaults/preferences/developers.js" -a $RM_FILE != "defaults/preferences/aa_per_machine.js" -a $RM_FILE != "defaults/preferences/autoupdate.js" -a $RM_FILE != "defaults/preferences/autochannel.js" ]; then
170 echo "remove \"$RM_FILE\"" >> "$MANIFEST"
174 function build_update
176 eval "$MAR -C \"$WORK\" -c output.mar $ARCHIVEFILES"
177 mv "$WORK/output.mar" "$1"
186 if which mbsdiff; then
187 MBSDIFF=${MBSDIFF:-mbsdiff}
189 if [ ! -x "$MAR" -o ! -x "$MBSDIFF" ]; then
190 if [ ! -f "external/mar" -o ! -f "external/mbsdiff" ]; then
191 wget ftp://ftp.mozilla.org/pub/mozilla.org/xulrunner/mar-generation-tools/mar-generation-tools-linux.zip
192 unzip mar-generation-tools-linux.zip -d external
194 MAR="$PWD/external/mar"
195 MBSDIFF="$PWD/external/mbsdiff"
199 function make_full_update
201 echo "Making full update"
204 prep_update client oldclient client.working
205 build_update "full_update.mar"
207 mv full_update.mar "$PUBPATH/$VERSION.mar"
208 echo "Making full update patch def"
209 mkdir -p "$PATCHPATH"
210 HASH=$(sha512sum "$PUBPATH/$VERSION.mar")
211 SIZE=$(du -b "$PUBPATH/$VERSION.mar")
212 echo "<patch type=\"complete\" URL=\"$VERSION.mar\" hashFunction=\"sha512\" hashValue=\"${HASH%% *}\" size=\"${SIZE%% *}\"/>" > "$PATCHPATH/$VERSION.patchline"
215 function make_partial_update
217 PREV_VERSION="${1%.mar}"
218 if [ "$VERSION" == "$PREV_VERSION" ]; then
219 echo "Skipping partial update for same version"
222 echo "Making partial update from $PREV_VERSION"
225 unwrap_update "$ARCHIVEPATH/$1" oldclient
226 prep_update client oldclient client.working
227 build_update "partial_update.mar"
228 mv partial_update.mar "$PUBPATH/$PREV_VERSION-$VERSION.mar"
229 echo "Making partial update patch def"
230 mkdir -p "$PATCHPATH"
231 HASH=$(sha512sum "$PUBPATH/$PREV_VERSION-$VERSION.mar")
232 SIZE=$(du -b "$PUBPATH/$PREV_VERSION-$VERSION.mar")
233 echo "<patch type=\"partial\" URL=\"$PREV_VERSION-$VERSION.mar\" hashFunction=\"sha512\" hashValue=\"${HASH%% *}\" size=\"${SIZE%% *}\"/>" > "$PATCHPATH/$PREV_VERSION-$VERSION.patchline"
236 function make_partial_updates
238 echo "Checking for partial update source files"
239 if [ -d "$ARCHIVEPATH" ]; then
240 for OLDVER in `find "$ARCHIVEPATH" -maxdepth 1 -name '*.mar'`; do
241 make_partial_update "${OLDVER##*/}"
244 mkdir -p "$ARCHIVEPATH"
245 echo "Copying full update to archive"
246 cp "$PUBPATH/$VERSION.mar" "$ARCHIVEPATH"
247 echo "Updating current version file"
248 echo "$VERSION" > "$PATCHPATH/VERSION"
251 function cleanup_files
253 echo "Cleaning up previous update mar files and update patch files"
254 find "$PUBPATH" -maxdepth 1 -name "*.mar" ! -name "*$VERSION.mar" -delete -print
255 find "$PATCHPATH" -maxdepth 1 -name "*.patch" ! -name "*$VERSION.patch" -delete -print
258 # First, do we have the mar and mbsdiff tools?
260 VERSION=`cat build/VERSION`
262 # Generic Updates - No XULRunner packaged, channel of "release"
263 # NOTE: Generic updates CAN update Windows/Linux builds, and will do so if you don't build platform specific ones
264 if [ $GEN_UPDATES -eq 1 ]; then
265 PATCHPATH="$prefix/patch"
266 PUBPATH="$prefix/pub"
267 ARCHIVEPATH="$prefix/archives"
268 if [ $CLIENTS -eq 1 ]; then
270 mkdir -p "$prefix/pub/clients/"
271 find "$prefix/pub/clients/" -name '*_client.xpi' -delete
272 mv evergreen_staff_client.xpi "$prefix/pub/clients/${VERSION}_client.xpi"
281 # Windows Updates - Windows XULRunner, update channel of "win"
282 if [ $WIN_UPDATES -eq 1 ]; then
283 PATCHPATH="$prefix/patch/win"
284 PUBPATH="$prefix/pub/win"
285 ARCHIVEPATH="$prefix/archives/win"
286 if [ $CLIENTS -eq 1 ]; then
288 mkdir -p "$prefix/pub/clients/"
289 find "$prefix/pub/clients/" -name '*_setup.exe' -delete
290 mv evergreen_staff_client_setup.exe "$prefix/pub/clients/${VERSION}_setup.exe"
299 # Linux Updates - Linux XULRunner, update channel of "lin'
300 if [ $LINUX_UPDATES -eq 1 ]; then
301 PATCHPATH="$prefix/patch/lin"
302 PUBPATH="$prefix/pub/lin"
303 ARCHIVEPATH="$prefix/archives/lin"
304 if [ $CLIENTS -eq 1 ]; then
306 mkdir -p "$prefix/pub/clients/"
307 find "$prefix/pub/clients/" -name '*.tar.bz2' -delete
308 mv evergreen_staff_client.tar.bz2 "$prefix/pub/clients/${VERSION}.tar.bz2"
318 # Not really "Updates" so much as "Update", plural for consistency in command.
319 # Extensions don't do partial updates. Or at least not that I found docs for.
320 if [ $EXT_UPDATES -eq 1 ]; then
322 mkdir -p "$prefix/pub/"
323 find "$prefix/pub/" -maxdepth 1 -name '*_extension.xpi' -delete
324 mv evergreen.xpi "$prefix/pub/${VERSION}_extension.xpi"
325 SHA512=$(sha512sum "$prefix/pub/${VERSION}_extension.xpi")
327 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"