-
Notifications
You must be signed in to change notification settings - Fork 98
/
build.sh
executable file
·719 lines (616 loc) · 27.6 KB
/
build.sh
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
#!/bin/bash -e
# Copyright (c) 2011 Zotero
# Center for History and New Media
# George Mason University, Fairfax, Virginia, USA
# http://zotero.org
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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/>.
CALLDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. "$CALLDIR/config.sh"
if [ "`uname`" = "Darwin" ]; then
MAC_NATIVE=1
else
MAC_NATIVE=0
fi
if [ "`uname -o 2> /dev/null`" = "Cygwin" ]; then
WIN_NATIVE=1
else
WIN_NATIVE=0
fi
function usage {
cat >&2 <<DONE
Usage: $0 [-d DIR] [-f FILE] -p PLATFORMS [-c CHANNEL] [-d]
Options
-d DIR build directory to build from (from build_xpi; cannot be used with -f)
-f FILE ZIP file to build from (cannot be used with -d)
-t add devtools
-p PLATFORMS build for platforms PLATFORMS (m=Mac, w=Windows, l=Linux)
-c CHANNEL use update channel CHANNEL
-e enforce signing
-s don't package; only build binaries in staging/ directory
DONE
exit 1
}
BUILD_DIR=`mktemp -d`
function cleanup {
rm -rf $BUILD_DIR
}
trap cleanup EXIT
function abspath {
echo $(cd $(dirname $1); pwd)/$(basename $1);
}
SOURCE_DIR=""
ZIP_FILE=""
BUILD_MAC=0
BUILD_WIN32=0
BUILD_LINUX=0
PACKAGE=1
DEVTOOLS=0
while getopts "d:f:p:c:tse" opt; do
case $opt in
d)
SOURCE_DIR="$OPTARG"
;;
f)
ZIP_FILE="$OPTARG"
;;
p)
for i in `seq 0 1 $((${#OPTARG}-1))`
do
case ${OPTARG:i:1} in
m) BUILD_MAC=1;;
w) BUILD_WIN32=1;;
l) BUILD_LINUX=1;;
*)
echo "$0: Invalid platform option ${OPTARG:i:1}"
usage
;;
esac
done
;;
c)
UPDATE_CHANNEL="$OPTARG"
;;
t)
DEVTOOLS=1
;;
e)
SIGN=1
;;
s)
PACKAGE=0
;;
*)
usage
;;
esac
shift $((OPTIND-1)); OPTIND=1
done
# Require source dir or ZIP file
if [[ -z "$SOURCE_DIR" ]] && [[ -z "$ZIP_FILE" ]]; then
usage
elif [[ -n "$SOURCE_DIR" ]] && [[ -n "$ZIP_FILE" ]]; then
usage
fi
# Require at least one platform
if [[ $BUILD_MAC == 0 ]] && [[ $BUILD_WIN32 == 0 ]] && [[ $BUILD_LINUX == 0 ]]; then
usage
fi
# Bundle devtools with dev builds
if [ $UPDATE_CHANNEL == "beta" ] || [ $UPDATE_CHANNEL == "dev" ]; then
DEVTOOLS=1
fi
BUILD_ID=`date +%Y%m%d%H%M%S`
shopt -s extglob
mkdir -p "$BUILD_DIR/zotero"
rm -rf "$STAGE_DIR"
mkdir "$STAGE_DIR"
rm -rf "$DIST_DIR"
mkdir "$DIST_DIR"
# Save build id, which is needed for updates manifest
echo $BUILD_ID > "$DIST_DIR/build_id"
if [ -z "$UPDATE_CHANNEL" ]; then UPDATE_CHANNEL="default"; fi
if [ -n "$ZIP_FILE" ]; then
ZIP_FILE="`abspath $ZIP_FILE`"
echo "Building from $ZIP_FILE"
unzip -q $ZIP_FILE -d "$BUILD_DIR/zotero"
else
# TODO: Could probably just mv instead, at least if these repos are merged
rsync -a "$SOURCE_DIR/" "$BUILD_DIR/zotero/"
fi
cd "$BUILD_DIR/zotero"
# 5.0.96.3 / 5.0.97-beta.37+ddc7be75c
VERSION=`perl -ne 'print and last if s/.*<em:version>(.+)<\/em:version>.*/\1/;' install.rdf`
# 5.0.96 / 5.0.97
VERSION_NUMERIC=`perl -ne 'print and last if s/.*<em:version>(\d+\.\d+(\.\d+)?).*<\/em:version>.*/\1/;' install.rdf`
if [ -z "$VERSION" ]; then
echo "Version number not found in install.rdf"
exit 1
fi
rm install.rdf
echo
echo "Version: $VERSION"
# Delete Mozilla signing info if present
rm -rf META-INF
# Copy branding
cp -R "$CALLDIR/assets/branding" "$BUILD_DIR/zotero/chrome/branding"
# Add to chrome manifest
echo "" >> "$BUILD_DIR/zotero/chrome.manifest"
cat "$CALLDIR/assets/chrome.manifest" >> "$BUILD_DIR/zotero/chrome.manifest"
# Copy Error Console files
cp "$CALLDIR/assets/console/jsconsole-clhandler.js" "$BUILD_DIR/zotero/components/"
echo >> "$BUILD_DIR/zotero/chrome.manifest"
cat "$CALLDIR/assets/console/jsconsole-clhandler.manifest" >> "$BUILD_DIR/zotero/chrome.manifest"
cp -R "$CALLDIR/assets/console/content" "$BUILD_DIR/zotero/chrome/console"
cp -R "$CALLDIR/assets/console/skin/osx" "$BUILD_DIR/zotero/chrome/console/skin"
cp -R "$CALLDIR/assets/console/locale/en-US" "$BUILD_DIR/zotero/chrome/console/locale"
cat "$CALLDIR/assets/console/jsconsole.manifest" >> "$BUILD_DIR/zotero/chrome.manifest"
# Delete files that shouldn't be distributed
find "$BUILD_DIR/zotero/chrome" -name .DS_Store -exec rm -f {} \;
# Zip chrome into JAR
cd "$BUILD_DIR/zotero"
zip -r -q zotero.jar chrome deleted.txt resource styles.zip translators.index translators.zip styles translators.json translators
rm -rf "chrome/"* install.rdf deleted.txt resource styles.zip translators.index translators.zip styles translators.json translators
# Copy updater.ini
cp "$CALLDIR/assets/updater.ini" "$BUILD_DIR/zotero"
# Adjust chrome.manifest
perl -pi -e 's^(chrome|resource)/^jar:zotero.jar\!/$1/^g' "$BUILD_DIR/zotero/chrome.manifest"
# Adjust connector pref
perl -pi -e 's/pref\("extensions\.zotero\.httpServer\.enabled", false\);/pref("extensions.zotero.httpServer.enabled", true);/g' "$BUILD_DIR/zotero/defaults/preferences/zotero.js"
perl -pi -e 's/pref\("extensions\.zotero\.connector\.enabled", false\);/pref("extensions.zotero.connector.enabled", true);/g' "$BUILD_DIR/zotero/defaults/preferences/zotero.js"
# Copy icons
cp -r "$CALLDIR/assets/icons" "$BUILD_DIR/zotero/chrome/icons"
# Copy application.ini and modify
cp "$CALLDIR/assets/application.ini" "$BUILD_DIR/application.ini"
perl -pi -e "s/\{\{VERSION}}/$VERSION/" "$BUILD_DIR/application.ini"
perl -pi -e "s/\{\{BUILDID}}/$BUILD_ID/" "$BUILD_DIR/application.ini"
# Copy prefs.js and modify
cp "$CALLDIR/assets/prefs.js" "$BUILD_DIR/zotero/defaults/preferences"
perl -pi -e 's/pref\("app\.update\.channel", "[^"]*"\);/pref\("app\.update\.channel", "'"$UPDATE_CHANNEL"'");/' "$BUILD_DIR/zotero/defaults/preferences/prefs.js"
# Add devtools manifest and prefs
if [ $DEVTOOLS -eq 1 ]; then
# Adjust paths for .jar
cat "$CALLDIR/assets/devtools.manifest" >> "$BUILD_DIR/zotero/chrome.manifest"
perl -pi -e 's/chrome\/locale\/en-US\/devtools\//jar:devtools.jar!\/locale\/en-US\/devtools\//' "$BUILD_DIR/zotero/chrome.manifest"
perl -pi -e 's/chrome\/devtools\//jar:devtools.jar!\//' "$BUILD_DIR/zotero/chrome.manifest"
echo 'pref("devtools.debugger.remote-enabled", true);' >> "$BUILD_DIR/zotero/defaults/preferences/prefs.js"
echo 'pref("devtools.debugger.remote-port", 6100);' >> "$BUILD_DIR/zotero/defaults/preferences/prefs.js"
echo 'pref("devtools.debugger.prompt-connection", false);' >> "$BUILD_DIR/zotero/defaults/preferences/prefs.js"
fi
echo -n "Channel: "
grep app.update.channel "$BUILD_DIR/zotero/defaults/preferences/prefs.js"
echo
# Remove unnecessary files
find "$BUILD_DIR" -name .DS_Store -exec rm -f {} \;
rm -rf "$BUILD_DIR/zotero/test"
cd "$CALLDIR"
# Mac
if [ $BUILD_MAC == 1 ]; then
echo 'Building Zotero.app'
# Set up directory structure
APPDIR="$STAGE_DIR/Zotero.app"
rm -rf "$APPDIR"
mkdir "$APPDIR"
chmod 755 "$APPDIR"
cp -r "$CALLDIR/mac/Contents" "$APPDIR"
CONTENTSDIR="$APPDIR/Contents"
# Modify platform-specific prefs
perl -pi -e 's/pref\("browser\.preferences\.instantApply", false\);/pref\("browser\.preferences\.instantApply", true);/' "$BUILD_DIR/zotero/defaults/preferences/prefs.js"
perl -pi -e 's/%GECKO_VERSION%/'"$GECKO_VERSION_MAC"'/g' "$BUILD_DIR/zotero/defaults/preferences/prefs.js"
# Fix horizontal mousewheel scrolling (this is set to 4 in the Fx60 .app greprefs.js, but
# defaults to 1 in later versions of Firefox, and needs to be 1 to work on macOS)
echo 'pref("mousewheel.with_shift.action", 1);' >> "$BUILD_DIR/zotero/defaults/preferences/prefs.js"
# Merge relevant assets from Firefox
mkdir "$CONTENTSDIR/MacOS"
cp -r "$MAC_RUNTIME_PATH/Contents/MacOS/"!(firefox|firefox-bin|crashreporter.app|pingsender|updater.app) "$CONTENTSDIR/MacOS"
cp -r "$MAC_RUNTIME_PATH/Contents/Resources/"!(application.ini|updater.ini|update-settings.ini|browser|devtools-files|precomplete|removed-files|webapprt*|*.icns|defaults|*.lproj) "$CONTENTSDIR/Resources"
# Use our own launcher
cp "$CALLDIR/mac/zotero" "$CONTENTSDIR/MacOS/zotero"
cp "$BUILD_DIR/application.ini" "$CONTENTSDIR/Resources"
# TEMP: Modified versions of some Firefox components for Big Sur, placed in xulrunner/MacOS
cp "$MAC_RUNTIME_PATH/../MacOS/"{libc++.1.dylib,libnss3.dylib,XUL} "$CONTENTSDIR/MacOS/"
# Use our own updater, because Mozilla's requires updates signed by Mozilla
cd "$CONTENTSDIR/MacOS"
tar -xjf "$CALLDIR/mac/updater.tar.bz2"
# Copy PDF tools and data
cp "$CALLDIR/pdftools/pdftotext-mac" "$CONTENTSDIR/MacOS/pdftotext"
cp "$CALLDIR/pdftools/pdfinfo-mac" "$CONTENTSDIR/MacOS/pdfinfo"
cp -R "$CALLDIR/pdftools/poppler-data" "$CONTENTSDIR/Resources/"
# Modify Info.plist
perl -pi -e "s/\{\{VERSION\}\}/$VERSION/" "$CONTENTSDIR/Info.plist"
perl -pi -e "s/\{\{VERSION_NUMERIC\}\}/$VERSION_NUMERIC/" "$CONTENTSDIR/Info.plist"
if [ $UPDATE_CHANNEL == "beta" ] || [ $UPDATE_CHANNEL == "dev" ]; then
perl -pi -e "s/org\.zotero\.zotero/org.zotero.zotero-$UPDATE_CHANNEL/" "$CONTENTSDIR/Info.plist"
# TEMP: Necessary on Ventura until Zotero 7
elif [ $UPDATE_CHANNEL == "source" ]; then
perl -pi -e "s/org\.zotero\.zotero/org.zotero.zotero-dev/" "$CONTENTSDIR/Info.plist"
fi
perl -pi -e "s/\{\{VERSION\}\}/$VERSION/" "$CONTENTSDIR/Info.plist"
# Needed for "monkeypatch" Windows builds:
# http://www.nntp.perl.org/group/perl.perl5.porters/2010/08/msg162834.html
rm -f "$CONTENTSDIR/Info.plist.bak"
echo
grep -B 1 org.zotero.zotero "$CONTENTSDIR/Info.plist"
echo
grep -A 1 CFBundleShortVersionString "$CONTENTSDIR/Info.plist"
echo
grep -A 1 CFBundleVersion "$CONTENTSDIR/Info.plist"
echo
# Add components
cp -R "$BUILD_DIR/zotero/"* "$CONTENTSDIR/Resources"
# Add Mac-specific Standalone assets
cd "$CALLDIR/assets/mac"
zip -r -q "$CONTENTSDIR/Resources/zotero.jar" *
# Add devtools
if [ $DEVTOOLS -eq 1 ]; then
# Create devtools.jar
cd "$BUILD_DIR"
mkdir -p devtools/locale
cp -r "$MAC_RUNTIME_PATH"/Contents/Resources/devtools-files/chrome/devtools/* devtools/
cp -r "$MAC_RUNTIME_PATH"/Contents/Resources/devtools-files/chrome/locale/* devtools/locale/
cd devtools
zip -r -q ../devtools.jar *
cd ..
rm -rf devtools
mv devtools.jar "$CONTENTSDIR/Resources/"
cp "$MAC_RUNTIME_PATH/Contents/Resources/devtools-files/components/interfaces.xpt" "$CONTENTSDIR/Resources/components/"
fi
# Add word processor plug-ins
mkdir "$CONTENTSDIR/Resources/extensions"
cp -RH "$CALLDIR/modules/zotero-word-for-mac-integration" "$CONTENTSDIR/Resources/extensions/[email protected]"
cp -RH "$CALLDIR/modules/zotero-libreoffice-integration" "$CONTENTSDIR/Resources/extensions/[email protected]"
echo
for ext in "[email protected]" "[email protected]"; do
perl -pi -e 's/\.SOURCE<\/em:version>/.SA.'"$VERSION"'<\/em:version>/' "$CONTENTSDIR/Resources/extensions/$ext/install.rdf"
echo -n "$ext Version: "
perl -ne 'print and last if s/.*<em:version>(.*)<\/em:version>.*/\1/;' "$CONTENTSDIR/Resources/extensions/$ext/install.rdf"
rm -rf "$CONTENTSDIR/Resources/extensions/$ext/.git" "$CONTENTSDIR/Resources/extensions/$ext/.github"
done
# Default preferenes are no longer read from built-in extensions in Firefox 60
echo >> "$CONTENTSDIR/Resources/defaults/preferences/prefs.js"
cat "$CALLDIR/modules/zotero-word-for-mac-integration/defaults/preferences/zoteroMacWordIntegration.js" >> "$CONTENTSDIR/Resources/defaults/preferences/prefs.js"
echo >> "$CONTENTSDIR/Resources/defaults/preferences/prefs.js"
cat "$CALLDIR/modules/zotero-libreoffice-integration/defaults/preferences/zoteroOpenOfficeIntegration.js" >> "$CONTENTSDIR/Resources/defaults/preferences/prefs.js"
echo
# Delete extraneous files
find "$CONTENTSDIR" -depth -type d -name .git -exec rm -rf {} \;
find "$CONTENTSDIR" \( -name .DS_Store -or -name update.rdf \) -exec rm -f {} \;
find "$CONTENTSDIR/Resources/extensions" -depth -type d -name build -exec rm -rf {} \;
# Copy over removed-files and make a precomplete file since it
# needs to be stable for the signature
cp "$CALLDIR/update-packaging/removed-files_mac" "$CONTENTSDIR/Resources/removed-files"
touch "$CONTENTSDIR/Resources/precomplete"
# Sign
if [ $SIGN == 1 ]; then
# Unlock keychain if a password is provided (necessary for building from a shell)
if [ -n "$KEYCHAIN_PASSWORD" ]; then
security -v unlock-keychain -p "$KEYCHAIN_PASSWORD" ~/Library/Keychains/$KEYCHAIN.keychain-db
fi
# Clear extended attributes, which can cause codesign to fail
/usr/bin/xattr -cr "$APPDIR"
# Sign app
entitlements_file="$CALLDIR/mac/entitlements.xml"
/usr/bin/codesign --force --options runtime --entitlements "$entitlements_file" --sign "$DEVELOPER_ID" \
"$APPDIR/Contents/MacOS/pdftotext" \
"$APPDIR/Contents/MacOS/pdfinfo" \
"$APPDIR/Contents/MacOS/XUL" \
"$APPDIR/Contents/MacOS/updater.app/Contents/MacOS/org.mozilla.updater"
find "$APPDIR/Contents" -name '*.dylib' -exec /usr/bin/codesign --force --options runtime --entitlements "$entitlements_file" --sign "$DEVELOPER_ID" {} \;
find "$APPDIR/Contents" -name '*.app' -exec /usr/bin/codesign --force --options runtime --entitlements "$entitlements_file" --sign "$DEVELOPER_ID" {} \;
/usr/bin/codesign --force --options runtime --entitlements "$entitlements_file" --sign "$DEVELOPER_ID" "$APPDIR/Contents/MacOS/zotero"
# Bundle and sign Safari App Extension
#
# Even though it's signed by Xcode, we sign it again to make sure it matches the parent app signature
if [[ -n "$SAFARI_APPEX" ]] && [[ -d "$SAFARI_APPEX" ]]; then
echo
# Extract entitlements, which differ from parent app
/usr/bin/codesign -d --entitlements :"$BUILD_DIR/safari-entitlements.plist" $SAFARI_APPEX
mkdir "$APPDIR/Contents/PlugIns"
cp -R $SAFARI_APPEX "$APPDIR/Contents/PlugIns/ZoteroSafariExtension.appex"
# Add suffix to appex bundle identifier
if [ $UPDATE_CHANNEL == "beta" ] || [ $UPDATE_CHANNEL == "dev" ] || [ $UPDATE_CHANNEL == "source" ]; then
perl -pi -e "s/org\.zotero\.SafariExtensionApp\.SafariExtension/org.zotero.SafariExtensionApp.SafariExtension-$UPDATE_CHANNEL/" "$APPDIR/Contents/PlugIns/ZoteroSafariExtension.appex/Contents/Info.plist"
fi
find "$APPDIR/Contents/PlugIns/ZoteroSafariExtension.appex/Contents" -name '*.dylib' -exec /usr/bin/codesign --force --options runtime --entitlements "$entitlements_file" --sign "$DEVELOPER_ID" {} \;
/usr/bin/codesign --force --options runtime --entitlements "$BUILD_DIR/safari-entitlements.plist" --sign "$DEVELOPER_ID" "$APPDIR/Contents/PlugIns/ZoteroSafariExtension.appex"
fi
# Sign final app package
echo
/usr/bin/codesign --force --options runtime --entitlements "$entitlements_file" --sign "$DEVELOPER_ID" "$APPDIR"
# Verify app
/usr/bin/codesign --verify -vvvv "$APPDIR"
# Verify Safari App Extension
if [[ -n "$SAFARI_APPEX" ]] && [[ -d "$SAFARI_APPEX" ]]; then
echo
/usr/bin/codesign --verify -vvvv "$APPDIR/Contents/PlugIns/ZoteroSafariExtension.appex"
fi
fi
# Build and notarize disk image
if [ $PACKAGE == 1 ]; then
if [ $MAC_NATIVE == 1 ]; then
echo "Creating Mac installer"
dmg="$DIST_DIR/Zotero-$VERSION.dmg"
"$CALLDIR/mac/pkg-dmg" --source "$STAGE_DIR/Zotero.app" \
--target "$dmg" \
--sourcefile --volname Zotero --copy "$CALLDIR/mac/DSStore:/.DS_Store" \
--symlink /Applications:"/Drag Here to Install" > /dev/null
# Upload disk image to Apple
"$CALLDIR/scripts/notarize_mac_app" "$dmg"
echo
# Staple notarization info to disk image
"$CALLDIR/scripts/notarization_stapler" "$dmg"
echo "Notarization complete"
else
echo 'Not building on Mac; creating Mac distribution as a zip file'
rm -f "$DIST_DIR/Zotero_mac.zip"
cd "$STAGE_DIR" && zip -rqX "$DIST_DIR/Zotero-${VERSION}_mac.zip" Zotero.app
fi
fi
fi
# Win32
if [ $BUILD_WIN32 == 1 ]; then
echo 'Building Zotero_win32'
# Set up directory
APPDIR="$STAGE_DIR/Zotero_win32"
rm -rf "$APPDIR"
mkdir "$APPDIR"
# Modify platform-specific prefs
perl -pi -e 's/%GECKO_VERSION%/'"$GECKO_VERSION_WIN"'/g' "$BUILD_DIR/zotero/defaults/preferences/prefs.js"
# Copy relevant assets from Firefox
cp -R "$WIN32_RUNTIME_PATH"/!(application.ini|browser|defaults|devtools-files|crashreporter*|firefox.exe|maintenanceservice*|precomplete|removed-files|uninstall|update*) "$APPDIR"
# Copy zotero_win32.exe, which is built directly from Firefox source
#
# After the initial build the temporary resource in "C:\mozilla-source\obj-i686-pc-mingw32\browser\app\module.res"
# is modified with Visual Studio resource editor where icon and file details are changed.
# Then firefox.exe is rebuilt again
cp "$CALLDIR/win/zotero_win32.exe" "$APPDIR/zotero.exe"
# Update .exe version number (only possible on Windows)
if [ $WIN_NATIVE == 1 ]; then
# FileVersion is limited to four integers, so it won't be properly updated for non-release
# builds (e.g., we'll show 5.0.97.0 for 5.0.97-beta.37). ProductVersion will be the full
# version string.
rcedit "`cygpath -w \"$APPDIR/zotero.exe\"`" \
--set-file-version "$VERSION_NUMERIC" \
--set-product-version "$VERSION"
fi
# Use our own updater, because Mozilla's requires updates signed by Mozilla
cp "$CALLDIR/win/updater.exe" "$APPDIR"
cat "$CALLDIR/win/installer/updater_append.ini" >> "$APPDIR/updater.ini"
# Copy PDF tools and data
cp "$CALLDIR/pdftools/pdftotext-win.exe" "$APPDIR/pdftotext.exe"
cp "$CALLDIR/pdftools/pdfinfo-win.exe" "$APPDIR/pdfinfo.exe"
cp -R "$CALLDIR/pdftools/poppler-data" "$APPDIR/"
cp -R "$BUILD_DIR/zotero/"* "$BUILD_DIR/application.ini" "$APPDIR"
# Add Windows-specific Standalone assets
cd "$CALLDIR/assets/win"
zip -r -q "$APPDIR/zotero.jar" *
# Add devtools
if [ $DEVTOOLS -eq 1 ]; then
# Create devtools.jar
cd "$BUILD_DIR"
mkdir -p devtools/locale
cp -r "$WIN32_RUNTIME_PATH"/devtools-files/chrome/devtools/* devtools/
cp -r "$WIN32_RUNTIME_PATH"/devtools-files/chrome/locale/* devtools/locale/
cd devtools
zip -r -q ../devtools.jar *
cd ..
rm -rf devtools
mv devtools.jar "$APPDIR"
cp "$WIN32_RUNTIME_PATH/devtools-files/components/interfaces.xpt" "$APPDIR/components/"
fi
# Add word processor plug-ins
mkdir "$APPDIR/extensions"
cp -RH "$CALLDIR/modules/zotero-word-for-windows-integration" "$APPDIR/extensions/[email protected]"
cp -RH "$CALLDIR/modules/zotero-libreoffice-integration" "$APPDIR/extensions/[email protected]"
echo
for ext in "[email protected]" "[email protected]"; do
perl -pi -e 's/\.SOURCE<\/em:version>/.SA.'"$VERSION"'<\/em:version>/' "$APPDIR/extensions/$ext/install.rdf"
echo -n "$ext Version: "
perl -ne 'print and last if s/.*<em:version>(.*)<\/em:version>.*/\1/;' "$APPDIR/extensions/$ext/install.rdf"
rm -rf "$APPDIR/extensions/$ext/.git" "$APPDIR/extensions/$ext/.github"
done
# Default preferenes are no longer read from built-in extensions in Firefox 60
echo >> "$APPDIR/defaults/preferences/prefs.js"
cat "$CALLDIR/modules/zotero-word-for-windows-integration/defaults/preferences/zoteroWinWordIntegration.js" >> "$APPDIR/defaults/preferences/prefs.js"
echo >> "$APPDIR/defaults/preferences/prefs.js"
cat "$CALLDIR/modules/zotero-libreoffice-integration/defaults/preferences/zoteroOpenOfficeIntegration.js" >> "$APPDIR/defaults/preferences/prefs.js"
echo >> "$APPDIR/defaults/preferences/prefs.js"
echo
# Delete extraneous files
find "$APPDIR" -depth -type d -name .git -exec rm -rf {} \;
find "$APPDIR" \( -name .DS_Store -or -name '.git*' -or -name '.travis.yml' -or -name update.rdf -or -name '*.bak' \) -exec rm -f {} \;
find "$APPDIR/extensions" -depth -type d -name build -exec rm -rf {} \;
find "$APPDIR" \( -name '*.exe' -or -name '*.dll' \) -exec chmod 755 {} \;
if [ $PACKAGE == 1 ]; then
if [ $WIN_NATIVE == 1 ]; then
INSTALLER_PATH="$DIST_DIR/Zotero-${VERSION}_setup.exe"
echo 'Creating Windows installer'
# Copy installer files
cp -r "$CALLDIR/win/installer" "$BUILD_DIR/win_installer"
# Build and sign uninstaller
perl -pi -e "s/\{\{VERSION}}/$VERSION/" "$BUILD_DIR/win_installer/defines.nsi"
"`cygpath -u \"${NSIS_DIR}makensis.exe\"`" /V1 "`cygpath -w \"$BUILD_DIR/win_installer/uninstaller.nsi\"`"
mkdir "$APPDIR/uninstall"
mv "$BUILD_DIR/win_installer/helper.exe" "$APPDIR/uninstall"
# Sign zotero.exe, updater, uninstaller and PDF tools
if [ $SIGN == 1 ]; then
"`cygpath -u \"$SIGNTOOL\"`" \
sign /n "$SIGNTOOL_CERT_SUBJECT" \
/d "$SIGNATURE_DESC" \
/du "$SIGNATURE_URL" \
/fd SHA256 \
/tr "$SIGNTOOL_TIMESTAMP_SERVER" \
/td SHA256 \
"`cygpath -w \"$APPDIR/zotero.exe\"`"
sleep $SIGNTOOL_DELAY
#
# Windows doesn't check DLL signatures
#
#for dll in "$APPDIR/"*.dll "$APPDIR/"*.dll; do
# "`cygpath -u \"$SIGNTOOL\"`" \
# sign /n "$SIGNTOOL_CERT_SUBJECT" \
# /d "$SIGNATURE_DESC" \
# /fd SHA256 \
# /tr "$SIGNTOOL_TIMESTAMP_SERVER" \
# /td SHA256 \
# "`cygpath -w \"$dll\"`"
#done
"`cygpath -u \"$SIGNTOOL\"`" \
sign /n "$SIGNTOOL_CERT_SUBJECT" \
/d "$SIGNATURE_DESC Updater" \
/fd SHA256 \
/tr "$SIGNTOOL_TIMESTAMP_SERVER" \
/td SHA256 \
"`cygpath -w \"$APPDIR/updater.exe\"`"
sleep $SIGNTOOL_DELAY
"`cygpath -u \"$SIGNTOOL\"`" \
sign /n "$SIGNTOOL_CERT_SUBJECT" \
/d "$SIGNATURE_DESC Uninstaller" \
/fd SHA256 \
/tr "$SIGNTOOL_TIMESTAMP_SERVER" \
/td SHA256 \
"`cygpath -w \"$APPDIR/uninstall/helper.exe\"`"
sleep $SIGNTOOL_DELAY
"`cygpath -u \"$SIGNTOOL\"`" \
sign /n "$SIGNTOOL_CERT_SUBJECT" \
/d "$SIGNATURE_DESC PDF Converter" \
/fd SHA256 \
/tr "$SIGNTOOL_TIMESTAMP_SERVER" \
/td SHA256 \
"`cygpath -w \"$APPDIR/pdftotext.exe\"`"
sleep $SIGNTOOL_DELAY
"`cygpath -u \"$SIGNTOOL\"`" \
sign /n "$SIGNTOOL_CERT_SUBJECT" \
/d "$SIGNATURE_DESC PDF Info" \
/fd SHA256 \
/tr "$SIGNTOOL_TIMESTAMP_SERVER" \
/td SHA256 \
"`cygpath -w \"$APPDIR/pdfinfo.exe\"`"
sleep $SIGNTOOL_DELAY
fi
# Stage installer
INSTALLER_STAGE_DIR="$BUILD_DIR/win_installer/staging"
mkdir "$INSTALLER_STAGE_DIR"
cp -R "$APPDIR" "$INSTALLER_STAGE_DIR/core"
# Build and sign setup.exe
"`cygpath -u \"${NSIS_DIR}makensis.exe\"`" /V1 "`cygpath -w \"$BUILD_DIR/win_installer/installer.nsi\"`"
mv "$BUILD_DIR/win_installer/setup.exe" "$INSTALLER_STAGE_DIR"
if [ $SIGN == 1 ]; then
"`cygpath -u \"$SIGNTOOL\"`" \
sign /n "$SIGNTOOL_CERT_SUBJECT" \
/d "$SIGNATURE_DESC Setup" \
/du "$SIGNATURE_URL" \
/fd SHA256 \
/tr "$SIGNTOOL_TIMESTAMP_SERVER" \
/td SHA256 \
"`cygpath -w \"$INSTALLER_STAGE_DIR/setup.exe\"`"
sleep $SIGNTOOL_DELAY
fi
# Compress application
cd "$INSTALLER_STAGE_DIR" && 7z a -r -t7z "`cygpath -w \"$BUILD_DIR/app_win32.7z\"`" \
-mx -m0=BCJ2 -m1=LZMA:d24 -m2=LZMA:d19 -m3=LZMA:d19 -mb0:1 -mb0s1:2 -mb0s2:3 > /dev/null
# Compress 7zSD.sfx
upx --best -o "`cygpath -w \"$BUILD_DIR/7zSD.sfx\"`" \
"`cygpath -w \"$CALLDIR/win/installer/7zstub/firefox/7zSD.sfx\"`" > /dev/null
# Combine 7zSD.sfx and app.tag into setup.exe
cat "$BUILD_DIR/7zSD.sfx" "$CALLDIR/win/installer/app.tag" \
"$BUILD_DIR/app_win32.7z" > "$INSTALLER_PATH"
# Sign Zotero_setup.exe
if [ $SIGN == 1 ]; then
"`cygpath -u \"$SIGNTOOL\"`" \
sign /n "$SIGNTOOL_CERT_SUBJECT" \
/d "$SIGNATURE_DESC Setup" \
/du "$SIGNATURE_URL" \
/fd SHA256 \
/tr "$SIGNTOOL_TIMESTAMP_SERVER" \
/td SHA256 \
"`cygpath -w \"$INSTALLER_PATH\"`"
fi
chmod 755 "$INSTALLER_PATH"
else
echo 'Not building on Windows; only building zip file'
fi
cd "$STAGE_DIR" && zip -rqX "$DIST_DIR/Zotero-${VERSION}_win32.zip" Zotero_win32
fi
fi
# Linux
if [ $BUILD_LINUX == 1 ]; then
for arch in "i686" "x86_64"; do
RUNTIME_PATH=`eval echo '$LINUX_'$arch'_RUNTIME_PATH'`
# Set up directory
echo 'Building Zotero_linux-'$arch
APPDIR="$STAGE_DIR/Zotero_linux-$arch"
rm -rf "$APPDIR"
mkdir "$APPDIR"
# Merge relevant assets from Firefox
cp -r "$RUNTIME_PATH/"!(application.ini|browser|defaults|devtools-files|crashreporter|crashreporter.ini|firefox-bin|pingsender|precomplete|removed-files|run-mozilla.sh|update-settings.ini|updater|updater.ini) "$APPDIR"
# Use our own launcher that calls the original Firefox executable with -app
mv "$APPDIR"/firefox "$APPDIR"/zotero-bin
cp "$CALLDIR/linux/zotero" "$APPDIR"/zotero
# Copy Ubuntu launcher files
cp "$CALLDIR/linux/zotero.desktop" "$APPDIR"
cp "$CALLDIR/linux/set_launcher_icon" "$APPDIR"
# Use our own updater, because Mozilla's requires updates signed by Mozilla
cp "$CALLDIR/linux/updater-$arch" "$APPDIR"/updater
# Copy PDF tools and data
cp "$CALLDIR/pdftools/pdftotext-linux-$arch" "$APPDIR/pdftotext"
cp "$CALLDIR/pdftools/pdfinfo-linux-$arch" "$APPDIR/pdfinfo"
cp -R "$CALLDIR/pdftools/poppler-data" "$APPDIR/"
cp -R "$BUILD_DIR/zotero/"* "$BUILD_DIR/application.ini" "$APPDIR"
# Modify platform-specific prefs
perl -pi -e 's/pref\("browser\.preferences\.instantApply", false\);/pref\("browser\.preferences\.instantApply", true);/' "$BUILD_DIR/zotero/defaults/preferences/prefs.js"
perl -pi -e 's/%GECKO_VERSION%/'"$GECKO_VERSION_LINUX"'/g' "$BUILD_DIR/zotero/defaults/preferences/prefs.js"
# Add Unix-specific Standalone assets
cd "$CALLDIR/assets/unix"
zip -0 -r -q "$APPDIR/zotero.jar" *
# Add devtools
if [ $DEVTOOLS -eq 1 ]; then
# Create devtools.jar
cd "$BUILD_DIR"
mkdir -p devtools/locale
cp -r "$RUNTIME_PATH"/devtools-files/chrome/devtools/* devtools/
cp -r "$RUNTIME_PATH"/devtools-files/chrome/locale/* devtools/locale/
cd devtools
zip -r -q ../devtools.jar *
cd ..
rm -rf devtools
mv devtools.jar "$APPDIR"
cp "$RUNTIME_PATH/devtools-files/components/interfaces.xpt" "$APPDIR/components/"
fi
# Add word processor plug-ins
mkdir "$APPDIR/extensions"
cp -RH "$CALLDIR/modules/zotero-libreoffice-integration" "$APPDIR/extensions/[email protected]"
perl -pi -e 's/\.SOURCE<\/em:version>/.SA.'"$VERSION"'<\/em:version>/' "$APPDIR/extensions/[email protected]/install.rdf"
echo
echo -n "[email protected] Version: "
perl -ne 'print and last if s/.*<em:version>(.*)<\/em:version>.*/\1/;' "$APPDIR/extensions/[email protected]/install.rdf"
echo
rm -rf "$APPDIR/extensions/[email protected]/.git" "$APPDIR/extensions/[email protected]/.github"
# Default preferenes are no longer read from built-in extensions in Firefox 60
echo >> "$APPDIR/defaults/preferences/prefs.js"
cat "$CALLDIR/modules/zotero-libreoffice-integration/defaults/preferences/zoteroOpenOfficeIntegration.js" >> "$APPDIR/defaults/preferences/prefs.js"
echo >> "$APPDIR/defaults/preferences/prefs.js"
# Delete extraneous files
find "$APPDIR" -depth -type d -name .git -exec rm -rf {} \;
find "$APPDIR" \( -name .DS_Store -or -name update.rdf \) -exec rm -f {} \;
find "$APPDIR/extensions" -depth -type d -name build -exec rm -rf {} \;
if [ $PACKAGE == 1 ]; then
# Create tar
rm -f "$DIST_DIR/Zotero-${VERSION}_linux-$arch.tar.bz2"
cd "$STAGE_DIR"
tar -cjf "$DIST_DIR/Zotero-${VERSION}_linux-$arch.tar.bz2" "Zotero_linux-$arch"
fi
done
fi
rm -rf $BUILD_DIR