Created
August 31, 2017 08:17
-
-
Save milouse/67c44b4906d12a5a04288260a39e164b to your computer and use it in GitHub Desktop.
A quick script to decypher and reencrypt all the content of a password-store repository when you want to add or change your gpg keys
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
#!/usr/bin/env bash | |
[ ! -n "$1" ] && echo "You must provide the new key id" && exit 1 | |
recipient_chain= | |
for recip in $@; do | |
recipient_chain+="-r $recip " | |
done | |
for gpgfile in `find . -type f -name *.gpg`; do | |
real_name=$(basename "$gpgfile" '.gpg') | |
echo "Decyphering $real_name" | |
gpg -d "$gpgfile" > "new_${real_name}" | |
rm "$gpgfile" | |
echo "Recyphering $real_name" | |
echo "gpg $recipient_chain -e ${real_name}" | |
gpg $recipient_chain -e "new_${real_name}" | |
rm "new_${real_name}" | |
mv "new_${real_name}.gpg" "$gpgfile" | |
done | |
rm .gpg-id | |
for recip in $@; do | |
echo "$recip" >> .gpg-id | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment