-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
led-indicator
executable file
·47 lines (41 loc) · 1.24 KB
/
led-indicator
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
#!/bin/bash
# this one could make good use of trap
# other interesting triggers are possible, see
# grep LEDS_TRIGGER /boot/config-$(uname -r)
# ls /lib/modules/$(uname -r)/kernel/drivers/leds/trigger/
# modprobe what-you-want
# echo what-you-want > /sys/class/leds/*capslock/trigger
# for details refer to https://github.com/torvalds/linux/tree/master/drivers/leds/trigger
if [ ! 0 -eq `id -u` ]; then
echo "must run as root"
exit 1
fi
# if the keyboard has only one LED, blink only that
lsusb |grep Apple.*Keyboard >/dev/null
if [ $? = 0 ]; then CYCLOP=1; else CYCLOP=0; fi
for a in setleds sleep; do
hash $a >/dev/null
if [ ! $? -eq 0 ]; then
echo $a not found
exit 1
fi
done
if [ $CYCLOP = 1 ]; then
while (sleep $(echo 1 - $(date +.%N)|bc -l)); do
setleds -L +caps < /dev/console
sleep 0.1
setleds -L -caps < /dev/console
done
else
while (sleep $(echo 1 - $(date +.%N)|bc -l)); do
setleds -L +num < /dev/console
sleep 0.1
setleds -L -num < /dev/console
setleds -L +caps < /dev/console
sleep 0.1
setleds -L -caps < /dev/console
setleds -L +scroll < /dev/console
sleep 0.1
setleds -L -scroll < /dev/console
done
fi