10-usb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2009-2010 OpenWrt.org
  4. #
  5. # This is free software, licensed under the GNU General Public License v2.
  6. # See /LICENSE for more information.
  7. #
  8. usb_led=''
  9. usb_device=''
  10. led_set_attr() {
  11. [ -f "/sys/class/leds/$1/$2" ] && echo "$3" > "/sys/class/leds/$1/$2"
  12. }
  13. usb_led_set_timer() {
  14. led_set_attr "${usb_led}" 'trigger' 'timer'
  15. led_set_attr "${usb_led}" 'delay_on' "$1"
  16. led_set_attr "${usb_led}" 'delay_off' "$2"
  17. }
  18. usb_led_on() {
  19. led_set_attr "${usb_led}" 'trigger' 'none'
  20. led_set_attr "${usb_led}" 'brightness' 255
  21. }
  22. usb_led_off() {
  23. led_set_attr "${usb_led}" 'trigger' 'none'
  24. led_set_attr "${usb_led}" 'brightness' 0
  25. }
  26. get_usb_led() {
  27. local hardware=`sed -n /Hardware/s/.*:.//p /proc/cpuinfo`
  28. case "${hardware}" in
  29. 'Linksys WRT350N v2')
  30. usb_led='wrt350nv2:green:usb'
  31. usb_device='1-1:1.0'
  32. ;;
  33. esac;
  34. }
  35. get_usb_led
  36. case "${ACTION}" in
  37. add)
  38. # update LEDs
  39. [ "${usb_device}" = "${DEVICENAME}" ] && usb_led_on
  40. ;;
  41. remove)
  42. # update LEDs
  43. [ "${usb_device}" = "${DEVICENAME}" ] && usb_led_off
  44. ;;
  45. esac