mirror of
https://github.com/gSpotx2f/luci-app-internet-detector.git
synced 2025-12-31 11:56:03 +03:00
v0.3. Internet detector daemon
This commit is contained in:
14
led/etc/internet-detector/run-script
Executable file
14
led/etc/internet-detector/run-script
Executable file
@@ -0,0 +1,14 @@
|
||||
# Shell commands that are executed every time the Internet is checked for availability
|
||||
#
|
||||
# $1 : (0|1) - internet status: 0 is up, 1 is down
|
||||
#
|
||||
|
||||
LEDN=1
|
||||
LED_CMD="/usr/bin/internet-detector-led.sh"
|
||||
LED_STATE=`$LED_CMD state $LEDN`
|
||||
|
||||
if [ $LED_STATE -eq 0 -a $1 -eq 0 ]; then
|
||||
$LED_CMD on $LEDN
|
||||
elif [ $LED_STATE -ne 0 -a $1 -eq 1 ]; then
|
||||
$LED_CMD off $LEDN
|
||||
fi
|
||||
63
led/usr/bin/internet-detector-led.sh
Executable file
63
led/usr/bin/internet-detector-led.sh
Executable file
@@ -0,0 +1,63 @@
|
||||
#/bin/sh
|
||||
|
||||
#
|
||||
# Usage: internet-detector-led.sh on|off|state|list [<LED number>|<LED sysfs-name>]
|
||||
#
|
||||
# Examples:
|
||||
# internet-detector-led.sh list # list of available LEDs
|
||||
# internet-detector-led.sh on 2 # turn on LED 2
|
||||
# internet-detector-led.sh off 2 # turn off LED 2
|
||||
# internet-detector-led.sh on "nbg6817:white:internet" # turn on LED by sysfs-name (/sys/class/leds/nbg6817:white:internet)
|
||||
# internet-detector-led.sh off "nbg6817:white:internet" # turn off --"--
|
||||
# internet-detector-led.sh on # same as "internet-detector-led.sh on 1" (default <LED number> is 1)
|
||||
# internet-detector-led.sh off # turn off --"--
|
||||
# internet-detector-led.sh state 2 # current state (brightness) of LED 2
|
||||
# ...
|
||||
#
|
||||
|
||||
if [ -n $2 ]; then
|
||||
LEDN=$2
|
||||
else
|
||||
LEDN=1
|
||||
fi
|
||||
|
||||
SYSFS_LEDS="/sys/class/leds/"
|
||||
|
||||
LED="`ls -1 $SYSFS_LEDS | awk -v LEDN=$LEDN '{
|
||||
LEDN = (length(LEDN) == 0) ? 1 : LEDN;
|
||||
if($0 == LEDN || NR == LEDN) {
|
||||
print $0;
|
||||
exit;
|
||||
}
|
||||
}'`" 2> /dev/null
|
||||
|
||||
LED_BR_PATH="${SYSFS_LEDS}/${LED}/brightness"
|
||||
|
||||
[ -w $LED_BR_PATH ] || exit 1
|
||||
|
||||
MAX_BRIGHTNESS=`cat ${SYSFS_LEDS}/${LED}/max_brightness` 2> /dev/null
|
||||
|
||||
if [ -z $MAX_BRIGHTNESS ]; then
|
||||
MAX_BRIGHTNESS=1
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
on)
|
||||
printf $MAX_BRIGHTNESS > $LED_BR_PATH
|
||||
;;
|
||||
off)
|
||||
printf 0 > $LED_BR_PATH
|
||||
;;
|
||||
state)
|
||||
cat $LED_BR_PATH 2> /dev/null
|
||||
;;
|
||||
list)
|
||||
ls -1 $SYSFS_LEDS | awk '{print NR ": " $0}'
|
||||
;;
|
||||
*)
|
||||
echo "Usage: `basename $0` on|off|state|list [<LED number>|<LED sysfs-name>]" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0;
|
||||
Reference in New Issue
Block a user