we did it reddit

This commit is contained in:
Luke Smith 2019-04-11 23:12:19 -04:00
parent 2452a74f33
commit 594a2ffee9
No known key found for this signature in database
GPG Key ID: 4C50B54A911F6252

52
mw
View File

@ -172,13 +172,6 @@ EOF
read -r login read -r login
printf "\033[0m" printf "\033[0m"
[ -z "$login" ] && login="$fulladdr" [ -z "$login" ] && login="$fulladdr"
if [ "$service" = "gmail.com" ]; then
type="Gmail"; ifgoogleline="folderfilter = lambda foldername: foldername not in ['[Gmail]/All Mail']
ssl_version = tls1_2"
printf "\033[1mGoogle\033[0m mail account detected. Remember to check the README to make sure of Google-specific settings you must enable.\\n"
else
type="IMAP"; ifgoogleline="remotehost = $imap"
fi
grep "i[0-9]" "$muttdir/personal.muttrc" | awk '{print $3}' | sed -e 's/i//g' > "$tmpdir/mutt_used" grep "i[0-9]" "$muttdir/personal.muttrc" | awk '{print $3}' | sed -e 's/i//g' > "$tmpdir/mutt_used"
seq 1 9 > "$tmpdir/mutt_all" seq 1 9 > "$tmpdir/mutt_all"
idnum=$(diff "$tmpdir/mutt_all" "$tmpdir/mutt_used" | sed -n 2p | awk '{print $2}') idnum=$(diff "$tmpdir/mutt_all" "$tmpdir/mutt_used" | sed -n 2p | awk '{print $2}')
@ -236,16 +229,15 @@ formatShortcut() { \
done ;} done ;}
trysync() { \ trysync() { \
! ping -q -c 1 1.1.1.1 > /dev/null && printf "No internet connection detected.\\nTry rerunning \`mbsync $title\` manually when connection is established, then select the option to detect mailboxes and finalize installation.\\n" && return 1 ! ping -q -c 1 1.1.1.1 > /dev/null && printf "No internet connection detected.\\nTry rerunning \`mbsync %s\` manually when connection is established, then select the option to detect mailboxes and finalize installation.\\n" "$title" && return 1
printf "\033[32mYou must have an internet connection to continue.\033[0m\\nmutt-wizard will run mbsync briefly to (1) ensure that login details are functional and (2) allow mbsync to tell us what mailboxes your email account has.\\nAfter around 15 seconds, mutt-wizard will kill the process and continue.\\nYou can run mbsync manually to finish the mail sync later.\\n" printf "\033[32mYou must have an internet connection to continue.\033[0m\\nmutt-wizard will run mbsync briefly to (1) ensure that login details are functional and (2) allow mbsync to tell us what mailboxes your email account has.\\nAfter around 15 seconds, mutt-wizard will kill the process and continue.\\nYou can run mbsync manually to finish the mail sync later.\\n"
cont cont
(sleep 15; killall mbsync)>/dev/null 2>&1 &
mkdir -p "$maildir/$title" mkdir -p "$maildir/$title"
mbsync "$title" if mailboxes="$(mbsync -l "$title")" >/dev/null 2>&1; then
if ls -d "$maildir/$title/"* >/dev/null 2>&1; then printf "\033[32mMailboxes detected.\033[0m\\n"
printf "\033[32mSync successful.\033[0m\\n"; return echo "$mailboxes" | xargs -I {} mkdir -p "$maildir/$title/{}"
else else
printf "\033[31m\033[31mSync not successful.\033[0m Try running \`mbsync $title\` manually after double-checking your password and server settings.\\nThen select to finalize the account.\\n"; return 1 printf "\033[31m\033[31mSync not successful.\033[0m Try running \`mbsync %s\` manually after double-checking your password and server settings.\\nThen select to finalize the account.\\n" "$title"; return 1
fi fi
} }
@ -278,15 +270,14 @@ finalize() { \
printf "All done.\\n" printf "All done.\\n"
} }
wipe () { \ confirm() { printf "Are you \033[31;1mreally\033[0m sure you want to %s?\\n\t" "$@" && read -r input && ! echo "$input" | grep -i "y\(es\)*" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1
printf "Are you \033[31;1mreally\033[0m sure you want to delete all email accounts?\\n" && read -r input && ! echo "$input" | grep -i "y\(es\)*" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1 printf "Are you really, really sure you want to %s?\\n\t" "$@" && read -r input && ! echo "$input" | grep -i "y\(es\)*" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1
printf "Are you really, really sure?" && read -r input && ! echo "$input" | grep -i "y\(es\)*" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1 return 0 ;}
rm -rf "$mbsyncrc" "$accdir" "$creddir" "$muttdir/personal.muttrc" && echo "All configs and account settings have been purged."
}
pick() { \ pick() { \
numbered="$(ls $accdir/*muttrc | sed "s/.*\///;s/\..*//" | nl)" numbered="$(ls $accdir/*muttrc | sed "s/.*\///;s/\..*//" | nl)"
[ "$(echo "$numbered" | wc -w)" = 0 ] && printf "No accounts to delete.\\n" && return 1 [ "$(echo "$numbered" | wc -w)" = 0 ] && printf "No accounts to choose from.\\n" && return 1
printf "Select an accounts to %s:\\n" "$1" printf "Select an accounts to %s:\\n" "$1"
echo "$numbered" echo "$numbered"
printf "\033[36m\t" printf "\033[36m\t"
@ -295,14 +286,14 @@ pick() { \
[ -z "$input" ] && return 1 [ -z "$input" ] && return 1
title="$(echo "$numbered" | grep "$input" | awk '{print $2}')" title="$(echo "$numbered" | grep "$input" | awk '{print $2}')"
[ -z "$title" ] && printf "Invalid response." && return 1 [ -z "$title" ] && printf "Invalid response." && return 1
[ -n "$2" ] && printf "Are you sure you want to %s the \`%s\` account?\\n" "$1" "$title" && read -r input && echo "$input" | grep -i "y\(es\)*" >/dev/null return 0 ;}
}
delete() { sed -i "/IMAPAccount $title/,/# End profile/d" "$mbsyncrc" delete() { sed -i "/IMAPAccount $title/,/# End profile/d" "$mbsyncrc"
rm -rf "${accdir:?}/${title:?}" "$creddir/$title.gpg" "$accdir/$title.muttrc" rm -rf "${accdir:?}/${title:?}" "$creddir/$title.gpg" "$accdir/$title.muttrc"
sed -i "/$title.muttrc/d" "$muttdir/personal.muttrc" sed -i "/$title.muttrc/d" "$muttdir/personal.muttrc"
# Delete from the line matching the account name, until the next account or empty line sed -i "/account $title/,/^\(\s*$\|account\)/d" "$HOME/.config/msmtp/config"
sed -i "/account $title/,/^\(\s*$\|account\)/d" "$HOME/.config/msmtp/config";} confirm "delete the local mail repository as well?" && rm -rf "${maildir:?}/${title:?}"
}
choosecron() { ! pgrep crond >/dev/null && echo "No cron manager running. Install/enable one and then select this option again." && return 1 choosecron() { ! pgrep crond >/dev/null && echo "No cron manager running. Install/enable one and then select this option again." && return 1
if crontab -l | grep mailsync >/dev/null; then if crontab -l | grep mailsync >/dev/null; then
@ -327,14 +318,13 @@ choosecron() { ! pgrep crond >/dev/null && echo "No cron manager running. Instal
fi fi
} }
cont() { [ -n "$1" ] && printf "%s\\n" "$1" cont() { printf "Press Enter to continue.\\n"
printf "Press Enter to continue.\\n"
stty -echo stty -echo
read -r null read -r null
stty echo stty echo ; }
}
addtype() { \ addtype() { \
! command -v mbsync >/dev/null && printf "You must have the \`mbsync\` command to add an account.\\nIt syncs mail and detects remote mailboxes.\\nYou can typically get it by installing \`isync\`.\\n" && return 1
while : ; do while : ; do
echo "Do you want to keep your mail for this account offline with mbsync? [yes/no]" echo "Do you want to keep your mail for this account offline with mbsync? [yes/no]"
read -r offnot read -r offnot
@ -368,7 +358,6 @@ What would you like \033[32mmutt-wizard\033[0m to do?
5 Change GPG key pair used for encryption 5 Change GPG key pair used for encryption
6 Delete all account data 6 Delete all account data
7 Enable/disable autosync 7 Enable/disable autosync
9 Edit this script
0 Exit 0 Exit
Input a number to continue or press ctrl-c.\\n" Input a number to continue or press ctrl-c.\\n"
printf "\033[36m\t" printf "\033[36m\t"
@ -377,12 +366,11 @@ Input a number to continue or press ctrl-c.\\n"
case "$choice" in case "$choice" in
1) addtype ;; 1) addtype ;;
2) pick finalize && finalize ;; 2) pick finalize && finalize ;;
3) pick "change the password of" yes && getpass ;; 3) pick "change the password of" && confirm "change the password of" && getpass ;;
4) pick delete yes && delete ;; 4) pick delete && confirm "delete the \`$title\` profile" && delete ;;
5) askgpg ;; 5) askgpg ;;
6) wipe && printf "Account data purged." ;; 6) confirm "delete all account data" && wipe && rm -ri "$mbsyncrc" "$accdir" "$creddir" "$muttdir/personal.muttrc" && echo "All configs and account settings have been purged." ;;
7) choosecron ;; 7) choosecron ;;
9) "$EDITOR" "$0"; exit ;;
0) break ;; 0) break ;;
*) printf "Invalid input.\\n" *) printf "Invalid input.\\n"
esac esac