base-files: configure LED when added
authorDaniel Golle <daniel@makrotopia.org>
Thu, 3 Oct 2024 15:25:36 +0000 (16:25 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Thu, 3 Oct 2024 22:05:24 +0000 (23:05 +0100)
Currently LED configuration is only carried out once during boot.
Apply LED configuration also with a hotplug call when a new LED gets
added later.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
package/base-files/files/etc/hotplug.d/leds/00-init [new file with mode: 0644]
package/base-files/files/etc/init.d/led

diff --git a/package/base-files/files/etc/hotplug.d/leds/00-init b/package/base-files/files/etc/hotplug.d/leds/00-init
new file mode 100644 (file)
index 0000000..0303e2b
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+[ "$ACTION" = "add" ] && /etc/init.d/led start "$DEVICENAME"
index ea2688cab29efaf74ad8ed0c08f6e571511fb19b..5130ac7d41bb7e074310fdd6b7dfbcfac2f959fb 100755 (executable)
@@ -64,6 +64,8 @@ load_led() {
        config_get gpio $1 gpio "0"
        config_get_bool inverted $1 inverted "0"
 
+       [ "$2" ] && [ "$sysfs" != "$2" ] && return
+
        # execute application led trigger
        [ -f "/usr/libexec/led-trigger/${trigger}" ] && {
                . "/usr/libexec/led-trigger/${trigger}"
@@ -121,7 +123,7 @@ load_led() {
                                        [ -e "/sys/class/leds/${sysfs}/$m" ] && \
                                                echo 1 > /sys/class/leds/${sysfs}/$m
                                done
-                               echo $interval > /sys/class/leds/${sysfs}/interval
+                               echo $interval > /sys/class/leds/${sysfs}/interval 2>/dev/null
                        }
                        ;;
 
@@ -171,6 +173,7 @@ start() {
                [ -s /var/run/led.state ] && {
                        local led trigger brightness color
                        while read led trigger brightness color; do
+                               [ "$1" ] && [ "$1" != "$led" ] && continue
                                [ -e "/sys/class/leds/$led/trigger" ] && \
                                        echo "$trigger" > "/sys/class/leds/$led/trigger"
 
@@ -185,6 +188,6 @@ start() {
                }
 
                config_load system
-               config_foreach load_led led
+               config_foreach load_led led "$1"
        }
 }