-
-
Save epcim/e09315942364658b6870794dfe06cd20 to your computer and use it in GitHub Desktop.
Small script that re-encrypts GPG-encrypted files with a new key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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