gpg clean up

This commit is contained in:
Luke Smith 2019-02-21 21:44:35 -05:00
parent 8c91d8f86d
commit 46c48281e1
No known key found for this signature in database
GPG Key ID: 4C50B54A911F6252

10
mw
View File

@ -7,7 +7,7 @@ creddir="$HOME/.local/share/muttwizard" # Location of encrypted credentials
bindir="$HOME/.config/mutt/bin" # Location of scripts run by mutt or the wizard bindir="$HOME/.config/mutt/bin" # Location of scripts run by mutt or the wizard
namere="^[a-z_][a-z0-9_-]*$" # Regex to ensure viable username namere="^[a-z_][a-z0-9_-]*$" # Regex to ensure viable username
emailre=".\+@.\+\\..\+" # Regex to confirm valid email address emailre=".\+@.\+\\..\+" # Regex to confirm valid email address
gpgemail="$(cat "$creddir/gpgemail" 2>&1)" # Get previously set gpg email address gpgemail="$(cat "$creddir/gpgemail" 2>/dev/null)" # Get previously set gpg email address
tmpdir="$(mktemp -d)" tmpdir="$(mktemp -d)"
GPG="gpg"; command -v gpg >/dev/null || GPG="gpg2" # Ensure proper gpg command GPG="gpg"; command -v gpg >/dev/null || GPG="gpg2" # Ensure proper gpg command
@ -169,11 +169,11 @@ getpass() { \
askgpg() { \ askgpg() { \
printf "To safely encrypt passwords, mutt-wizard requires that you have a GPG public/private key pair.\\n\\nPlease input the email address of your GPG key pair below.\\nEmail: " printf "To safely encrypt passwords, mutt-wizard requires that you have a GPG public/private key pair.\\n\\nPlease input the email address of your GPG key pair below.\\nEmail: "
read -r gpgemail read -r gpgemail
while ! echo "$gpgemail" | grep "$emailre"; do while ! echo "$gpgemail" | grep "$emailre" >/dev/null; do
printf "That is not a valud email address. Please try again.\\nEmail: " printf "That is not a valid email address. Please try again.\\nEmail: "
read -r gpgemail read -r gpgemail
done done
if "$GPG" -K | grep "<$gpgemail>"; then if "$GPG" -K | grep "<$gpgemail>" >/dev/null; then
echo "$gpgemail" > "$creddir/gpgemail" echo "$gpgemail" > "$creddir/gpgemail"
else else
printf "You do not appear to have a private key associated with %s.\\nPlease generate a GPG key pair by running \`%s --full-gen-key\` and rerun the wizard.\\n" "$gpgemail" "$GPG" printf "You do not appear to have a private key associated with %s.\\nPlease generate a GPG key pair by running \`%s --full-gen-key\` and rerun the wizard.\\n" "$gpgemail" "$GPG"
@ -273,12 +273,14 @@ main() { \
\033[31m1 Add an email account\033[0m \033[31m1 Add an email account\033[0m
2 Autodetect mailboxes 2 Autodetect mailboxes
3 Change an account's password 3 Change an account's password
4 Change GPG key pair used for encryption
0 Exit 0 Exit
Input a number to continue or press ctrl-c.\\n" Input a number to continue or press ctrl-c.\\n"
read -r choice read -r choice
case "$choice" in case "$choice" in
1) addaccount ;; 1) addaccount ;;
2) pick delete yes && finalize "$title" ;; 2) pick delete yes && finalize "$title" ;;
4) askgpg ;;
0) break ;; 0) break ;;
*) printf "Invalid input.\\n" *) printf "Invalid input.\\n"
esac esac