summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2021-01-03 14:51:29 +0100
committertv <tv@krebsco.de>2021-01-03 15:49:23 +0100
commite38bde2eeb31b86746cd2b243f94622ddbd8cd2d (patch)
treea94affb0e5d2dca52886d1222ae27d694fa65be9
parentdc47cb298e2d496ca9c6117d24c3ffcce4465a62 (diff)
crxmake: use tmpdir and explicit output path
-rwxr-xr-xcrxmake22
1 files changed, 14 insertions, 8 deletions
diff --git a/crxmake b/crxmake
index 11022b5..9418f83 100755
--- a/crxmake
+++ b/crxmake
@@ -1,11 +1,13 @@
#! /bin/sh
# Pack a Chromium extension directory into CRX3 format
-# usage: crxmake EXTENSION_DIR KEY_FILE
+# usage: crxmake EXTENSION_DIR KEY_FILE OUT_FILE
set -efu
-dir=$1
-key=$2
+dir=$(realpath "$1")
+key=$(realpath "$2")
+out=$(realpath "$3")
+
name=$(basename "$dir")
crx="$name.crx"
pub="$name.pub"
@@ -13,16 +15,19 @@ sig="$name.sig"
zip="$name.zip"
tosign="$name.presig"
binary_crx_id="$name.crxid"
-trap 'rm -f "$pub" "$sig" "$zip" "$tosign" "$binary_crx_id"' EXIT
+workdir=$(mktemp -d -t crxmake.XXXXXXXX)
+oldworkdir=$PWD
+cd "$workdir"
+trap 'cd "$oldworkdir" && rm -fR "$workdir"' EXIT
# zip up the crx dir
-cwd=$(pwd -P)
-(cd "$dir" && zip -qr -9 -X "$cwd/$zip" .)
+(cd "$dir" && zip -qr -9 -X "$workdir/$zip" .)
#extract crx id
-openssl rsa -in "$key" -pubout -outform der | openssl dgst -sha256 -binary -out "$binary_crx_id"
+openssl rsa -in "$key" -pubout -outform der 2>/dev/null |
+openssl dgst -sha256 -binary -out "$binary_crx_id"
truncate -s 16 "$binary_crx_id"
#generate file to sign
@@ -54,4 +59,5 @@ header_chunk_3="82 F1 04 12 0A 10"
echo "$header_chunk_3" | xxd -r -p
cat "$binary_crx_id" "$zip"
) > "$crx"
-echo "Wrote $crx"
+
+mv "$crx" "$out"