You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.4 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2008-2011 OpenWrt.org
  3. START=50
  4. append_bool() {
  5. local section="$1"
  6. local option="$2"
  7. local value="$3"
  8. local _val
  9. config_get_bool _val "$section" "$option" '0'
  10. [ "$_val" -gt 0 ] && append args "$3"
  11. }
  12. append_string() {
  13. local section="$1"
  14. local option="$2"
  15. local value="$3"
  16. local _val
  17. config_get _val "$section" "$option"
  18. [ -n "$_val" ] && append args "$3 $_val"
  19. }
  20. compute_seconds() {
  21. local interval="$1"
  22. local unit="$2"
  23. if [ -z "$interval" ]
  24. then
  25. interval=10
  26. fi
  27. if [ -z "$unit" ]
  28. then
  29. unit="minutes"
  30. fi
  31. # compute interval in seconds
  32. case "$unit" in
  33. "days" )
  34. interval_seconds=$(($interval*60*60*24))
  35. ;;
  36. "hours" )
  37. interval_seconds=$(($interval*60*60))
  38. ;;
  39. "minutes" )
  40. interval_seconds=$(($interval*60))
  41. ;;
  42. "seconds" )
  43. interval_seconds=$interval
  44. ;;
  45. * )
  46. # default is minutes
  47. interval_seconds=$(($interval*60))
  48. ;;
  49. esac
  50. echo $interval_seconds
  51. }
  52. start_service() {
  53. local section="$1"
  54. args=""
  55. config_get "interval" "$section" "idle_time_interval"
  56. config_get "unit" "$section" "idle_time_unit"
  57. append_string "$section" "disk" "-a"
  58. config_get_bool "enabled" "$section" "enabled" '1'
  59. [ "$enabled" -gt 0 ] || return 1
  60. service_start /usr/bin/hd-idle $args -i "$(compute_seconds $interval $unit)"
  61. }
  62. start() {
  63. config_load "hd-idle"
  64. config_foreach start_service "hd-idle"
  65. }
  66. stop() {
  67. service_stop /usr/bin/hd-idle
  68. }