-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatwork
More file actions
executable file
·116 lines (100 loc) · 2.88 KB
/
atwork
File metadata and controls
executable file
·116 lines (100 loc) · 2.88 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/sh
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2025 Jeremy Brubaker <jbru362@gmail.com>
#
# abstract-atwork: Return true if WiFi is connected to anything in $WORK_SSID
# abstract-atworkd: Daemon to set status for atwork to query
#
# Defaults {{{1
#
if [ "$(id -u)" -eq 0 ]; then
ATWORK_DIR=/run/atwork
else
ATWORK_DIR=${XDG_RUNTIME_DIR:-${XDG_CACHE_HOME:-"$HOME/.cache"}}/atwork
fi
mkdir -p $ATWORK_DIR
ATWORK_FILE=$ATWORK_DIR/atwork
ATWORK_PID_FILE=$ATWORK_DIR/atwork.pid
# Documentation {{{1
#
VERSION='1.0'
print_help() (
[ -n "$1" ] && printf "%s\n" "$1"
case $(basename "$0") in
atwork)
cat <<END
Usage: $0 [OPTION]
Check if connected to an SSID found in \$WORK_SSID
-h display this help and exit
-V output version information and exit
END
;;
atworkd)
cat <<END
Usage: $0 [OPTION]
Continually check if connected to an SSID found in \$WORK_SSID
-h display this help and exit
-V output version information and exit
END
;;
esac
) >&2
print_version() (
cat <<END
$0 $VERSION
Copyright (C) 2025 Orion Arts
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Jeremy Brubaker.
END
) >&2
# Process options {{{1
#
while getopts ':hV' c; do
case $c in
h) print_help; exit 0 ;;
V) print_version; exit 0 ;;
?) print_help "Invalid option: -$OPTARG"; exit 1 ;;
esac
done
shift $((OPTIND-1))
OPTIND=1
# Main {{{1
#
case $(basename $0) in
atwork)
if kill -0 "$(cat "$ATWORK_PID_FILE")" 2>/dev/null; then
[ -f "$ATWORK_FILE" ]
else
printf 'atworkd not running. To be safe you are currently "at work"\n' >&2
true
fi
;;
atworkd)
trap 'rm -f $ATWORK_PID_FILE $ATWORK_FILE' EXIT
echo $$ > "$ATWORK_PID_FILE"
while true; do
if echo "$WORK_SSID" | grep -qs \
"\<$(nmcli dev wifi show 2>/dev/null | grep SSID | cut -d' ' -f2)\>"; then
touch "$ATWORK_FILE"
else
rm -f "$ATWORK_FILE"
fi
sleep 10
done
;;
esac