1a9332327ac30ece061308a44a13873863a6df55
[openwrt/openwrt.git] / target / linux / bcm53xx / base-files / etc / diag.sh
1 #!/bin/sh
2
3 . /lib/functions/leds.sh
4
5 get_status_led() {
6 local status_led_file
7
8 # There may be more than one color of power LED, try to avoid amber/red
9 status_led_file=$(find /sys/class/leds/ -name "*:power" -a ! -name "*:amber:*" -a ! -name "*:red:*" | head -n1)
10 if [ -d "$status_led_file" ]; then
11 status_led=$(basename $status_led_file)
12 return
13 fi;
14
15 # Now just pick any power LED
16 status_led_file=$(find /sys/class/leds/ -name "*:power" | head -n1)
17 if [ -d "$status_led_file" ]; then
18 status_led=$(basename $status_led_file)
19 return
20 fi;
21 }
22
23 set_state() {
24 get_status_led
25
26 [ -z "$status_led" ] && return
27
28 case "$1" in
29 preinit)
30 status_led_blink_preinit
31 ;;
32 failsafe)
33 status_led_blink_failsafe
34 ;;
35 preinit_regular)
36 status_led_blink_preinit_regular
37 ;;
38 done)
39 status_led_on
40 ;;
41 esac
42 }