2022-09-06 11:47:52 -06:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# This script assumes a linux environment
|
|
|
|
|
|
|
|
set -e
|
2023-09-09 07:47:38 -06:00
|
|
|
shopt -s extglob
|
2022-09-06 11:47:52 -06:00
|
|
|
|
2022-09-19 09:08:34 -06:00
|
|
|
echo "*** uBOLite.mv3: Creating extension"
|
2022-09-06 11:47:52 -06:00
|
|
|
|
2023-04-07 08:19:43 -06:00
|
|
|
PLATFORM="chromium"
|
2022-09-07 08:15:36 -06:00
|
|
|
|
2023-04-07 08:19:43 -06:00
|
|
|
for i in "$@"; do
|
|
|
|
case $i in
|
|
|
|
quick)
|
|
|
|
QUICK="yes"
|
|
|
|
;;
|
2023-04-07 11:24:57 -06:00
|
|
|
full)
|
|
|
|
FULL="yes"
|
|
|
|
;;
|
2023-04-07 08:19:43 -06:00
|
|
|
firefox)
|
|
|
|
PLATFORM="firefox"
|
|
|
|
;;
|
|
|
|
chromium)
|
|
|
|
PLATFORM="chromium"
|
|
|
|
;;
|
2024-02-14 12:27:36 -07:00
|
|
|
uBOLite_+([0-9]).+([0-9]).+([0-9]).+([0-9]))
|
2023-09-09 07:47:38 -06:00
|
|
|
TAGNAME="$i"
|
|
|
|
FULL="yes"
|
|
|
|
;;
|
2024-03-11 20:22:57 -06:00
|
|
|
before=+([[:print:]]))
|
2024-02-14 12:27:36 -07:00
|
|
|
BEFORE="${i:7}"
|
|
|
|
;;
|
2023-04-07 08:19:43 -06:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2024-03-11 20:22:57 -06:00
|
|
|
echo "PLATFORM=$PLATFORM"
|
|
|
|
echo "TAGNAME=$TAGNAME"
|
|
|
|
echo "BEFORE=$BEFORE"
|
|
|
|
|
2023-04-07 08:19:43 -06:00
|
|
|
DES="dist/build/uBOLite.$PLATFORM"
|
|
|
|
|
|
|
|
if [ "$QUICK" != "yes" ]; then
|
2022-09-07 08:15:36 -06:00
|
|
|
rm -rf $DES
|
|
|
|
fi
|
|
|
|
|
2022-09-06 11:47:52 -06:00
|
|
|
mkdir -p $DES
|
|
|
|
cd $DES
|
|
|
|
DES=$(pwd)
|
|
|
|
cd - > /dev/null
|
|
|
|
|
2024-02-14 12:27:36 -07:00
|
|
|
mkdir -p "$DES"/css/fonts
|
|
|
|
mkdir -p "$DES"/js
|
|
|
|
mkdir -p "$DES"/img
|
2022-09-06 11:47:52 -06:00
|
|
|
|
2023-08-25 09:17:15 -06:00
|
|
|
if [ -n "$UBO_VERSION" ]; then
|
2023-08-11 11:22:25 -06:00
|
|
|
UBO_REPO="https://github.com/gorhill/uBlock.git"
|
|
|
|
UBO_DIR=$(mktemp -d)
|
|
|
|
echo "*** uBOLite.mv3: Fetching uBO $UBO_VERSION from $UBO_REPO into $UBO_DIR"
|
2023-08-19 06:50:20 -06:00
|
|
|
cd "$UBO_DIR"
|
|
|
|
git init -q
|
|
|
|
git remote add origin "https://github.com/gorhill/uBlock.git"
|
|
|
|
git fetch --depth 1 origin "$UBO_VERSION"
|
|
|
|
git checkout -q FETCH_HEAD
|
2023-08-19 07:15:15 -06:00
|
|
|
cd - > /dev/null
|
2023-08-11 11:22:25 -06:00
|
|
|
else
|
|
|
|
UBO_DIR=.
|
|
|
|
fi
|
2023-08-10 11:08:15 -06:00
|
|
|
|
2022-09-19 09:08:34 -06:00
|
|
|
echo "*** uBOLite.mv3: Copying common files"
|
2024-02-14 12:27:36 -07:00
|
|
|
cp -R "$UBO_DIR"/src/css/fonts/* "$DES"/css/fonts/
|
|
|
|
cp "$UBO_DIR"/src/css/themes/default.css "$DES"/css/
|
|
|
|
cp "$UBO_DIR"/src/css/common.css "$DES"/css/
|
|
|
|
cp "$UBO_DIR"/src/css/dashboard-common.css "$DES"/css/
|
|
|
|
cp "$UBO_DIR"/src/css/fa-icons.css "$DES"/css/
|
2022-09-13 15:44:24 -06:00
|
|
|
|
2024-02-14 12:27:36 -07:00
|
|
|
cp "$UBO_DIR"/src/js/dom.js "$DES"/js/
|
|
|
|
cp "$UBO_DIR"/src/js/fa-icons.js "$DES"/js/
|
|
|
|
cp "$UBO_DIR"/src/js/i18n.js "$DES"/js/
|
|
|
|
cp "$UBO_DIR"/src/lib/punycode.js "$DES"/js/
|
2022-09-07 08:15:36 -06:00
|
|
|
|
2024-02-14 12:27:36 -07:00
|
|
|
cp -R "$UBO_DIR/src/img/flags-of-the-world" "$DES"/img
|
2023-06-11 07:20:10 -06:00
|
|
|
|
2024-02-14 12:27:36 -07:00
|
|
|
cp LICENSE.txt "$DES"/
|
2022-09-06 11:47:52 -06:00
|
|
|
|
2022-09-19 09:08:34 -06:00
|
|
|
echo "*** uBOLite.mv3: Copying mv3-specific files"
|
2023-04-07 08:19:43 -06:00
|
|
|
if [ "$PLATFORM" = "firefox" ]; then
|
2024-02-14 12:27:36 -07:00
|
|
|
cp platform/mv3/firefox/background.html "$DES"/
|
2023-04-07 08:19:43 -06:00
|
|
|
fi
|
2024-02-14 12:27:36 -07:00
|
|
|
cp platform/mv3/extension/*.html "$DES"/
|
|
|
|
cp platform/mv3/extension/*.json "$DES"/
|
|
|
|
cp platform/mv3/extension/css/* "$DES"/css/
|
|
|
|
cp -R platform/mv3/extension/js/* "$DES"/js/
|
|
|
|
cp platform/mv3/extension/img/* "$DES"/img/
|
|
|
|
cp -R platform/mv3/extension/_locales "$DES"/
|
|
|
|
cp platform/mv3/README.md "$DES/"
|
2022-09-07 08:15:36 -06:00
|
|
|
|
2023-04-07 08:19:43 -06:00
|
|
|
if [ "$QUICK" != "yes" ]; then
|
2022-09-19 09:08:34 -06:00
|
|
|
echo "*** uBOLite.mv3: Generating rulesets"
|
2022-09-07 08:15:36 -06:00
|
|
|
TMPDIR=$(mktemp -d)
|
2024-02-14 12:27:36 -07:00
|
|
|
mkdir -p "$TMPDIR"
|
2023-04-07 08:19:43 -06:00
|
|
|
if [ "$PLATFORM" = "chromium" ]; then
|
2024-02-14 12:27:36 -07:00
|
|
|
cp platform/mv3/chromium/manifest.json "$DES"/
|
2023-04-07 08:19:43 -06:00
|
|
|
elif [ "$PLATFORM" = "firefox" ]; then
|
2024-02-14 12:27:36 -07:00
|
|
|
cp platform/mv3/firefox/manifest.json "$DES"/
|
|
|
|
fi
|
|
|
|
./tools/make-nodejs.sh "$TMPDIR"
|
|
|
|
cp platform/mv3/package.json "$TMPDIR"/
|
|
|
|
cp platform/mv3/*.js "$TMPDIR"/
|
|
|
|
cp platform/mv3/*.mjs "$TMPDIR"/
|
|
|
|
cp platform/mv3/extension/js/utils.js "$TMPDIR"/js/
|
2024-11-17 15:27:27 -07:00
|
|
|
cp "$UBO_DIR"/assets/assets.dev.json "$TMPDIR"/
|
2024-10-25 17:12:08 -06:00
|
|
|
cp "$UBO_DIR"/assets/resources/*.js "$TMPDIR"/
|
2024-02-14 12:27:36 -07:00
|
|
|
cp -R platform/mv3/scriptlets "$TMPDIR"/
|
|
|
|
mkdir -p "$TMPDIR"/web_accessible_resources
|
|
|
|
cp "$UBO_DIR"/src/web_accessible_resources/* "$TMPDIR"/web_accessible_resources/
|
|
|
|
cd "$TMPDIR"
|
|
|
|
node --no-warnings make-rulesets.js output="$DES" platform="$PLATFORM"
|
2024-03-11 20:22:57 -06:00
|
|
|
if [ -n "$BEFORE" ]; then
|
|
|
|
echo "*** uBOLite.mv3: salvaging rule ids to minimize diff size"
|
|
|
|
echo " before=$BEFORE/$PLATFORM"
|
|
|
|
echo " after=$DES"
|
|
|
|
node salvage-ruleids.mjs before="$BEFORE"/"$PLATFORM" after="$DES"
|
|
|
|
fi
|
2022-09-07 08:15:36 -06:00
|
|
|
cd - > /dev/null
|
2024-02-14 12:27:36 -07:00
|
|
|
rm -rf "$TMPDIR"
|
2022-09-07 08:15:36 -06:00
|
|
|
fi
|
2022-09-06 11:47:52 -06:00
|
|
|
|
2022-09-19 09:08:34 -06:00
|
|
|
echo "*** uBOLite.mv3: extension ready"
|
2022-09-06 11:47:52 -06:00
|
|
|
echo "Extension location: $DES/"
|
|
|
|
|
2024-07-29 12:54:46 -06:00
|
|
|
# Local build
|
|
|
|
if [ -z "$TAGNAME" ]; then
|
|
|
|
# Enable DNR rule debugging
|
2024-03-06 10:46:12 -07:00
|
|
|
tmp=$(mktemp)
|
2024-07-29 12:54:46 -06:00
|
|
|
jq '.permissions += ["declarativeNetRequestFeedback"]' \
|
|
|
|
"$DES/manifest.json" > "$tmp" \
|
2024-03-06 10:46:12 -07:00
|
|
|
&& mv "$tmp" "$DES/manifest.json"
|
2024-07-29 12:54:46 -06:00
|
|
|
# Use a different extension id than the official one
|
|
|
|
if [ "$PLATFORM" = "firefox" ]; then
|
|
|
|
tmp=$(mktemp)
|
|
|
|
jq '.browser_specific_settings.gecko.id = "uBOLite.dev@raymondhill.net"' "$DES/manifest.json" > "$tmp" \
|
|
|
|
&& mv "$tmp" "$DES/manifest.json"
|
|
|
|
fi
|
2024-03-06 10:46:12 -07:00
|
|
|
fi
|
|
|
|
|
2023-04-07 11:24:57 -06:00
|
|
|
if [ "$FULL" = "yes" ]; then
|
2023-04-07 11:34:27 -06:00
|
|
|
EXTENSION="zip"
|
|
|
|
if [ "$PLATFORM" = "firefox" ]; then
|
|
|
|
EXTENSION="xpi"
|
|
|
|
fi
|
2023-04-07 11:24:57 -06:00
|
|
|
echo "*** uBOLite.mv3: Creating publishable package..."
|
2023-09-09 07:47:38 -06:00
|
|
|
if [ -z "$TAGNAME" ]; then
|
2024-02-14 12:27:36 -07:00
|
|
|
TAGNAME="uBOLite_$(jq -r .version "$DES"/manifest.json)"
|
2023-09-09 07:47:38 -06:00
|
|
|
else
|
|
|
|
tmp=$(mktemp)
|
2023-09-10 12:24:29 -06:00
|
|
|
jq --arg version "${TAGNAME:8}" '.version = $version' "$DES/manifest.json" > "$tmp" \
|
2023-09-09 07:47:38 -06:00
|
|
|
&& mv "$tmp" "$DES/manifest.json"
|
|
|
|
fi
|
|
|
|
PACKAGENAME="$TAGNAME.$PLATFORM.mv3.$EXTENSION"
|
2022-09-07 08:23:40 -06:00
|
|
|
TMPDIR=$(mktemp -d)
|
2024-02-14 12:27:36 -07:00
|
|
|
mkdir -p "$TMPDIR"
|
|
|
|
cp -R "$DES"/* "$TMPDIR"/
|
|
|
|
cd "$TMPDIR" > /dev/null
|
2024-11-20 10:55:13 -07:00
|
|
|
rm -f ./log.txt
|
2024-02-14 12:27:36 -07:00
|
|
|
zip "$PACKAGENAME" -qr ./*
|
2022-09-07 08:23:40 -06:00
|
|
|
cd - > /dev/null
|
2024-02-14 12:27:36 -07:00
|
|
|
cp "$TMPDIR"/"$PACKAGENAME" dist/build/
|
|
|
|
rm -rf "$TMPDIR"
|
2022-09-08 09:21:39 -06:00
|
|
|
echo "Package location: $(pwd)/dist/build/$PACKAGENAME"
|
2022-09-07 08:23:40 -06:00
|
|
|
fi
|