forked from EFForg/https-everywhere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makexpi.sh
executable file
·136 lines (118 loc) · 4.77 KB
/
makexpi.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
#!/bin/bash
set -o errexit
APP_NAME=https-everywhere
# builds a .xpi from the git repository, placing the .xpi in the root
# of the repository.
#
# invoke with no arguments to build from the current src directory.
#
# ./makexpi.sh
#
# OR, invoke with a tag name to build a specific branch or tag.
#
# e.g.:
#
# ./makexpi.sh 0.2.3.development.2
cd "`dirname $0`"
RULESETS_UNVALIDATED="$PWD/pkg/rulesets.unvalidated.sqlite"
RULESETS_JSON="$PWD/src/defaults/rulesets.json"
ANDROID_APP_ID=org.mozilla.firefox
VERSION=`echo $1 | cut -d "-" -f 2`
[ -d pkg ] || mkdir pkg
# If the command line argument is a tag name, check that out and build it
if [ -n "$1" ] && [ "$2" != "--no-recurse" ] ; then
BRANCH=`git branch | head -n 1 | cut -d \ -f 2-`
SUBDIR=checkout
[ -d $SUBDIR ] || mkdir $SUBDIR
cp -r -f -a .git $SUBDIR
cd $SUBDIR
git reset --hard "$1"
# When a file is renamed, the old copy can linger in the checkout directory.
# Ensure a clean build.
git clean -fdx
git submodule update --recursive -f
# Use the version of the build script that was current when that
# tag/release/branch was made.
./makexpi.sh $1 --no-recurse || exit 1
# The fact that the above works even when the thing you are building predates
# support for --no-recurse in this script is (1) non-intuitive; (2) crazy; and (3)
# involves two pristine checkouts of $1 within each other
# Now escape from the horrible mess we've made
cd ..
XPI_NAME="$APP_NAME-$VERSION"
cp $SUBDIR/pkg/$XPI_NAME-eff.xpi pkg/
if ! cp $SUBDIR/pkg/$XPI_NAME-amo.xpi pkg/ 2> /dev/null ; then
echo Old version does not support AMO
fi
rm -rf $SUBDIR
exit 0
fi
# Only generate the ruleset database if any rulesets have changed. Tried
# implementing this with make, but make is very slow with 15k+ input files.
needs_update() {
find src/chrome/content/rules/ -newer $RULESETS_UNVALIDATED |\
grep -q .
}
if [ ! -f "$RULESETS_UNVALIDATED" ] || needs_update ; then
# This is an optimization to get the OS reading the rulesets into RAM ASAP;
# it's useful on machines with slow disk seek times; doing several of these
# at once allows the IO subsystem to seek more efficiently.
for firstchar in `echo {a..z} {A..Z} {0..9}` ; do
# Those cover everything but it wouldn't matter if they didn't
nohup cat src/chrome/content/rules/"$firstchar"*.xml >/dev/null 2>/dev/null &
done
echo "Generating ruleset DB"
python2.7 ./utils/make-sqlite.py
fi
# =============== BEGIN VALIDATION ================
# Unless we're in a hurry, validate the ruleset library & locales
die() {
echo >&2 "ERROR:" "$@"
exit 1
}
bash utils/validate.sh
# The name/version of the XPI we're building comes from src/install.rdf
XPI_NAME="pkg/$APP_NAME-`grep em:version src/install.rdf | sed -e 's/[<>]/ /g' | cut -f3`"
if [ "$1" ]; then
XPI_NAME="$XPI_NAME"
else
# During development, generate packages named with the short hash of HEAD.
XPI_NAME="$XPI_NAME~`git rev-parse --short HEAD`"
if ! git diff-index --quiet HEAD; then
XPI_NAME="$XPI_NAME-dirty"
fi
fi
# Prepare packages suitable for uploading to EFF and AMO, respectively.
[ -d pkg ] || mkdir pkg
rsync -a --delete --delete-excluded --exclude /chrome/content/rules src/ pkg/xpi-eff
cp -a translations/* pkg/xpi-eff/chrome/locale/
rsync -a --delete pkg/xpi-eff/ pkg/xpi-amo
# The AMO version of the package cannot contain the updateKey or updateURL tags.
# Also, it has a different id than the eff-hosted version, because Firefox now
# requires us to upload the eff-hosted version to an unlisted extension on AMO
# in order to receive a signature indicating that it is not malware.
# https://github.com/efforg/https-everywhere/issues/2051
sed -i.bak -e '/updateKey/d' -e '/updateURL/d' \
-e 's,<em:id>[email protected]</em:id>,<em:id>[email protected]</em:id>,' \
pkg/xpi-amo/install.rdf
rm pkg/xpi-amo/install.rdf.bak
# Used for figuring out which branch to pull from when viewing source for rules
GIT_OBJECT_FILE=".git/refs/heads/master"
export GIT_COMMIT_ID="HEAD"
if [ -e "$GIT_OBJECT_FILE" ]; then
export GIT_COMMIT_ID=$(cat "$GIT_OBJECT_FILE")
fi
# Build the XPI!
rm -f "${XPI_NAME}.xpi"
rm -f "${XPI_NAME}-eff.xpi"
rm -f "${XPI_NAME}-amo.xpi"
python2.7 utils/create_xpi.py -n "${XPI_NAME}-eff.xpi" -x ".build_exclusions" "pkg/xpi-eff"
python2.7 utils/create_xpi.py -n "${XPI_NAME}-amo.xpi" -x ".build_exclusions" "pkg/xpi-amo"
echo >&2 "Total included rules: `find src/chrome/content/rules -name "*.xml" | wc -l`"
echo >&2 "Rules disabled by default: `find src/chrome/content/rules -name "*.xml" | xargs grep -F default_off | wc -l`"
echo >&2 "Created ${XPI_NAME}-eff.xpi and ${XPI_NAME}-amo.xpi"
bash utils/android-push.sh "$XPI_NAME-eff.xpi"
if [ -n "$BRANCH" ]; then
cp $SUBDIR/${XPI_NAME}-eff.xpi $SUBDIR/${XPI_NAME}-amo.xpi pkg
rm -rf $SUBDIR
fi