From bc2e9052af84664a2caae0581aa745d09240b160 Mon Sep 17 00:00:00 2001
From: John Crispin <john@phrozen.org>
Date: Mon, 19 Apr 2021 13:49:20 +0200
Subject: [PATCH 29/43] base-files: add a turnoff command to the led script

Signed-off-by: John Crispin <john@phrozen.org>
---
 package/base-files/files/etc/init.d/led | 29 +++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/package/base-files/files/etc/init.d/led b/package/base-files/files/etc/init.d/led
index 8d97515d52..c402428e40 100755
--- a/package/base-files/files/etc/init.d/led
+++ b/package/base-files/files/etc/init.d/led
@@ -3,6 +3,10 @@
 
 START=96
 
+extra_command "turnon" "Put the LEDs into their default state"
+extra_command "turnoff" "Turn all LEDs off"
+extra_command "blink" "Blink all LEDs"
+
 load_led() {
 	local name
 	local sysfs
@@ -122,7 +126,32 @@ load_led() {
 	}
 }
 
+turnoff() {
+	for led in `ls /sys/class/leds/`; do
+		echo none > /sys/class/leds/$led/trigger
+		echo 0 > /sys/class/leds/$led/brightness
+	done
+}
+
+turnon() {
+	turnoff
+	. /etc/diag.sh
+	set_state done
+	start
+}
+
+blink() {
+	for led in `ls /sys/class/leds/`; do
+		echo 0 > /sys/class/leds/$led/brightness
+		echo timer > /sys/class/leds/$led/trigger
+	done
+}
+
 start() {
+	[ "$(uci -q get system.@system[-1].leds_off)" = '1' ] && {
+		turnoff
+		exit 0
+	}
 	[ -e /sys/class/leds/ ] && {
 		[ -s /var/run/led.state ] && {
 			local led trigger brightness
-- 
2.25.1

