|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Build an HTTPS Everywhere Opera CRX Distribution |
| 4 | +# Written for transparency and reproducibility on Opera upload |
| 5 | +# See browser-dist.md for more info |
| 6 | + |
| 7 | +# To build the current state of the tree: |
| 8 | +# |
| 9 | +# ./browser-dist-opera.sh |
| 10 | +# |
| 11 | +# To build a particular tagged release: |
| 12 | +# |
| 13 | +# ./browser-dist-opera.sh <version number> |
| 14 | +# |
| 15 | +# eg: |
| 16 | +# |
| 17 | +# ./browser-dist-opera.sh 2017.8.15 |
| 18 | +# |
| 19 | +# Note that .crx files must be signed; this script makes you a |
| 20 | +# "dummy-chromium.pem" private key for you to sign your own local releases, |
| 21 | +# but these .crx files won't detect and upgrade to official HTTPS Everywhere |
| 22 | +# releases signed by EFF :/. We should find a more elegant arrangement. |
| 23 | + |
| 24 | +! getopt --test > /dev/null |
| 25 | +if [[ ${PIPESTATUS[0]} -ne 4 ]]; then |
| 26 | + echo 'I’m sorry, `getopt --test` failed in this environment.' |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +OPTIONS=eck: |
| 31 | +LONGOPTS=remove-extension-update,remove-update-channels,key: |
| 32 | +! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@") |
| 33 | +if [[ ${PIPESTATUS[0]} -ne 0 ]]; then |
| 34 | + # e.g. return value is 1 |
| 35 | + # then getopt has complained about wrong arguments to stdout |
| 36 | + exit 2 |
| 37 | +fi |
| 38 | + |
| 39 | +# read getopt’s output this way to handle the quoting right: |
| 40 | +eval set -- "$PARSED" |
| 41 | + |
| 42 | +REMOVE_EXTENSION_UPDATE=false |
| 43 | +REMOVE_UPDATE_CHANNELS=false |
| 44 | +KEY=$(pwd)/dummy-chromium.pem |
| 45 | +while true; do |
| 46 | + case "$1" in |
| 47 | + -e|--remove-extension-update) |
| 48 | + REMOVE_EXTENSION_UPDATE=true |
| 49 | + shift |
| 50 | + ;; |
| 51 | + -c|--remove-update-channels) |
| 52 | + REMOVE_UPDATE_CHANNELS=true |
| 53 | + shift |
| 54 | + ;; |
| 55 | + -k|--key) |
| 56 | + KEY="$2" |
| 57 | + shift 2 |
| 58 | + ;; |
| 59 | + --) |
| 60 | + shift |
| 61 | + break |
| 62 | + ;; |
| 63 | + *) |
| 64 | + echo "Programming error" |
| 65 | + exit 3 |
| 66 | + ;; |
| 67 | + esac |
| 68 | +done |
| 69 | + |
| 70 | +if [ "${KEY:0:1}" != "/" ]; then |
| 71 | + echo "Key must be specified as an absolute path." |
| 72 | + exit 4 |
| 73 | +fi |
| 74 | + |
| 75 | +cd $(dirname $0) |
| 76 | + |
| 77 | +if [ -n "$1" ]; then |
| 78 | + BRANCH=`git branch | head -n 1 | cut -d \ -f 2-` |
| 79 | + SUBDIR=checkout |
| 80 | + [ -d $SUBDIR ] || mkdir $SUBDIR |
| 81 | + cp -r -f -a .git $SUBDIR |
| 82 | + cd $SUBDIR |
| 83 | + git reset --hard "$1" |
| 84 | + git submodule update --recursive -f |
| 85 | +fi |
| 86 | + |
| 87 | +VERSION=`python3.6 -c "import json ; print(json.loads(open('../chromium/manifest.json').read())['version'])"` |
| 88 | + |
| 89 | +echo "Building version" $VERSION |
| 90 | + |
| 91 | +[ -d pkg ] || mkdir -p ../pkg |
| 92 | +[ -e pkg/crx-opera ] && rm -rf ../pkg/crx-opera |
| 93 | + |
| 94 | +# Clean up obsolete ruleset databases, just in case they still exist. |
| 95 | +rm -f src/chrome/content/rules/default.rulesets src/defaults/rulesets.sqlite |
| 96 | + |
| 97 | +mkdir -p ../pkg/crx-opera/rules |
| 98 | +cd ../pkg/crx-opera |
| 99 | +cp -a ../../chromium/* ./ |
| 100 | +# Turn the Firefox translations into the appropriate Chrome format: |
| 101 | +rm -rf _locales/ |
| 102 | +mkdir _locales/ |
| 103 | +python3.6 ../../utils/chromium-translations.py ../../translations/ _locales/ |
| 104 | +python3.6 ../../utils/chromium-translations.py ../../src/chrome/locale/ _locales/ |
| 105 | +do_not_ship="*.py *.xml" |
| 106 | +rm -f $do_not_ship |
| 107 | + |
| 108 | +mkdir wasm |
| 109 | +cp ../../lib-wasm/pkg/*.wasm wasm |
| 110 | +cp ../../lib-wasm/pkg/*.js wasm |
| 111 | + |
| 112 | +cd ../.. |
| 113 | + |
| 114 | +python3.6 ./utils/merge-rulesets.py || exit 5 |
| 115 | + |
| 116 | +cp src/chrome/content/rules/default.rulesets.json pkg/crx-opera/rules/default.rulesets.json |
| 117 | + |
| 118 | +sed -i -e "s/VERSION/$VERSION/g" pkg/crx-opera/manifest.json |
| 119 | + |
| 120 | +for x in `cat .build_exclusions`; do |
| 121 | + rm -rf pkg/crx-opera/$x |
| 122 | +done |
| 123 | + |
| 124 | +#Create Opera CRX caveat |
| 125 | +cd pkg/crx-opera |
| 126 | +sed -i 's/rules\/default.rulesets/rules\/default.rulesets.json/g' background-scripts/update.js |
| 127 | +cd ../.. |
| 128 | + |
| 129 | +# Remove the 'applications' manifest key from the crx version of the extension, change the 'author' string to a hash, and add the "update_url" manifest key |
| 130 | +# "update_url" needs to be present to avoid problems reported in https://bugs.chromium.org/p/chromium/issues/detail?id=805755 |
| 131 | +python3.6 -c "import json; m=json.loads(open('pkg/crx-opera/manifest.json').read()); m['author']={'email': '[email protected]'}; del m['applications']; open('pkg/crx-opera/manifest.json','w').write(json.dumps(m,indent=4,sort_keys=True))" |
| 132 | + |
| 133 | +# If the --remove-update-channels flag is set, remove all out-of-band update channels |
| 134 | +if $REMOVE_UPDATE_CHANNELS; then |
| 135 | + echo "Flag --remove-update-channels specified. Removing all out-of-band update channels." |
| 136 | + echo "require.scopes.update_channels.update_channels = [];" >> pkg/crx-opera/background-scripts/update_channels.js |
| 137 | +fi |
| 138 | + |
| 139 | +if [ -n "$BRANCH" ] ; then |
| 140 | + crx_opera="pkg/https-everywhere-$VERSION-opera.crx" |
| 141 | +else |
| 142 | + crx_opera="pkg/https-everywhere-$VERSION-pre-opera.crx" |
| 143 | +fi |
| 144 | +if ! [ -f "$KEY" ] ; then |
| 145 | + echo "Making a dummy signing key for local build purposes" |
| 146 | + openssl genrsa -out /tmp/dummy-chromium.pem 768 |
| 147 | + openssl pkcs8 -topk8 -nocrypt -in /tmp/dummy-chromium.pem -out $KEY |
| 148 | +fi |
| 149 | + |
| 150 | +# now pack the crx'es |
| 151 | +BROWSER="chromium-browser" |
| 152 | +which $BROWSER || BROWSER="chromium" |
| 153 | + |
| 154 | +$BROWSER --no-message-box --pack-extension="pkg/crx-opera" --pack-extension-key="$KEY" 2> /dev/null |
| 155 | + |
| 156 | +mv pkg/crx-opera.crx $crx_opera |
| 157 | + |
| 158 | +echo >&2 "Opera crx package has sha256sum: `openssl dgst -sha256 -binary "$crx_opera" | xxd -p`" |
| 159 | +echo >&2 "Total included rules: `find src/chrome/content/rules -name "*.xml" | wc -l`" |
| 160 | +echo >&2 "Rules disabled by default: `find src/chrome/content/rules -name "*.xml" | xargs grep -F default_off | wc -l`" |
| 161 | + |
| 162 | +echo "Created $crx_opera" |
| 163 | + |
| 164 | +if [ -n "$BRANCH" ]; then |
| 165 | + cd .. |
| 166 | + cp $SUBDIR/$crx_opera pkg |
| 167 | + rm -rf $SUBDIR |
| 168 | +fi |
0 commit comments