diff --git a/src/freedombone-utils-gpg b/src/freedombone-utils-gpg index 2a244248..bb1d39a6 100755 --- a/src/freedombone-utils-gpg +++ b/src/freedombone-utils-gpg @@ -28,6 +28,20 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +function gpg_update_mutt { + key_username=$1 + + if [ ! -f /home/$key_username/.muttrc ]; then + return + fi + + 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]*//') + + 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 + chown $key_username:$key_username /home/$key_username/.muttrc +} + function gpg_import_public_key { key_username=$1 key_filename=$2 diff --git a/src/freedombone-utils-keys b/src/freedombone-utils-keys index 452f4bb3..33dba28b 100755 --- a/src/freedombone-utils-keys +++ b/src/freedombone-utils-keys @@ -36,6 +36,7 @@ function interactive_gpg_from_usb { GPG_LOADING="yes" SSH_IMPORTED="no" GPG_CTR=0 + while [[ $GPG_LOADING == "yes" ]] do detect_usb_drive @@ -43,6 +44,7 @@ function interactive_gpg_from_usb { if [ ! -b $USB_DRIVE ]; then if (( GPG_CTR > 0 )); then gpg_reconstruct_key $MY_USERNAME interactive + gpg_update_mutt $MY_USERNAME return 0 fi dialog --title $"Recover Encryption Keys" --msgbox $'No USB drive found' 6 30 @@ -68,6 +70,7 @@ function interactive_gpg_from_usb { if (( GPG_CTR > 0 )); then backup_unmount_drive ${USB_DRIVE} gpg_reconstruct_key $MY_USERNAME interactive + gpg_update_mutt $MY_USERNAME return 0 fi dialog --title $"Recover Encryption Keys" \ @@ -94,7 +97,7 @@ function interactive_gpg_from_usb { echo $'No backup key file found on USB drive' exit 725729 fi - CURR_EMAIL_ADDRESS=$USER@$HOSTNAME + CURR_EMAIL_ADDRESS=$MY_USERNAME@$HOSTNAME 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]*//') @@ -118,8 +121,7 @@ function interactive_gpg_from_usb { echo $'Setting permissions' gpg_set_permissions $MY_USERNAME echo $"Updating muttrc for $MY_USERNAME" - CURR_GPG_ID=$(gpg --homedir=$HOME_DIR/.gnupg --list-keys $CURR_EMAIL_ADDRESS | sed -n '2p' | sed 's/^[ \t]*//') - 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/$MY_USERNAME/.muttrc + gpg_update_mutt $MY_USERNAME fi GPG_LOADING="no" dialog --title $"Recover Encryption Keys" \