Skip to content

Instantly share code, notes, and snippets.

@sometimesfood
Last active April 28, 2023 11:30
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Small script that re-encrypts GPG-encrypted files with a new key
#!/bin/bash
checkusage() {
[[ $# -lt 2 ]] && err_exit 'Usage: reencrypt.sh KEY_ID FILE...'
}
err() { echo -e "$@" >&2; }
err_exit() {
err "$@"
exit 1
}
reencrypt() {
local key_id="$1"
local file="$2"
mv ${file} ${file}.bak
gpg --decrypt ${file}.bak \
| gpg --recipient ${key_id} --encrypt --output ${file}
}
main() {
checkusage "$@"
local key_id=$1
shift
local files="$@"
for file in $files; do
reencrypt "${key_id}" "${file}"
done
}
main "$@"
# Local Variables:
# indent-tabs-mode: nil
# sh-indentation: 2
# sh-basic-offset: 2
# End:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment