aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2021-01-04 16:49:43 +0100
committertv <tv@krebsco.de>2021-01-14 23:33:18 +0100
commitfa6a59e303d9290bd293bd0dbc8997d31bc387fc (patch)
tree4e74b29916a0de7e7e69913099d7d5ce3282bc7f
parented69f746a38f00a8d2eec90057ff8cc247df4dd6 (diff)
add build-crx.sh and install-crx.sh
-rwxr-xr-xbuild-crx.sh56
-rwxr-xr-xinstall-crx.sh26
2 files changed, 82 insertions, 0 deletions
diff --git a/build-crx.sh b/build-crx.sh
new file mode 100755
index 0000000..ad0460e
--- /dev/null
+++ b/build-crx.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+# usage: ./build-crx.sh [--generate-key] [OUTPUT_DIR [TABFS_SOURCE_DIR]]
+set -efu
+
+# TODO keep in sync with ./install-crx.sh
+source_dir=${2-$(dirname "$0")}
+out_dir=${1-$source_dir/out}
+crx_file=$out_dir/TabFS.crx
+update_file=$out_dir/TabFS.xml
+policy_file=$out_dir/TabFS.json
+
+# TODO keep in sync with system_extensions_dir and system_update_dir in
+# ./install-crx.sh
+crx_url=file:///etc/chromium/extensions/TabFS.crx
+update_url=file:///etc/chromium/extensions/TabFS.xml
+
+key_file=$out_dir/TabFS.pem
+key_size=2048
+
+
+mkdir -p "$out_dir"
+
+if ! test -e "$key_file" || printf %s $* | grep -q -- '--generate-key\>'; then
+ openssl genrsa -out "$key_file" "$key_size"
+fi
+
+ext_dir=$source_dir/extension
+
+crxmake "$ext_dir" "$key_file" "$crx_file"
+
+appid=$(crxid "$key_file")
+version=$(jq -r .version "$ext_dir"/manifest.json)
+
+cat > "$update_file" <<EOF
+<?xml version='1.0' encoding='UTF-8'?>
+<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
+ <app appid='$appid'>
+ <updatecheck codebase='$crx_url' version='$version' />
+ </app>
+</gupdate>
+EOF
+
+jq > "$policy_file" \
+--null-input \
+--arg appid "$appid" \
+--arg update_url "$update_url" \
+'
+{
+ ExtensionSettings: {
+ "\($appid)": {
+ installation_mode: "normal_installed",
+ $update_url
+ }
+ }
+}
+'
diff --git a/install-crx.sh b/install-crx.sh
new file mode 100755
index 0000000..bb3cbcf
--- /dev/null
+++ b/install-crx.sh
@@ -0,0 +1,26 @@
+#! /bin/sh
+# usage: sudo ./install-crx.sh [OUTPUT_DIR]
+set -efu
+
+# TODO keep in sync with ./build-crx.sh
+out_dir=${1-$(dirname "$0")}
+crx_file=$out_dir/TabFS.crx
+update_file=$out_dir/TabFS.xml
+policy_file=$out_dir/TabFS.json
+
+# TODO keep in sync with crx_url and update_url n ./build-crx.sh
+system_extensions_dir=/etc/chromium/extensions
+system_update_dir=/etc/chromium/extensions
+system_policies_dir=/etc/chromium/policies/managed
+
+
+mkdir -p "$system_extensions_dir"
+mkdir -p "$system_update_dir"
+mkdir -p "$system_policies_dir"
+
+cp "$crx_file" "$system_extensions_dir"
+cp "$update_file" "$system_update_dir"
+
+# Remove existing policy to force reloading the extensions
+rm -f "$system_policies_dir"/TabFS.json
+cp "$policy_file" "$system_policies_dir"/TabFS.json