base-files: don't wipe LED state when adding a single LED
authorDaniel Golle <daniel@makrotopia.org>
Sat, 5 Oct 2024 17:20:35 +0000 (18:20 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Mon, 7 Oct 2024 00:41:32 +0000 (01:41 +0100)
Only replace LED state of a single LED instead of removing the entire
/var/run/led.state file.

Fixes: 511e8f84d0 ("base-files: configure LED when added")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
package/base-files/files/etc/init.d/led

index 5130ac7d41bb7e074310fdd6b7dfbcfac2f959fb..7f05254c2ba3a30f474ddb50f50a5c272d92c044 100755 (executable)
@@ -184,7 +184,12 @@ start() {
                                        echo "$color" | sed 's/:/\ /g' > \
                                                "/sys/class/leds/$led/multi_intensity"
                        done < /var/run/led.state
-                       rm /var/run/led.state
+                       if [ "$1" ]; then
+                               grep -v "^$1 " /var/run/led.state > /var/run/led.state.new
+                               mv /var/run/led.state.new /var/run/led.state
+                       else
+                               rm /var/run/led.state
+                       fi
                }
 
                config_load system