summaryrefslogtreecommitdiff
path: root/src/usr/bin/netmounts-trayicon
blob: 932dcf1e7701150aa4531cfade444332d6abc779 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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