base-files: fix shell scope error for the default LED brightness
authorAndre Heider <a.heider@gmail.com>
Sat, 14 Dec 2024 10:27:09 +0000 (11:27 +0100)
committerJohn Crispin <john@phrozen.org>
Sat, 14 Dec 2024 18:51:50 +0000 (19:51 +0100)
This fixes "sh: write error: Invalid argument" for all default!=1 LEDs
as an empty $brightness was used.

Setting up LEDs via luci also now works again.

Fixes cbdfd03e: "base-files: add option to set LED brightness"
Signed-off-by: Andre Heider <a.heider@gmail.com>
Link: https://github.com/openwrt/openwrt/issues/17269
Signed-off-by: John Crispin <john@phrozen.org>
package/base-files/files/etc/init.d/led

index d292e2a8dd1557693bb2cf160ab1521777b05133..79fdd452cecc03457898bcb08224631dedbc0a10 100755 (executable)
@@ -106,9 +106,10 @@ load_led() {
                [ "$default" = 0 ] &&
                        echo 0 >/sys/class/leds/${sysfs}/brightness
 
-               [ $default = 1 ] &&
-                       [ -z "$brightness" ] && brightness=$(cat /sys/class/leds/${sysfs}/max_brightness)
-                       echo $brightness > /sys/class/leds/${sysfs}/brightness
+               [ "$default" = 1 ] && {
+                       [ -z "$brightness" ] && brightness="$(cat /sys/class/leds/${sysfs}/max_brightness)"
+                       echo "$brightness" > /sys/class/leds/${sysfs}/brightness
+               }
 
                led_color_set "$1" "$sysfs"