Improve the master key import

This commit is contained in:
Bob Mottram 2017-06-23 23:39:16 +01:00
parent dc436a7687
commit 08ca1e149a
1 changed files with 21 additions and 0 deletions

View File

@ -128,9 +128,30 @@ function interactive_gpg_from_usb {
echo $'No backup key file found on USB drive'
exit 725729
fi
CURR_EMAIL_ADDRESS=$USER@$HOSTNAME
CURR_GPG_ID=$(gpg --list-keys $MY_EMAIL_ADDRESS | sed -n '2p' | sed 's/^[ \t]*//')
CURR_GPG_BACKUP_ID=$(gpg --list-keys "(backup key)" | sed -n '2p' | sed 's/^[ \t]*//')
echo $'Making backup copy of existing gpg keys'
if [ -d $HOME_DIR/.gnupg ]; then
if [ -d $HOME_DIR/.gnupg_old ]; then
rm -rf $HOME_DIR/.gnupg_old
fi
cp -r $HOME_DIR/.gnupg $HOME_DIR/.gnupg_old
chmod 700 $HOME_DIR/.gnupg_old
chmod -R 600 $HOME_DIR/.gnupg_old/*
chown -R $MY_USERNAME:$MY_USERNAME $HOME_DIR/.gnupg_old
fi
echo $'Removing old gpg keys'
gpg --homedir=$HOME_DIR/.gnupg --delete-secret-key "$CURR_GPG_BACKUP_ID"
gpg --homedir=$HOME_DIR/.gnupg --delete-key "$CURR_GPG_BACKUP_ID"
gpg --homedir=$HOME_DIR/.gnupg --delete-secret-key "$CURR_GPG_ID"
gpg --homedir=$HOME_DIR/.gnupg --delete-key "$CURR_GPG_ID"
echo $'Importing master keys'
gpg --homedir=$HOME_DIR/.gnupg --allow-secret-key-import --import $USB_MOUNT/.mastergpgkey
echo "$BACKUP_DUMMY_PASSWORD" | gpg --batch --passphrase-fd 0 --homedir=$HOME_DIR/.gnupg --allow-secret-key-import --import $USB_MOUNT/.backupgpgkey
if [ -d $HOME_DIR/.gnupg ]; then
echo $'Setting permissions'
chmod 700 $HOME_DIR/.gnupg
chmod -R 600 $HOME_DIR/.gnupg/*
chown -R $MY_USERNAME:$MY_USERNAME $HOME_DIR/.gnupg