113 lines
2.7 KiB
Bash
Executable File
113 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
CURDIR=$(dirname "$(readlink -f "$0")")
|
|
source "$CURDIR"/shared.so
|
|
|
|
OUT=
|
|
TOOL=
|
|
|
|
function exec {
|
|
ACTIONS=("send mails in queue" "list mails in queue" "switch connection status" "quit")
|
|
PS3="Select action: "
|
|
|
|
select action in "${ACTIONS[@]}"
|
|
do
|
|
echo # empty line after selection
|
|
case $REPLY in # $REPLY takes the numbers which is nice
|
|
1) # Show queue; ask for confirmation; if yes, send emails
|
|
send_mailqueue
|
|
break ;;
|
|
2) # Show queue
|
|
list_mailqueue
|
|
break ;;
|
|
3) # Switch online status
|
|
switch_conn
|
|
break ;;
|
|
4|"q") # exit silently, one can also press "q" instead of the number
|
|
exit 0
|
|
break ;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
function check_mailqueue {
|
|
QUEUE=$(msmtp-listqueue.sh | grep -o "^From: " | wc -l)
|
|
OUT="$OUT;mq=$QUEUE"
|
|
TOOL="$TOOL;conn=$var_conn"
|
|
|
|
# If $QUEUE > 0 and >10 runs, show notification
|
|
if [ "$QUEUE" -gt 0 ]; then
|
|
var_mailqueue_runs=$(($var_mailqueue_runs + 1))
|
|
fi
|
|
if [ "$QUEUE" -gt 0 ] && [ "$var_mailqueue_runs" -gt 9 ]; then
|
|
notify-send "There are mails in the mailqueue. Remember sending them manually or switch online status."
|
|
var_mailqueue_runs=0 # reset counter
|
|
fi
|
|
}
|
|
|
|
# MAIL QUEUE ACTIONS
|
|
function send_mailqueue {
|
|
msmtp-listqueue.sh
|
|
read -p "Send these queued mails? [Y/n]: " YN
|
|
if [[ $YN =~ ^(Y|y|)$ ]]; then
|
|
msmtp-runqueue.sh
|
|
else
|
|
echo "Not sending emails"
|
|
fi
|
|
}
|
|
function list_mailqueue {
|
|
msmtp-listqueue.sh
|
|
}
|
|
function switch_conn {
|
|
echo "Current connection status: $var_conn"
|
|
read -p "Switch connection status? [Y/n]: " YN
|
|
if [[ $YN =~ ^(Y|y|)$ ]]; then
|
|
if [ "$var_conn" == "off" ]; then
|
|
var_conn="on"
|
|
echo "Connection status switched to \"on\""
|
|
else
|
|
var_conn="off"
|
|
echo "Connection status switched to \"off\""
|
|
fi
|
|
else
|
|
echo "Connection status not changed."
|
|
fi
|
|
}
|
|
|
|
# SVN STATUS
|
|
function check_svn {
|
|
STATUS=$(wget -T 5 -q -O - $SVNSTATUS)
|
|
EXIT="$?"
|
|
if ([ "$EXIT" == 4 ] || [ "$EXIT" == 6 ] || [ "$EXIT" == 28 ]); then
|
|
SVN="t/o"
|
|
else
|
|
SVN=$(echo $STATUS | cut -d";" -f1)
|
|
SVN_REV=$(echo $STATUS | cut -d";" -f2)
|
|
fi
|
|
OUT="$OUT;svn=$SVN"
|
|
TOOL="$TOOL;svn=$SVN_REV"
|
|
}
|
|
|
|
# DIRECT EXECUTE, CASE MENU
|
|
if [ "$1" == "exec" ]; then
|
|
while :; do
|
|
exec
|
|
wtmp; source "$TMP"
|
|
echo
|
|
done
|
|
else
|
|
# Show info on status bar
|
|
check_mailqueue
|
|
check_svn
|
|
OUT=$(echo $OUT | sed -r 's/^;//')
|
|
OUT=$(echo $OUT | sed -r 's/;/ \| /g')
|
|
TOOL=$(echo $TOOL | sed -r 's/^;//')
|
|
TOOL=$(echo $TOOL | sed -r 's/;/ \| /g')
|
|
echo "<txt>$OUT</txt>"
|
|
echo "<tool>$TOOL</tool>"
|
|
echo "<img>/usr/share/icons/gnome/16x16/actions/format-justify-fill.png</img>"
|
|
echo "<click>xfce4-terminal -x $0 exec &</click>"
|
|
|
|
wtmp
|
|
fi
|