Use the default gpg key if specified within the config file

This commit is contained in:
Bob Mottram 2018-01-11 13:32:25 +00:00
parent 1feb529b86
commit 07bca1fc2f
3 changed files with 39 additions and 0 deletions

View File

@ -37,6 +37,19 @@ MY_EMAIL_ADDRESS=$USER@$HOSTNAME
GPG_ID=$(gpg --list-keys $MY_EMAIL_ADDRESS | sed -n '2p' | sed 's/^[ \t]*//')
GPG_BACKUP_ID=$(gpg --list-keys "(backup key)" | sed -n '2p' | sed 's/^[ \t]*//')
# If the default key is specified within gpg.conf
if [ -f ~/.gnupg/gpg.conf ]; then
if grep -q "default-key" ~/.gnupg/gpg.conf; then
default_gpg_key=$(cat ~/.gnupg/gpg.conf | grep "default-key")
if [[ "$default_gpg_key" != *'#'* ]]; then
default_gpg_key=$(cat ~/.gnupg/gpg.conf | grep "default-key" | awk -F ' ' '{print $2}')
if [ ${#default_gpg_key} -gt 3 ]; then
GPG_ID=$(gpg --list-keys $default_gpg_key | sed -n '2p' | sed 's/^[ \t]*//')
fi
fi
fi
fi
# Start including files
UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*

View File

@ -38,6 +38,19 @@ function gpg_update_mutt {
CURR_EMAIL_ADDRESS=$key_username@$HOSTNAME
CURR_GPG_ID=$(gpg --homedir=/home/$key_username/.gnupg --list-keys $CURR_EMAIL_ADDRESS | sed -n '2p' | sed 's/^[ \t]*//')
# If the default key is specified within gpg.conf
if [ -f /home/$key_username/gpg.conf ]; then
if grep -q "default-key" /home/$key_username/gpg.conf; then
default_gpg_key=$(cat /home/$key_username/gpg.conf | grep "default-key")
if [[ "$default_gpg_key" != *'#'* ]]; then
default_gpg_key=$(cat /home/$key_username/gpg.conf | grep "default-key" | awk -F ' ' '{print $2}')
if [ ${#default_gpg_key} -gt 3 ]; then
CURR_GPG_ID=$(gpg --homedir=/home/$key_username/.gnupg --list-keys $default_gpg_key | sed -n '2p' | sed 's/^[ \t]*//')
fi
fi
fi
fi
sed -i "s|set pgp_encrypt_only_command.*|set pgp_encrypt_only_command=\"/usr/lib/mutt/pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --trust-model always --encrypt-to $CURR_GPG_ID -- -r %r -- %f\"|g" /home/$key_username/.muttrc
sed -i "s|set pgp_encrypt_sign_command.*|set pgp_encrypt_sign_command=\"/usr/lib/mutt/pgpewrap gpg %?p?--passphrase-fd 0? --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --trust-model always --encrypt-to $CURR_GPG_ID -- -r %r -- %f\"|g" /home/$key_username/.muttrc

View File

@ -101,6 +101,19 @@ function interactive_gpg_from_usb {
CURR_GPG_ID=$(gpg --homedir=$HOME_DIR/.gnupg --list-keys $CURR_EMAIL_ADDRESS | sed -n '2p' | sed 's/^[ \t]*//')
CURR_GPG_BACKUP_ID=$(gpg --homedir=$HOME_DIR/.gnupg --list-keys "(backup key)" | sed -n '2p' | sed 's/^[ \t]*//')
# If the default key is specified within gpg.conf
if [ -f $HOME_DIR/gpg.conf ]; then
if grep -q "default-key" $HOME_DIR/gpg.conf; then
default_gpg_key=$(cat $HOME_DIR/gpg.conf | grep "default-key")
if [[ "$default_gpg_key" != *'#'* ]]; then
default_gpg_key=$(cat $HOME_DIR/gpg.conf | grep "default-key" | awk -F ' ' '{print $2}')
if [ ${#default_gpg_key} -gt 3 ]; then
CURR_GPG_ID=$(gpg --homedir=$HOME_DIR/.gnupg --list-keys $default_gpg_key | sed -n '2p' | sed 's/^[ \t]*//')
fi
fi
fi
fi
echo $'Making backup copy of existing gpg keys'
if [ -d $HOME_DIR/.gnupg ]; then
if [ -d $HOME_DIR/.gnupg_old ]; then