Skip to content

Instantly share code, notes, and snippets.

@feklee
Last active June 15, 2022 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feklee/3d931bdb3d7582bb862e8d9e9443e83e to your computer and use it in GitHub Desktop.
Save feklee/3d931bdb3d7582bb862e8d9e9443e83e to your computer and use it in GitHub Desktop.
Appends a PDF file to a PGP encrypted PDF file
#!/bin/bash
# Felix E. Klee <felix.klee@inka.de>
set -e
# Usage info
show_help() {
cat << EOF
Usage: ${0##*/} PGP_ENCRYPTED_PDF NEW_PDF PGP_ENCRYPTED_RESULT
Appends NEW_PDF to PGP_ENCRYPTED_PDF and saves it to PGP_ENCRYPTED_RESULT.
EOF
}
if [ "$#" -ne 3 ]; then
show_help >&2
exit 1
fi
PGP_ENCRYPTED_PDF="$1"
NEW_PDF="$2"
PGP_ENCRYPTED_RESULT="$3"
TEMP_PDF=$(mktemp -t XXXXXXXX.pdf)
gpg --batch --yes -o "$TEMP_PDF" -d "$PGP_ENCRYPTED_PDF"
qpdf "$TEMP_PDF" --replace-input --pages "$TEMP_PDF" "$NEW_PDF" --
gpg -e -r "$EMAIL" "$TEMP_PDF"
mv "$TEMP_PDF.gpg" "$PGP_ENCRYPTED_RESULT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment