tpacpi-bat.initd.1 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/sbin/openrc-run
  2. # Copyright (C) 2012-2016 Christoph Junghans <junghans@gentoo.org>
  3. #
  4. # Distributed under the terms of the GNU General Public License, v2 or later
  5. extra_started_commands="low high info"
  6. BATS="1"
  7. depend() {
  8. after modules
  9. }
  10. start() {
  11. local state1
  12. ebegin "Making sure that module 'acpi_call' is loaded"
  13. modprobe acpi_call
  14. state1=$?
  15. eend ${state1}
  16. [ "${state1}" -ne "0" ] && return 1
  17. ebegin "Starting ${SVCNAME}"
  18. set_all ${TPACPI_BAT_THRESH_START} ${TPACPI_BAT_THRESH_STOP}
  19. eend $?
  20. }
  21. stop() {
  22. einfo "Nothing required to be done to stop ${SVCNAME}"
  23. }
  24. require_started() {
  25. if ! service_started; then
  26. "${RC_SERVICE}" start || return $?
  27. fi
  28. }
  29. high() {
  30. require_started
  31. einfo "Switching ${SVCNAME} to high thesholds"
  32. set_all ${TPACPI_BAT_HIGH_THRESH_START} ${TPACPI_BAT_HIGH_THRESH_STOP}
  33. }
  34. low() {
  35. require_started
  36. einfo "Switching ${SVCNAME} to low thesholds"
  37. set_all ${TPACPI_BAT_LOW_THRESH_START} ${TPACPI_BAT_LOW_THRESH_STOP}
  38. }
  39. set_all() {
  40. local tstart=$1
  41. local tstop=$2
  42. local bat
  43. for bat in ${BATS}; do
  44. ebegin " setting thresholds for ${bat}: $tstart $tstop"
  45. /usr/bin/tpacpi-bat -s startThreshold ${bat} ${tstart}
  46. /usr/bin/tpacpi-bat -s stopThreshold ${bat} ${tstop}
  47. eend $?
  48. done
  49. }
  50. info() {
  51. local tstart
  52. local tstop
  53. local bat
  54. require_started
  55. for bat in ${BATS}; do
  56. tstart=$(/usr/bin/tpacpi-bat -g startThreshold ${bat})
  57. tstop=$(/usr/bin/tpacpi-bat -g stopThreshold ${bat})
  58. einfo "Battery ${bat}: ${tstart} ${tstop}"
  59. done
  60. }