base-files: maintain LED config state

Record the state of any hardware LED configured through UCI and use that
information to revert the state when applying updated settings while
maintaining default behaviour of system LEDs.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2016-06-08 10:14:27 +02:00
parent 98d418e05f
commit 35b33f0413

View file

@ -37,6 +37,12 @@ load_led() {
[ -e /sys/class/leds/${sysfs}/brightness ] && { [ -e /sys/class/leds/${sysfs}/brightness ] && {
echo "setting up led ${name}" echo "setting up led ${name}"
printf "%s %s %d\n" \
"$sysfs" \
"$(sed -ne 's/^.*\[\(.*\)\].*$/\1/p' /sys/class/leds/${sysfs}/trigger)" \
"$(cat /sys/class/leds/${sysfs}/brightness)" \
>> /var/run/led.state
[ "$default" = 0 ] && [ "$default" = 0 ] &&
echo 0 >/sys/class/leds/${sysfs}/brightness echo 0 >/sys/class/leds/${sysfs}/brightness
@ -103,11 +109,17 @@ load_led() {
start() { start() {
[ -e /sys/class/leds/ ] && { [ -e /sys/class/leds/ ] && {
local led [ -s /var/run/led.state ] && {
for led in /sys/class/leds/*; do local led trigger brightness
[ -e "$led/trigger" ] && echo "none" > "$led/trigger" while read led trigger brightness; do
[ -e "$led/brightness" ] && echo "0" > "$led/brightness" [ -e "/sys/class/leds/$led/trigger" ] && \
done echo "$trigger" > "/sys/class/leds/$led/trigger"
[ -e "/sys/class/leds/$led/brightness" ] && \
echo "$brightness" > "/sys/class/leds/$led/brightness"
done < /var/run/led.state
rm /var/run/led.state
}
config_load system config_load system
config_foreach load_led led config_foreach load_led led