65 lines
2.1 KiB
Bash
Executable File
65 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Unpack pinned Chromium builds of uBlock Origin Lite and Dark Reader into the
|
|
# Jarvis browser state directory. The helper loads these on the next start.
|
|
set -euo pipefail
|
|
|
|
UBOL_VERSION="${JARVIS_UBOL_VERSION:-2026.825.1619}"
|
|
DARK_READER_VERSION="${JARVIS_DARK_READER_VERSION:-4.9.129}"
|
|
ROOT="${JARVIS_BROWSER_EXTENSIONS:-${XDG_STATE_HOME:-$HOME/.local/state}/jarvis/browser/extensions}"
|
|
UBOL_URL="https://github.com/uBlockOrigin/uBOL-home/releases/download/${UBOL_VERSION}/uBOLite_${UBOL_VERSION}.chromium.zip"
|
|
DARK_READER_URL="https://github.com/darkreader/darkreader/releases/download/v${DARK_READER_VERSION}/darkreader-chrome-mv3.zip"
|
|
|
|
manifest_version() {
|
|
local file="$1"
|
|
[[ -f "$file" ]] || return 1
|
|
python3 - "$file" << 'PY'
|
|
import json, sys
|
|
try:
|
|
print(json.load(open(sys.argv[1], encoding="utf-8")).get("version", ""))
|
|
except Exception:
|
|
raise SystemExit(1)
|
|
PY
|
|
}
|
|
|
|
install_zip() {
|
|
local name="$1" url="$2" version="$3" dest="$4"
|
|
local current=""
|
|
current="$(manifest_version "${dest}/manifest.json" || true)"
|
|
if [[ "$current" == "$version" ]]; then
|
|
echo "${name} ${version} already installed"
|
|
return 0
|
|
fi
|
|
local tmp
|
|
tmp="$(mktemp -d)"
|
|
trap 'rm -rf "$tmp"' RETURN
|
|
echo "downloading ${name} ${version}"
|
|
curl -fsSL -o "${tmp}/ext.zip" "$url"
|
|
rm -rf "${tmp}/unpack"
|
|
mkdir -p "${tmp}/unpack"
|
|
unzip -q "${tmp}/ext.zip" -d "${tmp}/unpack"
|
|
local manifest
|
|
manifest="$(find "${tmp}/unpack" -name manifest.json -print -quit)"
|
|
if [[ -z "$manifest" ]]; then
|
|
echo "error: ${name} archive has no manifest.json" >&2
|
|
exit 1
|
|
fi
|
|
local src
|
|
src="$(dirname "$manifest")"
|
|
local got
|
|
got="$(manifest_version "${src}/manifest.json")"
|
|
if [[ "$got" != "$version" ]]; then
|
|
echo "error: ${name} archive version ${got} does not match ${version}" >&2
|
|
exit 1
|
|
fi
|
|
rm -rf "$dest"
|
|
mkdir -p "$(dirname "$dest")"
|
|
mv "$src" "$dest"
|
|
echo "installed ${name} ${version} at ${dest}"
|
|
rm -rf "$tmp"
|
|
trap - RETURN
|
|
}
|
|
|
|
mkdir -p "$ROOT"
|
|
install_zip "uBlock Origin Lite" "$UBOL_URL" "$UBOL_VERSION" "${ROOT}/ublock-origin-lite"
|
|
install_zip "Dark Reader" "$DARK_READER_URL" "$DARK_READER_VERSION" "${ROOT}/dark-reader"
|