From 5c4b388d537f41851f4d06b545dcb4362427aaaa Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 11 Feb 2018 17:58:16 -0700 Subject: [PATCH] integration into single script --- mutt_install.sh | 83 ++++++++++++++++++++++++++++++++++++++++++------ removeaccount.sh | 39 ----------------------- wipe_settings.sh | 12 ------- 3 files changed, 73 insertions(+), 61 deletions(-) delete mode 100755 removeaccount.sh delete mode 100755 wipe_settings.sh diff --git a/mutt_install.sh b/mutt_install.sh index 628d044..acbe9e8 100755 --- a/mutt_install.sh +++ b/mutt_install.sh @@ -1,16 +1,46 @@ #!/bin/bash muttdir="$HOME/.config/mutt/" -mkdir -p "$muttdir"credentials/ "$muttdir"accounts/ -gpgemail=$( dialog --title "Luke's mutt/offlineIMAP password wizard" --inputbox "Insert the email address with which you originally created your GPG key pair. This is NOT necessarily the email you want to configure." 10 60 3>&1 1>&2 2>&3 3>&- ) +# Sees what accounts have been generated bny the wizard +# by checking ~/.offlineimap and yields a menu of them. +inventory() { \ + cat ~/.offlineimaprc | grep "^accounts =" | sed -e 's/accounts =\( \)//g;s/\(,\) /\n/g;' | nl --number-format=ln > /tmp/numbered + accounts=() + while read n s ; do + accounts+=($n "$s" off) + done < /tmp/numbered -mainloop() { fulladdr=$( dialog --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "Insert the full email address for the account you want to configure." 10 60 3>&1 1>&2 2>&3 3>&- ) + choices=$(dialog --separate-output --checklist "Choose an email account." 22 76 16 "${accounts[@]}" 2>&1 >/dev/tty) + + if [ -z "$choices" ]; + then + clear + else + userchoices=$(IFS="|"; keys="${choices[*]}"; keys="${keys//|/\\|}"; grep -w "${keys}" /tmp/numbered | awk '{print $2}') + fi ;} + + +removeAccount() { sed -ie " + /Account $1]/,/Account/{//!d} + /Account $1]/d + s/ $1\(,\|$\)//g + s/=$1\(,\|$\)/=/g + s/,$//g + " ~/.offlineimaprc + rm "$muttdir"accounts/$1.muttrc + rm "$muttdir"credentials/$1.gpg + rm -rf "$muttdir"accounts/$1 + echo $1 deleted. ;} + + + +addloop() { fulladdr=$( dialog --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "Insert the full email address for the account you want to configure." 10 60 3>&1 1>&2 2>&3 3>&- ) # Check to see if domain is in domain list serverinfo=$(cat "$muttdir"autoconf/domains.csv | grep -w ^${fulladdr##*@}) if [ -z "$serverinfo" ]; then - echo No suitable match. && exit + echo No suitable match in domains.csv. && clear && exit else # Read in server data as variables IFS=, read service imap iport smtp sport spoolfile postponed record < /tmp/$title gpg -r $gpgemail --encrypt /tmp/$title - shred -u /tmp/$title && echo "Password encrypted and memory shredded." + shred -u /tmp/$title mv /tmp/$title.gpg ~/.config/mutt/credentials/ # Creating the offlineimaprc if it doesn't exist already. @@ -76,10 +106,43 @@ addAccount() { grep "$muttdir"personal.muttrc -e "^source .*accounts.*" >/dev/null && echo there || \ echo "source ${muttdir}accounts/$title.muttrc" >> "$muttdir"personal.muttrc ;} -mainloop +# This is run when a user chooses to add an account. +addChosen() { \ + mkdir -p "$muttdir"credentials/ "$muttdir"accounts/ + gpgemail=$( dialog --title "Luke's mutt/offlineIMAP password wizard" --inputbox "Insert the email address with which you originally created your GPG key pair. This is NOT necessarily the email you want to configure." 10 60 3>&1 1>&2 2>&3 3>&- ) + addloop + while : ; + do + dialog --title "Luke's mutt/offlineIMAP password wizard" --yesno "Would you like to add another email account?" 10 60 || break + addloop + done ;} + +wipe () { rm $HOME/.offlineimaprc + rm -rf "$muttdir"/accounts + rm -f "$muttdir"credentials/*gpg + rm "$muttdir"personal.muttrc ;} + + + while : ; -do - dialog --title "Luke's mutt/offlineIMAP password wizard" --yesno "Would you like to add another email account?" 10 60 || break - mainloop + do +choice=$(dialog --title "Luke's mutt/offlineIMAP wizard" \ + --menu "What would you like to do?" 14 45 5 \ + 0 "List all email accounts configured." \ + 1 "Add an email account." \ + 2 "Remove an email account." \ + 3 "Remove all email accounts." \ + 4 "Exit this wizard." \ + 3>&1 1>&2 2>&3 3>&1 ) + + +case $choice in +0) dialog --title "Accounts detected" --msgbox "The following accounts have been detected: +$(grep ~/.offlineimaprc -e "^accounts =" | sed 's/accounts =//g') +" 6 60;; +1) addChosen;; +2) inventory && for i in $userchoices; do removeAccount $i ; done;; +3) (dialog --defaultno --title "Wipe all custom neomutt/offlineIMAP settings?" --yesno "Would you like to wipe all of the mutt/offlineIMAP settings generated by the system?" 6 60 && wipe) ;; +4) clear && break +esac done -clear diff --git a/removeaccount.sh b/removeaccount.sh deleted file mode 100755 index d4cd0a0..0000000 --- a/removeaccount.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/sh -muttdir="$HOME/.config/mutt/" - -# This script will remove an account from ~/.offlineimaprc and the -# designated location in ~/.config/mutt/accounts. - -# Feed the script the title of the account. - -cat ~/.offlineimaprc | grep "^accounts =" | sed -e 's/accounts =\( \)//g;s/\(,\) /\n/g;' | nl --number-format=ln > /tmp/numbered - -removeAccount() { sed -ie " - /Account $1]/,/Account/{//!d} - /Account $1]/d - s/ $1\(,\|$\)//g - s/=$1\(,\|$\)/=/g - s/,$//g - " ~/.offlineimaprc - rm "$muttdir"accounts/$1.muttrc - rm "$muttdir"credentials/$1.gpg - rm -rf "$muttdir"accounts/$1 - echo $1 deleted. ;} - -#/tmp/numbered - -accounts=() -while read n s ; do - accounts+=($n "$s" off) -done < /tmp/numbered - -choices=$(dialog --separate-output --checklist "Choose an email account to remove." 22 76 16 "${accounts[@]}" 2>&1 >/dev/tty) -clear - -if [ -z "$choices" ]; - then - clear - else - todelet=$(IFS="|"; keys="${choices[*]}"; keys="${keys//|/\\|}"; grep -w "${keys}" /tmp/numbered | awk '{print $2}') - for i in $todelet; do removeAccount $i; done -fi diff --git a/wipe_settings.sh b/wipe_settings.sh deleted file mode 100755 index bfdd8b8..0000000 --- a/wipe_settings.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -muttdir="$HOME/.config/mutt/" - -wipe () { rm $HOME/.offlineimaprc -rm -rf "$muttdir"/accounts -rm -f "$muttdir"credentials/*gpg -rm "$muttdir"personal.muttrc ;} - -(dialog --defaultno --title "Wipe all custom neomutt/offlineIMAP settings?" --yesno "Would you like to wipe all of the mutt/offlineIMAP settings generated by the system?" 6 60 && wipe) || clear && exit - -clear