Browse Source

outsource interaction part to separate file; better name scheming; update default status values; small improvements

master
mxmehl 6 years ago
parent
commit
42e41f3968
  1. 6
      config.cfg.sample
  2. 4
      shared-functions.so
  3. 66
      status-interaction.sh
  4. 15
      status-ip.sh
  5. 102
      status-misc.sh

6
config.cfg.sample

@ -1,6 +1,12 @@ @@ -1,6 +1,12 @@
# Status file
TMP=/tmp/status
# Default values when first starting the tool
var_conn="on"
var_mailqueue_runs=9
var_ip4=127.0.0.1
var_ip6=::1
var_vpn="off"
# status-ip.sh
IPSERV4="http://returns.plain-ipv4"

4
shared.so → shared-functions.so

@ -5,7 +5,6 @@ if [ ! -e "$CURDIR"/config.cfg ]; then echo "Missing config.cfg file. Edit and r @@ -5,7 +5,6 @@ if [ ! -e "$CURDIR"/config.cfg ]; then echo "Missing config.cfg file. Edit and r
source "$CURDIR"/config.cfg
# Create temp settings file
TMP=/tmp/statusbars
if [ ! -e "$TMP" ]; then
touch "$TMP"
fi
@ -16,4 +15,7 @@ function wtmp { @@ -16,4 +15,7 @@ function wtmp {
> $TMP
echo "var_mailqueue_runs=$var_mailqueue_runs" >> $TMP
echo "var_conn=$var_conn" >> $TMP
echo "var_ip4=$var_ip4" >> $TMP
echo "var_ip6=$var_ip6" >> $TMP
echo "var_vpn=$var_vpn" >> $TMP
}

66
status-interaction.sh

@ -0,0 +1,66 @@ @@ -0,0 +1,66 @@
#!/bin/bash
CURDIR=$(dirname "$(readlink -f "$0")")
source "$CURDIR"/shared-functions.so
# MAIL QUEUE ACTIONS
function send_mailqueue { # send queued mails
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 { # list emails in queue only
msmtp-listqueue.sh
}
# 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

15
status-ip.sh

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
#!/bin/bash
CURDIR=$(dirname "$(readlink -f "$0")")
source "$CURDIR"/shared.so
source "$CURDIR"/shared-functions.so
IP=$(wget -T 5 -q -O - $IPSERV4)
EXIT="$?"
@ -10,12 +10,16 @@ if [ "$var_conn" == "on" ]; then @@ -10,12 +10,16 @@ if [ "$var_conn" == "on" ]; then
if $(echo $IP | grep -qE "$VPNIP"); then
IMAGE="/usr/share/icons/gnome/16x16/apps/gnome-monitor.png"
TEXT="VPN ($IP)"
var_ip4="$IP"
var_vpn="on"
echo "<img>$IMAGE</img>"
elif ([ "$EXIT" == 4 ] || [ "$EXIT" == 6 ] || [ "$EXIT" == 28 ]); then
EXIT="fail"
TEXT="t/o"
else
TEXT="$IP"
var_ip4="$IP"
var_vpn="off"
fi
echo "<txt> $TEXT</txt>"
@ -25,11 +29,16 @@ if [ "$var_conn" == "on" ]; then @@ -25,11 +29,16 @@ if [ "$var_conn" == "on" ]; then
IP6=$(wget -T 5 -q -O - $IPSERV6)
EXIT="$?"
if ([ "$EXIT" == 4 ] || [ "$EXIT" == 6 ] || [ "$EXIT" == 28 ]); then
IP6="t/o"
TEXT="t/o"
else
TEXT="$IP6"
var_ip6="$IP6"
fi
echo "<tool>IPv6: $IP6</tool>"
echo "<tool>IPv6: $TEXT</tool>"
fi
else
echo "<txt>offline</txt>"
echo "<tool>Offline status is set. Turn on to enable checks</tool>"
fi
wtmp # Write changes back

102
status-misc.sh

@ -1,35 +1,21 @@ @@ -1,35 +1,21 @@
#!/bin/bash
CURDIR=$(dirname "$(readlink -f "$0")")
source "$CURDIR"/shared.so
source "$CURDIR"/shared-functions.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
# ONLINE STATUS
function isonline {
if [ "$var_conn" = "off" ]; then
return 1
else
return 0
fi
}
# NUMBER OF UNSENT EMAILS
function check_mailqueue {
QUEUE=$(msmtp-listqueue.sh | grep -o "^From: " | wc -l)
OUT="$OUT;mq=$QUEUE"
@ -45,35 +31,6 @@ function check_mailqueue { @@ -45,35 +31,6 @@ function check_mailqueue {
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 {
if isonline; then
@ -93,33 +50,16 @@ function check_svn { @@ -93,33 +50,16 @@ function check_svn {
TOOL="$TOOL;svn=$SVN_REV"
}
function isonline {
if [ "$var_conn" = "off" ]; then
return 1
else
return 0
fi
}
# OUTPUT INFO ON STATUSBAR
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 $CURDIR/status-interaction.sh &</click>"
# 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
wtmp

Loading…
Cancel
Save