Browse Source

initial commit

master
mxmehl 5 years ago
commit
a581a1843d
  1. 1
      .gitignore
  2. 11
      config.cfg.sample
  3. 19
      shared.so
  4. 35
      status-ip.sh
  5. 112
      status-misc.sh

1
.gitignore

@ -0,0 +1 @@
config.cfg

11
config.cfg.sample

@ -0,0 +1,11 @@
# Default values when first starting the tool
var_conn="on"
var_mailqueue_runs=9
# status-ip.sh
IPSERV4="http://returns.plain-ipv4"
IPSERV6="http://returns.plain-ipv6"
VPNIP="1.2.3.4|90.80.70.60"
# status-misc.sh
SVNSTATUS = http://website.showing."fin;revision".or.similar

19
shared.so

@ -0,0 +1,19 @@
# SHARED FUNCTIONS AND COMMANDS
# Test if config.cfg exists and set needed variables
if [ ! -e "$CURDIR"/config.cfg ]; then echo "Missing config.cfg file. Edit and rename config.cfg.sample"; exit 1; fi
source "$CURDIR"/config.cfg
# Create temp settings file
TMP=/tmp/statusbars
if [ ! -e "$TMP" ]; then
touch "$TMP"
fi
source "$TMP"
# WRITE TMP
function wtmp {
> $TMP
echo "var_mailqueue_runs=$var_mailqueue_runs" >> $TMP
echo "var_conn=$var_conn" >> $TMP
}

35
status-ip.sh

@ -0,0 +1,35 @@
#!/bin/bash
CURDIR=$(dirname "$(readlink -f "$0")")
source "$CURDIR"/shared.so
IP=$(wget -T 5 -q -O - $IPSERV4)
EXIT="$?"
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)"
echo "<img>$IMAGE</img>"
elif ([ "$EXIT" == 4 ] || [ "$EXIT" == 6 ] || [ "$EXIT" == 28 ]); then
EXIT="fail"
TEXT="t/o"
else
TEXT="$IP"
fi
echo "<txt> $TEXT</txt>"
# If request was successful, try IPv6 as well
if [ "$EXIT" != "fail" ]; then
IP6=$(wget -T 5 -q -O - $IPSERV6)
EXIT="$?"
if ([ "$EXIT" == 4 ] || [ "$EXIT" == 6 ] || [ "$EXIT" == 28 ]); then
IP6="t/o"
fi
echo "<tool>IPv6: $IP6</tool>"
fi
else
echo "<txt>offline</txt>"
echo "<tool>Offline status is set. Turn on to enable checks</tool>"
fi

112
status-misc.sh

@ -0,0 +1,112 @@
#!/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
Loading…
Cancel
Save