Files
dynamic-status/status-interaction.sh

67 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
CURDIR=$(dirname "$(readlink -f "$0")")
source "$CURDIR"/shared-functions.so
# MAIL QUEUE ACTIONS
function send_mailqueue { # send queued mails
$MSMTP_LIST
read -p "Send these queued mails? [Y/n]: " YN
if [[ $YN =~ ^(Y|y|)$ ]]; then
$MSMTP_RUN
else
echo "Not sending emails"
fi
}
function list_mailqueue { # list emails in queue only
$MSMTP_LIST
}
# CHANGE ONLINE STATUS
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
}
# OPTION SCREEN
function exec {
ACTIONS=("send mails in queue" "list mails in queue" "switch connection status [$var_conn]" "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
}
while :; do # endless loop
exec # interaction screen
wtmp; source "$TMP" # write changes back and load them
echo # empty line
done