Update muttrc after key reconstruction

This commit is contained in:
Bob Mottram 2017-06-24 18:39:13 +01:00
parent 7c2df014a2
commit e4304ced42
2 changed files with 19 additions and 3 deletions

View File

@ -28,6 +28,20 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
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 { function gpg_import_public_key {
key_username=$1 key_username=$1
key_filename=$2 key_filename=$2

View File

@ -36,6 +36,7 @@ function interactive_gpg_from_usb {
GPG_LOADING="yes" GPG_LOADING="yes"
SSH_IMPORTED="no" SSH_IMPORTED="no"
GPG_CTR=0 GPG_CTR=0
while [[ $GPG_LOADING == "yes" ]] while [[ $GPG_LOADING == "yes" ]]
do do
detect_usb_drive detect_usb_drive
@ -43,6 +44,7 @@ function interactive_gpg_from_usb {
if [ ! -b $USB_DRIVE ]; then if [ ! -b $USB_DRIVE ]; then
if (( GPG_CTR > 0 )); then if (( GPG_CTR > 0 )); then
gpg_reconstruct_key $MY_USERNAME interactive gpg_reconstruct_key $MY_USERNAME interactive
gpg_update_mutt $MY_USERNAME
return 0 return 0
fi fi
dialog --title $"Recover Encryption Keys" --msgbox $'No USB drive found' 6 30 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 if (( GPG_CTR > 0 )); then
backup_unmount_drive ${USB_DRIVE} backup_unmount_drive ${USB_DRIVE}
gpg_reconstruct_key $MY_USERNAME interactive gpg_reconstruct_key $MY_USERNAME interactive
gpg_update_mutt $MY_USERNAME
return 0 return 0
fi fi
dialog --title $"Recover Encryption Keys" \ dialog --title $"Recover Encryption Keys" \
@ -94,7 +97,7 @@ function interactive_gpg_from_usb {
echo $'No backup key file found on USB drive' echo $'No backup key file found on USB drive'
exit 725729 exit 725729
fi 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_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]*//') 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' echo $'Setting permissions'
gpg_set_permissions $MY_USERNAME gpg_set_permissions $MY_USERNAME
echo $"Updating muttrc for $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]*//') gpg_update_mutt $MY_USERNAME
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
fi fi
GPG_LOADING="no" GPG_LOADING="no"
dialog --title $"Recover Encryption Keys" \ dialog --title $"Recover Encryption Keys" \