function installExtension -d "Installs a Chromium extension for the browser with the specified information" -a name dir bin policyDir extensionDir [ -n "$bin" ] or set -l bin "google-chrome-stable" [ -n "$policyDir" ] or set -l policyDir "/opt/google/chrome/extensions" [ -n "$extensionDir" ] or set -l extensionDir "/usr/local/share/chromium-extensions" set -l keyFile "$dir.pem" set -l extensionFile "$dir.crx" set -l manifestFile "$dir/manifest.json" set -l destination "$extensionDir/$name.crx" rm "$keyFile" &> /dev/null $bin --pack-extension="$dir" # Tamper manifest file begin set -l manifest (cat "$manifestFile" | KEY=(openssl rsa -in "$keyFile" -pubout -outform DER | openssl base64 -A) jq ". + { key: env.KEY }") echo "$manifest" > "$manifestFile" $bin --pack-extension="$dir" --pack-extension-key="$keyFile" end set -l id (openssl rsa -in "$keyFile" -pubout -outform DER | sha256sum | head -c32 | tr 0-9a-f a-p) set -l extVersion (cat "$manifestFile" | jq -r ".version") # Install and configure extension begin set -l property "external_crx" sudo mkdir -p "$extensionDir" sudo cp "$extensionFile" "$destination" sudo chmod -R a+rx "$extensionDir" sudo chmod -R u+w "$extensionDir" sudo mkdir -p "$policyDir" for manifest in (find "$policyDir" -name "*.json" -print0 | string split0) if [ (cat "$manifest" | jq -r ".$property") = "$destination" ] sudo rm "$manifest" end end begin echo "null" | \ FILE="$destination" \ VERSION="$extVersion" \ jq '{ external_crx: env.FILE, external_version: env.VERSION }' end | sudo tee "$policyDir/$id.json" > /dev/null end end