-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaemon.sh
executable file
·70 lines (60 loc) · 2.28 KB
/
daemon.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
#!/bin/bash
if [[ "$EUID" -ne 0 ]]; then
echo "This script must be run as root. Please use sudo."
exit 1
fi
OLD_CONTENT=""
touch /tmp/kblightd
echo "kblightd started..."
echo "Waiting for updates to /tmp/kblightd"
# yes, this is bad code but who cares (it works)s
while true; do
NEW_CONTENT="$(cat /tmp/kblightd)"
if [[ "$NEW_CONTENT" != "$OLD_CONTENT" ]]; then
if [[ "$NEW_CONTENT" =~ "effect" ]]; then
OLD_CONTENT="$NEW_CONTENT"
if [[ "$NEW_CONTENT" =~ "effect strobe" ]]; then
echo "Strobe effect detected"
while true; do
if ! kblight set 0 >/dev/null; then
echo "An error occured while trying to apply effect: strobe."
exit 1
fi
sleep 0.04
kblight set 100 >/dev/null
sleep 0.04
NEW_CONTENT="$(cat /tmp/kblightd)"
if [[ "$NEW_CONTENT" != "$OLD_CONTENT" ]]; then
break
fi
done
elif [[ "$NEW_CONTENT" =~ "effect breathe" ]]; then
echo "Breathe effect detected"
while true; do
for i in $(seq 0 1 100); do
if ! kblight set "$i" >/dev/null; then
echo "An error occured while trying to apply effect: breathe."
exit 1
fi
NEW_CONTENT="$(cat /tmp/kblightd)"
if [[ "$NEW_CONTENT" != "$OLD_CONTENT" ]]; then
break
fi
sleep 0.013
done
NEW_CONTENT="$(cat /tmp/kblightd)"
if [[ "$NEW_CONTENT" != "$OLD_CONTENT" ]]; then
break
fi
for i in $(seq 100 -1 0); do
kblight set "$i" >/dev/null
sleep 0.013
done
sleep 1
done
else
echo "Either effect set to none or unknown effect found."
fi
fi
fi
done