2022-08-29 16:42:05 -06:00
|
|
|
#! /usr/bin/env bash
|
2021-06-18 16:21:23 -06:00
|
|
|
|
2023-02-22 15:17:12 -07:00
|
|
|
# Copyright (C) 2005-2023 Giorgio Maone <https://maone.net>
|
2021-06-18 16:21:23 -06:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2018-08-01 17:50:09 -06:00
|
|
|
BASE="$PWD"
|
2018-06-30 17:01:23 -06:00
|
|
|
SRC="$BASE/src"
|
|
|
|
BUILD="$BASE/build"
|
|
|
|
MANIFEST_IN="$SRC/manifest.json"
|
|
|
|
MANIFEST_OUT="$BUILD/manifest.json"
|
|
|
|
|
2019-10-01 14:27:13 -06:00
|
|
|
strip_rc_ver() {
|
|
|
|
MANIFEST="$1"
|
2020-03-16 12:11:54 -06:00
|
|
|
if [[ "$2" == "rel" ]]; then
|
2019-10-05 00:31:01 -06:00
|
|
|
replace='s/("version":.*)rc\d+/$1/'
|
|
|
|
else
|
2021-07-21 15:49:48 -06:00
|
|
|
replace='s/("version":.*?)(\d+)rc(\d+)/{$1 . ($2 == "0" ? "0" : ($2-1) . ".9" . sprintf("%03d", $3))}/e'
|
2019-10-05 00:31:01 -06:00
|
|
|
fi
|
|
|
|
perl -pi.bak -e "$replace" "$MANIFEST" && rm -f "$MANIFEST".bak
|
2019-10-01 14:27:13 -06:00
|
|
|
}
|
|
|
|
|
2018-07-08 06:05:04 -06:00
|
|
|
VER=$(grep '"version":' "$MANIFEST_IN" | sed -re 's/.*": "(.*?)".*/\1/')
|
2018-07-06 19:02:40 -06:00
|
|
|
if [ "$1" == "tag" ]; then
|
2024-07-25 03:07:21 -06:00
|
|
|
# ensure nscl is up-to-date git-wise
|
|
|
|
./nscl_gitsync.sh
|
|
|
|
|
2018-07-06 19:02:40 -06:00
|
|
|
echo "Tagging at $VER"
|
2020-10-04 16:20:49 -06:00
|
|
|
git tag -a "$VER" -e -m"$(gitcl 2>/dev/null)"
|
2024-07-16 03:38:46 -06:00
|
|
|
git push && git push origin "$VER"
|
2018-07-06 19:02:40 -06:00
|
|
|
exit 0
|
|
|
|
fi
|
2020-03-16 12:11:54 -06:00
|
|
|
if [[ "$1" =~ ^r(el(ease)?)?$ ]]; then
|
2019-10-05 00:31:01 -06:00
|
|
|
strip_rc_ver "$MANIFEST_IN" rel
|
2018-08-23 18:56:59 -06:00
|
|
|
"$0" && "$0" bump
|
|
|
|
exit
|
|
|
|
fi
|
2018-10-13 15:07:52 -06:00
|
|
|
|
|
|
|
if [[ "$1" == "bump" ]]; then
|
|
|
|
if [[ "$2" ]]; then
|
2018-08-25 16:37:52 -06:00
|
|
|
NEW_VER="$2"
|
|
|
|
if [[ "$2" == *.* ]]; then # full dotted version number
|
|
|
|
pattern='"\d+.*?'
|
|
|
|
NEW_VER='"'"$2"
|
|
|
|
elif [[ "$2" == *rc* ]]; then # new RC after release
|
|
|
|
if [[ "$2" == rc* ]]; then
|
2018-12-27 02:50:04 -07:00
|
|
|
if [[ ! "$VER" == *rc* ]]; then
|
|
|
|
echo >&2 "Please specify next release version (like 12rc1). Current is $VER"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
pattern='rc\d+'
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
pattern='\b(?:\d+rc)?\d+'
|
2018-08-25 16:37:52 -06:00
|
|
|
fi
|
|
|
|
else # incremental version
|
|
|
|
pattern='\b\d+'
|
|
|
|
fi
|
|
|
|
REPLACE_EXPR='s/(?<PREAMBLE>"version":.*)'"$pattern"'"/$+{PREAMBLE}'"$NEW_VER"'"/'
|
2018-10-12 14:34:42 -06:00
|
|
|
perl -pi.bak -e $REPLACE_EXPR "$MANIFEST_IN" && "$0" bump
|
|
|
|
rm -f "$MANIFEST_IN".bak
|
2018-08-25 16:37:52 -06:00
|
|
|
exit
|
|
|
|
fi
|
2018-07-08 06:05:04 -06:00
|
|
|
echo "Bumping to $VER"
|
|
|
|
git add "$MANIFEST_IN"
|
|
|
|
git commit -m "Version bump: $VER."
|
2024-08-07 13:52:34 -06:00
|
|
|
if ! [[ $VER == *rc* ]]; then
|
|
|
|
# it's a stable release: let's lock nscl and tag
|
|
|
|
git submodule update
|
|
|
|
"$0" tag
|
|
|
|
fi
|
2018-08-23 18:56:59 -06:00
|
|
|
exit
|
2018-07-08 06:05:04 -06:00
|
|
|
fi
|
2018-06-30 17:01:23 -06:00
|
|
|
XPI_DIR="$BASE/xpi"
|
|
|
|
XPI="$XPI_DIR/noscript-$VER"
|
|
|
|
LIB="$SRC/lib"
|
|
|
|
|
2021-02-13 13:17:20 -07:00
|
|
|
NSCL="$SRC/nscl"
|
2018-06-30 17:01:23 -06:00
|
|
|
|
2018-07-03 09:36:36 -06:00
|
|
|
rm -rf "$BUILD" "$XPI"
|
|
|
|
cp -pR "$SRC" "$BUILD"
|
2021-02-19 14:33:07 -07:00
|
|
|
|
|
|
|
# include nscl dependencies
|
|
|
|
"$NSCL/include.sh" "$BUILD"
|
2021-02-13 13:17:20 -07:00
|
|
|
|
2022-08-29 16:42:05 -06:00
|
|
|
cp -p LICENSE "$BUILD"/
|
2018-06-30 17:01:23 -06:00
|
|
|
|
2018-08-23 18:56:59 -06:00
|
|
|
BUILD_CMD="web-ext"
|
2020-01-09 13:41:03 -07:00
|
|
|
BUILD_OPTS="build --overwrite-dest"
|
2021-07-27 16:38:51 -06:00
|
|
|
CHROMIUM_BUILD_CMD="$BUILD_CMD"
|
|
|
|
CHROMIUM_BUILD_OPTS="$BUILD_OPTS"
|
2018-10-05 18:47:31 -06:00
|
|
|
|
2018-06-30 17:01:23 -06:00
|
|
|
if [[ $VER == *rc* ]]; then
|
|
|
|
sed -re 's/^(\s+)"strict_min_version":.*$/\1"update_url": "https:\/\/secure.informaction.com\/update\/?v='$VER'",\n\0/' \
|
|
|
|
"$MANIFEST_IN" > "$MANIFEST_OUT"
|
2018-10-13 15:07:52 -06:00
|
|
|
if [[ "$1" == "sign" ]]; then
|
2018-08-23 18:56:59 -06:00
|
|
|
BUILD_CMD="$BASE/../../we-sign"
|
|
|
|
BUILD_OPTS=""
|
|
|
|
fi
|
2018-06-30 17:01:23 -06:00
|
|
|
else
|
|
|
|
grep -v '"update_url":' "$MANIFEST_IN" > "$MANIFEST_OUT"
|
2018-10-13 15:07:52 -06:00
|
|
|
if [[ "$1" == "sign" ]]; then
|
2018-08-23 18:56:59 -06:00
|
|
|
echo >&2 "WARNING: won't auto-sign a release version, please manually upload to AMO."
|
|
|
|
fi
|
2018-06-30 17:01:23 -06:00
|
|
|
fi
|
|
|
|
if ! grep '"id":' "$MANIFEST_OUT" >/dev/null; then
|
|
|
|
echo >&2 "Cannot build manifest.json"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-10-01 14:27:13 -06:00
|
|
|
if [ "$1" != "debug" ]; then
|
2021-07-21 15:49:48 -06:00
|
|
|
DBG=""
|
2019-10-01 14:27:13 -06:00
|
|
|
for file in "$SRC"/content/*.js; do
|
|
|
|
if grep -P '\/\/\s(REL|DEV)_ONLY' "$file" >/dev/null; then
|
|
|
|
sed -re 's/\s*\/\/\s*(\S.*)\s*\/\/\s*REL_ONLY.*/\1/' -e 's/.*\/\/\s*DEV_ONLY.*//' "$file" > "$BUILD/content/$(basename "$file")"
|
|
|
|
fi
|
|
|
|
done
|
2021-07-21 15:49:48 -06:00
|
|
|
else
|
|
|
|
DBG="-dbg"
|
2019-10-01 14:27:13 -06:00
|
|
|
fi
|
2018-06-30 17:01:23 -06:00
|
|
|
|
|
|
|
echo "Creating $XPI.xpi..."
|
2018-07-03 09:36:36 -06:00
|
|
|
mkdir -p "$XPI_DIR"
|
2018-06-30 17:01:23 -06:00
|
|
|
|
2018-10-13 02:34:18 -06:00
|
|
|
if which cygpath; then
|
|
|
|
WEBEXT_IN="$(cygpath -w "$BUILD")"
|
|
|
|
WEBEXT_OUT="$(cygpath -w "$XPI_DIR")"
|
|
|
|
else
|
|
|
|
WEBEXT_IN="$BUILD"
|
|
|
|
WEBEXT_OUT="$XPI_DIR"
|
|
|
|
fi
|
|
|
|
|
2024-09-11 05:11:28 -06:00
|
|
|
COMMON_BUILD_OPTS="--ignore-files='test/**' 'embargoed/**' content/experiments.js"
|
2019-10-05 00:31:01 -06:00
|
|
|
|
2021-07-21 08:09:52 -06:00
|
|
|
build() {
|
|
|
|
"$BUILD_CMD" $BUILD_OPTS --source-dir="$WEBEXT_IN" --artifacts-dir="$WEBEXT_OUT" $COMMON_BUILD_OPTS
|
|
|
|
}
|
|
|
|
|
|
|
|
build
|
|
|
|
|
2022-03-28 04:39:14 -06:00
|
|
|
SIGNED="$XPI_DIR/noscript_security_suite-$VER-an+fx.xpi"
|
|
|
|
if [ -f "$SIGNED" ]; then
|
|
|
|
mv "$SIGNED" "$XPI.xpi"
|
|
|
|
elif [ -f "$XPI.zip" ]; then
|
|
|
|
SIGNED=""
|
|
|
|
if unzip -l "$XPI.xpi" | grep "META-INF/mozilla.rsa" >/dev/null 2>&1; then
|
|
|
|
echo "A signed $XPI.xpi already exists, not overwriting."
|
|
|
|
else
|
|
|
|
[[ "$VER" == *rc* ]] && xpicmd="mv" || xpicmd="cp"
|
|
|
|
$xpicmd "$XPI.zip" "$XPI$DBG.xpi"
|
|
|
|
echo "Created $XPI$DBG.xpi"
|
|
|
|
fi
|
2022-08-06 09:05:01 -06:00
|
|
|
elif ! [ -f "$XPI.xpi" ]; then
|
2022-03-28 04:39:14 -06:00
|
|
|
echo >&2 "ERROR: Could not create $XPI$DBG.xpi!"
|
|
|
|
exit 3
|
|
|
|
fi
|
2022-08-06 09:05:01 -06:00
|
|
|
ln -fs "$XPI.xpi" "$BASE/latest.xpi"
|
2022-03-28 04:39:14 -06:00
|
|
|
|
2021-05-17 04:59:15 -06:00
|
|
|
# create Chromium pre-release
|
2021-07-21 08:09:52 -06:00
|
|
|
|
2021-07-27 16:38:51 -06:00
|
|
|
BUILD_CMD="$CHROMIUM_BUILD_CMD"
|
|
|
|
BUILD_OPTS="$CHROMIUM_BUILD_OPTS"
|
2021-07-21 08:09:52 -06:00
|
|
|
CHROMIUM_UNPACKED="$BASE/chromium"
|
|
|
|
EDGE_UPDATE_URL="https://edge.microsoft.com/extensionwebstorebase/v1/crx"
|
|
|
|
rm -rf "$CHROMIUM_UNPACKED"
|
2019-10-01 14:27:13 -06:00
|
|
|
strip_rc_ver "$MANIFEST_OUT"
|
2021-07-27 16:38:51 -06:00
|
|
|
|
2021-05-17 04:59:15 -06:00
|
|
|
# manifest.json patching for Chromium:
|
2021-07-21 08:09:52 -06:00
|
|
|
|
|
|
|
EXTRA_PERMS=""
|
|
|
|
if grep 'patchWorkers.js' "$MANIFEST_OUT" >/dev/null 2>&1; then
|
|
|
|
EXTRA_PERMS='"debugger",'
|
|
|
|
fi
|
|
|
|
|
2021-05-17 04:59:15 -06:00
|
|
|
# skip "application" manifest key
|
2020-01-09 13:41:03 -07:00
|
|
|
(grep -B1000 '"name": "NoScript"' "$MANIFEST_OUT"; \
|
2021-07-21 08:09:52 -06:00
|
|
|
grep -A2000 '"version":' "$MANIFEST_OUT") | \
|
|
|
|
# auto-update URL for the Edge version on the Microsoft Store
|
|
|
|
sed -e '/"name":/a\' -e ' "update_url": "'$EDGE_UPDATE_URL'",' | \
|
2022-02-17 13:43:54 -07:00
|
|
|
# skip embeddingDocument.js and dns permission
|
|
|
|
grep -Pv 'content/embeddingDocument.js|"dns",' | \
|
2021-05-17 04:59:15 -06:00
|
|
|
# add "debugger" permission for patchWorkers.js
|
2021-07-21 08:09:52 -06:00
|
|
|
sed -re 's/( *)"webRequestBlocking",/&\n\1'"$EXTRA_PERMS"'/' | \
|
2021-05-17 04:59:15 -06:00
|
|
|
# add origin fallback for content scripts
|
|
|
|
sed -re 's/( *)"match_about_blank": *true/\1"match_origin_as_fallback": true,\n&/' > \
|
|
|
|
"$MANIFEST_OUT".tmp && \
|
2020-01-09 13:41:03 -07:00
|
|
|
mv "$MANIFEST_OUT.tmp" "$MANIFEST_OUT"
|
2021-07-21 08:09:52 -06:00
|
|
|
|
2021-07-21 15:49:48 -06:00
|
|
|
CHROME_ZIP=$(build | grep 'ready: .*\.zip' | sed -re 's/.* ready: //')
|
2021-07-21 08:09:52 -06:00
|
|
|
|
2021-07-21 15:49:48 -06:00
|
|
|
if [ -f "$CHROME_ZIP" ]; then
|
|
|
|
mv "$CHROME_ZIP" "$XPI$DBG-edge.zip"
|
2021-07-21 08:09:52 -06:00
|
|
|
# remove Edge-specific manifest lines and package for generic Chromium
|
|
|
|
grep -v '"update_url":' "$MANIFEST_OUT" > "$MANIFEST_OUT.tmp" && \
|
|
|
|
mv "$MANIFEST_OUT.tmp" "$MANIFEST_OUT" && \
|
|
|
|
build
|
2021-07-21 15:49:48 -06:00
|
|
|
mv "$CHROME_ZIP" "$XPI$DBG-chrome.zip"
|
2021-07-21 08:09:52 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
mv "$BUILD" "$CHROMIUM_UNPACKED"
|
2022-03-28 02:31:36 -06:00
|
|
|
|
2022-03-28 04:39:14 -06:00
|
|
|
if [ "$SIGNED" ]; then
|
2024-07-16 03:38:46 -06:00
|
|
|
"$0" tag
|
|
|
|
nscl
|
2022-03-28 02:31:36 -06:00
|
|
|
../../we-publish "$XPI.xpi"
|
2024-07-16 03:38:46 -06:00
|
|
|
fi
|