battery.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #! /bin/sh -
  2. #
  3. # /usr/libexec/acpi/battery.sh
  4. #
  5. # written by Frank Dietrich <ablesoft@gmx.de>
  6. #
  7. # based on default.sh in the acpid package
  8. # Detect AC connector plugged in or unplugged and take appropriated actions.
  9. #
  10. # On my notebook no event triggered if AC connector plugged in or unplugged.
  11. # So I will use the battery event to detect new powerstate.
  12. # get the AC connector state from /proc filesystem.
  13. STATE=`sed -n 's/^.*\(off\|on\)-line.*/\1/p' /proc/acpi/ac_adapter/ACAD/state`
  14. case "$STATE" in
  15. on)
  16. # AC connector plugged in
  17. # make an entry in /var/log/daemon.log
  18. logger "acpid: AC connector plugged in."
  19. # deactivate standby (spindown) timeout for the drive
  20. /sbin/hdparm -q -S 0 /dev/hda
  21. ;;
  22. off)
  23. # AC connector unplugged
  24. logger "acpid: AC connector unplugged."
  25. # activate standby (spindown) timeout for the drive
  26. # timeout 5 minutes (man hdparm, for more informations)
  27. /sbin/hdparm -q -S 60 /dev/hda
  28. ;;
  29. *)
  30. # AC connector in undetermined state
  31. logger "acpid: Could not determine new AC connector state."
  32. ;;
  33. esac