contrib/sign.sh: various cleanups, exit with 1 on error

This commit is contained in:
Matthias Schiffer 2015-11-23 01:14:54 +01:00
parent 40a9bdd7b1
commit f01121f7db

View File

@ -1,6 +1,8 @@
#!/bin/sh #!/bin/sh
if [ $# -eq 0 -o "-h" = "$1" -o "-help" = "$1" -o "--help" = "$1" ]; then set -e
if [ $# -ne 2 -o "-h" = "$1" -o "--help" = "$1" -o ! -r "$1" -o ! -r "$2" ]; then
cat <<EOHELP cat <<EOHELP
Usage: $0 <secret> <manifest> Usage: $0 <secret> <manifest>
@ -25,16 +27,18 @@ manifest="$2"
upper="$(mktemp)" upper="$(mktemp)"
lower="$(mktemp)" lower="$(mktemp)"
awk "BEGIN { sep=0 } trap 'echo rm -f "$upper" "$lower"; rm -f "$upper" "$lower"' EXIT
/^---\$/ { sep=1; next }
{ if(sep==0) print > \"$upper\"; awk 'BEGIN { sep=0 }
else print > \"$lower\"}" \ /^---$/ { sep=1; next }
{ if(sep==0) print > "'"$upper"'";
else print > "'"$lower"'"}' \
"$manifest" "$manifest"
ecdsasign "$upper" < "$SECRET" >> "$lower" ecdsasign "$upper" < "$SECRET" >> "$lower"
cat "$upper" > "$manifest" (
echo --- >> "$manifest" cat "$upper"
cat "$lower" >> "$manifest" echo ---
cat "$lower"
rm -f "$upper" "$lower" ) > "$manifest"