diff options
author | tv <tv@krebsco.de> | 2021-01-03 14:51:29 +0100 |
---|---|---|
committer | tv <tv@krebsco.de> | 2021-01-03 15:49:23 +0100 |
commit | e38bde2eeb31b86746cd2b243f94622ddbd8cd2d (patch) | |
tree | a94affb0e5d2dca52886d1222ae27d694fa65be9 | |
parent | dc47cb298e2d496ca9c6117d24c3ffcce4465a62 (diff) |
crxmake: use tmpdir and explicit output path
-rwxr-xr-x | crxmake | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -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" |