diff --git a/config.cfg.sample b/config.cfg.sample
index 25df78e..12435f3 100644
--- a/config.cfg.sample
+++ b/config.cfg.sample
@@ -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"
diff --git a/shared.so b/shared-functions.so
similarity index 81%
rename from shared.so
rename to shared-functions.so
index d51da04..5a98b18 100644
--- a/shared.so
+++ b/shared-functions.so
@@ -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 {
> $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
}
diff --git a/status-interaction.sh b/status-interaction.sh
new file mode 100755
index 0000000..b553dcf
--- /dev/null
+++ b/status-interaction.sh
@@ -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
diff --git a/status-ip.sh b/status-ip.sh
index 988ccff..6a70b8e 100755
--- a/status-ip.sh
+++ b/status-ip.sh
@@ -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
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 "
$IMAGE"
elif ([ "$EXIT" == 4 ] || [ "$EXIT" == 6 ] || [ "$EXIT" == 28 ]); then
EXIT="fail"
TEXT="t/o"
else
TEXT="$IP"
+ var_ip4="$IP"
+ var_vpn="off"
fi
echo " $TEXT"
@@ -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 "IPv6: $IP6"
+ echo "IPv6: $TEXT"
fi
else
echo "offline"
echo "Offline status is set. Turn on to enable checks"
fi
+
+wtmp # Write changes back
diff --git a/status-misc.sh b/status-misc.sh
index 08fa182..9d002cc 100755
--- a/status-misc.sh
+++ b/status-misc.sh
@@ -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 {
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 {
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 "$OUT"
+echo "$TOOL"
+echo "
/usr/share/icons/gnome/16x16/actions/format-justify-fill.png"
+echo "xfce4-terminal -x $CURDIR/status-interaction.sh &"
-# 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 "$OUT"
- echo "$TOOL"
- echo "
/usr/share/icons/gnome/16x16/actions/format-justify-fill.png"
- echo "xfce4-terminal -x $0 exec &"
-
- wtmp
-fi
+wtmp