summaryrefslogtreecommitdiff
path: root/src/usr/bin/netmounts-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/netmounts-trayicon
downloadstackrpms-acer-chromebook-ff8fb3958338891bc683b1ce510885f48eff4d17.tar.gz
stackrpms-acer-chromebook-ff8fb3958338891bc683b1ce510885f48eff4d17.tar.bz2
stackrpms-acer-chromebook-ff8fb3958338891bc683b1ce510885f48eff4d17.zip
initial commit
Diffstat (limited to 'src/usr/bin/netmounts-trayicon')
-rwxr-xr-xsrc/usr/bin/netmounts-trayicon68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/usr/bin/netmounts-trayicon b/src/usr/bin/netmounts-trayicon
new file mode 100755
index 0000000..932dcf1
--- /dev/null
+++ b/src/usr/bin/netmounts-trayicon
@@ -0,0 +1,68 @@
+#!/bin/sh
+# File: /usr/bin/netmounts-trayicon
+# Location: stackrpms-thinkpad-p50s package
+# Author: bgstack15
+# SPDX-License-Identifier: GPL-3.0
+# Startdate: 2022-01-07 14:15
+# Title: Net mounts Trayicon utility
+# Package: stackrpms-thinkpad-p50s
+# Purpose: Provide easy mount/unmount control for network shares from system tray
+# History:
+# 2022-11-03 adapted for package
+# Usage:
+# from ~/.fluxbox/startup
+# Reference: vpn-trayicon
+# Improve:
+# Documentation:
+# Dependencies:
+# devuan-req: mktrayicon
+
+clean_netmounts_trayicon() {
+ { test -e "${netmounts_trayicon}" && echo "q" > "${netmounts_trayicon}" ; } 1>/dev/null 2>&1 &
+ sleep 1 && rm -f "${netmounts_trayicon}" "${netmounts_KILLFILE}"
+}
+
+export netmounts_trayicon="/var/run/user/$( id -u )/${$}.netmounts.icon"
+export netmounts_KILLFILE=/tmp/kill-all-netmounts-trayicons
+
+test "ON" = "ON" && {
+ mkfifo "${netmounts_trayicon}"
+ mktrayicon "${netmounts_trayicon}" &
+ echo "m Mount net mounts,sudo /usr/bin/netmounts-on|Unmount net mounts,sudo /usr/bin/netmounts-off|quit,echo 'q' > ${netmounts_trayicon} ; touch \"${netmounts_KILLFILE}\"" > "${netmounts_trayicon}"
+ echo "i networkmanager" > "${netmounts_trayicon}"
+}
+
+rm -f "${netmounts_KILLFILE}"
+
+trap 'trap "" 2 ; touch "${netmounts_KILLFILE}" ' 2 # CTRL-C
+
+while ! test -e "${netmounts_KILLFILE}" 2>/dev/null ;
+do
+ status_now=1
+ mount | grep -qE 'nfs' && status_now=0
+ status_string="$( mount | awk '$5~/nfs/{print $3}' | tr '\n' '\r' )"
+ if test "${status_string}" != "${status_string_old}" ; then
+ echo "t ${status_string}" > "${netmounts_trayicon}"
+ fi
+ if test "${status_now}" != "${status_old}" ;
+ then
+ test -p "${netmounts_trayicon}" && case "${status_now}" in
+ 0) # netmounts is on now
+ test -n "${VPN_DEBUG}" && echo "net mounts are mounted (icon file ${netmounts_trayicon})" 1>&2
+ echo "i netmounts-on" > "${netmounts_trayicon}"
+ #echo "t netmounts is on" > "${netmounts_trayicon}"
+ ;;
+ 1) # netmounts is off now
+ test -n "${VPN_DEBUG}" && echo "netmounts are NOT mounted (icon file ${netmounts_trayicon})" 1>&2
+ echo "i netmounts-off" > "${netmounts_trayicon}"
+ echo "t no network mounts" > "${netmounts_trayicon}"
+ ;;
+ esac
+ fi
+ status_old="${status_now}"
+ status_string_old="${status_string}"
+ sleep 1
+done
+
+# safety shutoff
+clean_netmounts_trayicon
bgstack15