diag.sh 812 B

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