Skip to content

Instantly share code, notes, and snippets.

@epcim
Forked from sometimesfood/reencrypt.sh
Created April 28, 2023 11:30
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 epcim/e09315942364658b6870794dfe06cd20 to your computer and use it in GitHub Desktop.
Save epcim/e09315942364658b6870794dfe06cd20 to your computer and use it in GitHub Desktop.
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