#!/bin/sh # File: /usr/bin/vpn-trayicon # Location: stackrpms-acer-chromebook package # Author: bgstack15 # SPDX-License-Identifier: GPL-3.0 # Startdate: 2021-12-26 21:10 # Title: Vpn Trayicon utility # Package: stackrpms-acer-chromebook # 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: # dep-devuan: 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