base-files: unify get_dt_led helper function
[openwrt/staging/lynxis.git] / package / base-files / files / lib / functions / leds.sh
index 857e7e53927b04d25b7e54e6e8b3fcdc118d3a9c..83e775fada9ed303ec7acd6357500dbcd3b61903 100644 (file)
@@ -1,6 +1,18 @@
 #!/bin/sh
 # Copyright (C) 2013 OpenWrt.org
 
+get_dt_led() {
+       local label
+       local ledpath
+       local basepath="/proc/device-tree"
+       local nodepath="$basepath/aliases/led-$1"
+
+       [ -f "$nodepath" ] && ledpath=$(cat "$nodepath")
+       [ -n "$ledpath" ] && label=$(cat "$basepath$ledpath/label")
+
+       echo "$label"
+}
+
 led_set_attr() {
        [ -f "/sys/class/leds/$1/$2" ] && echo "$3" > "/sys/class/leds/$1/$2"
 }