summaryrefslogtreecommitdiff
path: root/src/usr/bin/vpn-trayicon
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2022-11-03 19:00:04 -0400
committerB. Stack <bgstack15@gmail.com>2022-11-03 19:28:46 -0400
commitff8fb3958338891bc683b1ce510885f48eff4d17 (patch)
tree7142a4061d50de6475763e4b2443ee6c2ebe3f70 /src/usr/bin/vpn-trayicon
downloadstackrpms-thinkpad-p50s-ff8fb3958338891bc683b1ce510885f48eff4d17.tar.gz
stackrpms-thinkpad-p50s-ff8fb3958338891bc683b1ce510885f48eff4d17.tar.bz2
stackrpms-thinkpad-p50s-ff8fb3958338891bc683b1ce510885f48eff4d17.zip
initial commit
Diffstat (limited to 'src/usr/bin/vpn-trayicon')
-rwxr-xr-xsrc/usr/bin/vpn-trayicon63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/usr/bin/vpn-trayicon b/src/usr/bin/vpn-trayicon
new file mode 100755
index 0000000..224e5cc
--- /dev/null
+++ b/src/usr/bin/vpn-trayicon
@@ -0,0 +1,63 @@
+#!/bin/sh
+# File: /usr/bin/vpn-trayicon
+# Location: stackrpms-thinkpad-p50s package
+# Author: bgstack15
+# SPDX-License-Identifier: GPL-3.0
+# Startdate: 2021-12-26 21:10
+# Title: Vpn Trayicon utility
+# Package: stackrpms-thinkpad-p50s
+# Purpose: Provide easy vpn control from system tray
+# History:
+# 2022-11-03 adapted for package
+# Usage:
+# On demand, run vpn-trayicon
+# Reference: keyboard-leds-trayicons
+# Improve:
+# Documentation:
+# for some stupid reason sudo /usr/local/bin/vpn-on doesn't work, so I just use the real commands here.
+# Dependencies:
+# devuan-req: mktrayicon
+
+clean_vpn_trayicon() {
+ { test -e "${vpn_trayicon}" && echo "q" > "${vpn_trayicon}" ; } 1>/dev/null 2>&1 &
+ sleep 1 && rm -f "${vpn_trayicon}" "${vpn_KILLFILE}"
+}
+
+export vpn_trayicon="/var/run/user/$( id -u )/${$}.vpn.icon"
+export vpn_KILLFILE=/tmp/kill-all-vpn-trayicons
+
+test "ON" = "ON" && {
+ mkfifo "${vpn_trayicon}"
+ mktrayicon "${vpn_trayicon}" &
+ echo "m Turn vpn on,sudo wg-quick up wg0|Turn vpn off,sudo wg-quick down wg0|quit,echo 'q' > ${vpn_trayicon} ; touch \"${vpn_KILLFILE}\"" > "${vpn_trayicon}"
+ echo "i networkmanager" > "${vpn_trayicon}"
+}
+
+rm -f "${vpn_KILLFILE}"
+
+trap 'trap "" 2 ; touch "${vpn_KILLFILE}" ' 2 # CTRL-C
+
+while ! test -e "${vpn_KILLFILE}" 2>/dev/null ;
+do
+ ip -o a s wg0 1>/dev/null 2>&1 ; status_now=$? ;
+ if test "${status_now}" != "${status_old}" ;
+ then
+ test -p "${vpn_trayicon}" && case "${status_now}" in
+ 0) # vpn is on now
+ test -n "${VPN_DEBUG}" && echo "vpn is on (icon file ${vpn_trayicon})" 1>&2
+ echo "i vpn-on" > "${vpn_trayicon}"
+ echo "t vpn is on" > "${vpn_trayicon}"
+ ;;
+ 1) # vpn is off now
+ test -n "${VPN_DEBUG}" && echo "vpn is off (icon file ${vpn_trayicon})" 1>&2
+ echo "i vpn-off" > "${vpn_trayicon}"
+ echo "t vpn is off" > "${vpn_trayicon}"
+ ;;
+ esac
+ fi
+ status_old="${status_now}"
+ sleep 1
+done
+
+# safety shutoff
+clean_vpn_trayicon
bgstack15