Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

mutt_install.sh 3.4 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/bash
  2. muttdir="$HOME/.config/mutt/"
  3. mkdir -p ~/.config/mutt/credentials
  4. # Email for GPG
  5. youremail=$(\
  6. dialog --title "Luke's mutt/offlineIMAP password wizard" --inputbox "Insert the email address with which you originally created your key pair. This is NOT necessarily the email you want to configure." 10 60 \
  7. 3>&1 1>&2 2>&3 3>&- \
  8. )
  9. # Get email address
  10. fulladdr=$(\
  11. dialog --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "Insert your full email address." 10 60 \
  12. 3>&1 1>&2 2>&3 3>&- \
  13. )
  14. # Check to see if domain is in domain list
  15. serverinfo=$(cat "$muttdir"autoconf/domains.csv | grep -w ^${fulladdr##*@})
  16. if [ -z "$serverinfo" ];
  17. then
  18. echo No suitable match. && exit
  19. else
  20. # Read in server data as variables
  21. IFS=, read service imap iport smtp sport spoolfile postponed record <<EOF
  22. $serverinfo
  23. EOF
  24. fi
  25. realname=$(\
  26. dialog --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "Enter the full name you'd like to be identified by on this email account." 10 60 \
  27. 3>&1 1>&2 2>&3 3>&- \
  28. )
  29. title=$(\
  30. dialog --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "Give a short, one-word name for this email account that will differentiate it from other email accounts." 10 60 \
  31. 3>&1 1>&2 2>&3 3>&- \
  32. )
  33. # Sets the repo type and other variables for the sed regex.
  34. if [[ "$service" == "gmail.com" ]];
  35. then
  36. type="Gmail"
  37. delet="remotehost"
  38. else
  39. type="IMAP"
  40. delet="Gmail]\/"
  41. fi
  42. # The replacements
  43. replacement="
  44. s/\$realname/$realname/g;
  45. s/\$title/$title/g;
  46. s/\$fulladdr/$fulladdr/g;
  47. s/\$imap/$imap/g;
  48. s/\$iport/$iport/g;
  49. s/\$smtp/$smtp/g;
  50. s/\$sport/$sport/g;
  51. s/\$spoolfile/$spoolfile/g;
  52. s/\$postponed/$postponed/g;
  53. s/\$record/$record/g;
  54. s/\$type/$type/g;
  55. /$delet/d"
  56. # Gets the first unused shortcut number in the muttrc and puts it in $idnum.
  57. cat "$muttdir"muttrc | grep i[0-9] | awk '{print $3}' | sed -e 's/i//g' > /tmp/mutt_used
  58. echo -e "1\n2\n3\n4\n5\n6\n7\n8\n9" > /tmp/mutt_all_possible
  59. idnum=$(diff /tmp/mutt_all_possible /tmp/mutt_used | sed -n 2p | awk '{print $2}')
  60. addAccount() {
  61. # First, adding the encrypted password.
  62. dialog --title "Luke's mutt/offlineIMAP password wizard" --passwordbox "Enter the password for the \"$title\" account." 10 60 2> /tmp/$title
  63. gpg -r $youremail --encrypt /tmp/$title
  64. shred -u /tmp/$title && echo "Password encrypted and memory shredded."
  65. mv /tmp/$title.gpg ~/.config/mutt/credentials/
  66. # Creating the offlineimaprc if it doesn't exist already.
  67. if [ ! -f ~/.offlineimaprc ]; then cp "$muttdir"autoconf/offlineimap_header ~/.offlineimaprc; fi
  68. cat "$muttdir"autoconf/offlineimap_profile | sed -e "$replacement" >> ~/.offlineimaprc
  69. # Add the mutt profile.
  70. cat "$muttdir"autoconf/mutt_profile | sed -e "$replacement" > "$muttdir"accounts/$title.muttrc
  71. # Add a numbered shortcut in the muttrc
  72. echo "macro index,pager i$idnum '<sync-mailbox><enter-command>source "$muttdir"accounts/$title.muttrc<enter><change-folder>!<enter>'" >> "$muttdir"muttrc
  73. # Adding directory structure for cache.
  74. mkdir -p "$muttdir"accounts/$title/cache/bodies "$muttdir"accounts/$title/cache/headers
  75. # Add to offlineimaprc sync list.
  76. sed -i "s/^accounts =.*[a-zA-Z]$/&, $title/g;s/^accounts =$/accounts = $title/g" ~/.offlineimaprc
  77. # Makes account default if there is no default account.
  78. grep "$muttdir"muttrc -e "^source .*accounts.*" >/dev/null && echo there || \
  79. echo "source ${muttdir}accounts/$title.muttrc" >> "$muttdir"muttrc ;}
  80. addAccount
  81. clear