-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinet-hg680p.sh
74 lines (64 loc) · 1.23 KB
/
inet-hg680p.sh
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
#!/bin/bash
# HG680P GPIO Wrapper
# by Lutfa Ilham
# mod by Adi Putra
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
SERVICE_NAME="Internet Indicator"
function loop() {
while true; do
hg680p.sh -lan warn
if curl -X "HEAD" --connect-timeout 3 -so /dev/null "http://www.gstatic.com/generate_204"; then
hg680p.sh -lan on
else
hg680p.sh -lan off
fi
sleep 1
done
}
function loop2() {
while true; do
hg680p.sh -power on
if curl -X "HEAD" --connect-timeout 3 -so /dev/null "http://www.gstatic.com/generate_204"; then
hg680p.sh -power warn
else
hg680p.sh -power off
fi
sleep 1
done
}
function start() {
echo -e "Starting ${SERVICE_NAME} service ..."
screen -AmdS internet-indicator "${0}" -l ; sleep 2;
screen -AmdS internet-indicator "${0}" -ll
}
function stop() {
echo -e "Stopping ${SERVICE_NAME} service ..."
kill $(screen -list | grep internet-indicator | awk -F '[.]' {'print $1'})
}
function usage() {
cat <<EOF
Usage:
-r Run ${SERVICE_NAME} service
-s Stop ${SERVICE_NAME} service
EOF
}
case "${1}" in
-l)
loop
;;
-ll)
loop2
;;
-r)
start
;;
-s)
stop
;;
*)
usage
;;
esac