bin/sign: allow alternative signatures

This commit is contained in:
xeruf 2021-07-10 21:47:34 +02:00
parent a5f22fd72e
commit 738458c5f2
1 changed files with 5 additions and 3 deletions

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
signature=$(pass information/signature) test -r "$1" || (echo "Usage: sign <document.pdf> [hoffset [voffset [scale [alt-signature]]]]" && exit 1)
signature=$(pass information/signature$(test -n "$5" && echo "-$5"))
# TODO make filenames unique and don't rerun unneccessarily # TODO make filenames unique and don't rerun unneccessarily
tmp_base=/tmp/sign tmp_base=/tmp/sign
@ -7,14 +9,14 @@ mkdir -p $tmp_base
tmp_signed=$tmp_base/$1_last-signature.pdf tmp_signed=$tmp_base/$1_last-signature.pdf
tmp_reversed=$tmp_base/$1_reverse.pdf tmp_reversed=$tmp_base/$1_reverse.pdf
sig=$tmp_base/signature_offset.pdf sig=$tmp_base/signature_offset.pdf
result="${1%.pdf}_signed.pdf" result="${1%.pdf}_${5:-signed}.pdf"
pdfjam "$signature" --outfile "$sig" --papersize "{595pt, 842pt}" --noautoscale true \ pdfjam "$signature" --outfile "$sig" --papersize "{595pt, 842pt}" --noautoscale true \
--offset "${2:-0}pt ${3:-0}pt" --scale "${4:-1}" --offset "${2:-0}pt ${3:-0}pt" --scale "${4:-1}"
pdfjam "$1" last "$sig" --outfile "$tmp_signed" --delta "0 -842pt" --nup "1x2" --fitpaper true pdfjam "$1" last "$sig" --outfile "$tmp_signed" --delta "0 -842pt" --nup "1x2" --fitpaper true
# https://apple.stackexchange.com/questions/198854/shell-command-to-count-pages-in-a-pdf-other-than-pdftk # https://apple.stackexchange.com/questions/198854/shell-command-to-count-pages-in-a-pdf-other-than-pdftk
if test $(pdftk "" dump_data | grep Pages | cut -d' ' -f2) -gt 1 if test "$(pdftk "$1" dump_data | grep Pages | cut -d' ' -f2)" -gt 1
then then
pdfjam "$1" last-1 --outfile "$tmp_reversed" pdfjam "$1" last-1 --outfile "$tmp_reversed"
pdfjam "$tmp_reversed" last-2 "$tmp_signed" --outfile "$result" pdfjam "$tmp_reversed" last-2 "$tmp_signed" --outfile "$result"