Last active
August 29, 2015 14:14
-
-
Save Superbil/9722f96e881912d110bc to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# setup your master key | |
PGP_KEY=0xAAAAAAA | |
# GPG backup path | |
pgp_backup=/backup_path/folder | |
# Check $pgp_backup folder is exist | |
[ ! -d $pgp_backup ] && exit 1 | |
function gpg_update_home () { | |
if [ -d ~/.gnupg ]; then | |
backup_path=~/.gnupg.backup.$RANDOM | |
mv ~/.gnupg $backup_path | |
unset backup_path | |
fi | |
# copy old .gnupg folder | |
rsync -avqp --chmod=D700,F600 --exclude '*.backup' $pgp_backup $HOME | |
} | |
function gpg_remove_master_key () { | |
gpg_export_path=$(dirname $pgp_backup)/subkeys.acs | |
# export secret-subkeys | |
gpg --export-secret-subkeys $PGP_KEY > $gpg_export_path | |
gpg --delete-secret-key $PGP_KEY | |
gpg --import $gpg_export_path | |
} | |
function gpg_clean_up() { | |
unset PGP_KEY | |
unset pgp_backup | |
unset gpg_export_path | |
} | |
gpg_update_home | |
gpg_remove_master_key | |
gpg_clean_up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment