99hd-apm-restore 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # vim:noexpandtab
  3. #
  4. # Author: Till Maas <opensource till name>
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  15. source "${PM_FUNCTIONS}"
  16. source /etc/pm/config.d/hd-apm-restore.conf
  17. HD_APM_DEVICES=""
  18. for udi in $(hal-find-by-capability --capability storage)
  19. do
  20. drive_type=$(hal-get-property --udi "${udi}" --key storage.drive_type)
  21. if [ "${drive_type}" == "disk" ]
  22. then
  23. HD_APM_DEVICES+="$(hal-get-property --udi "${udi}" --key block.device | sed 's,^/dev/,,') "
  24. fi
  25. done
  26. case "$1" in
  27. hibernate|suspend)
  28. for DEVICE in ${HD_APM_DEVICES}
  29. do
  30. HD_APM_FEATURE=$(hdparm -I "/dev/${DEVICE}" | grep "Advanced Power Management feature set")
  31. if [[ "${HD_APM_FEATURE}" != "" ]]
  32. then
  33. if (echo "${HD_APM_FEATURE}" | grep -q "*" )
  34. then
  35. HD_APM_LEVEL=$(hdparm -I "/dev/${DEVICE}" | grep "Advanced power management level" | cut -d" " -f 5)
  36. else
  37. HD_APM_LEVEL=255
  38. fi
  39. if [[ "${HD_APM_LEVEL}" != "unknown" ]]
  40. then
  41. echo "saving level ${HD_APM_LEVEL} for device ${DEVICE}"
  42. savestate "${DEVICE}" "${HD_APM_LEVEL}"
  43. else
  44. echo "Advanced Power Management value of device ${DEVICE} unknown"
  45. fi
  46. else
  47. echo "Advanced Power Management not supported by device ${DEVICE}."
  48. fi
  49. done
  50. ;;
  51. thaw|resume)
  52. for DEVICE in ${HD_APM_DEVICES}
  53. do
  54. HD_APM_LEVEL=$(restorestate "${DEVICE}")
  55. if [[ "${HD_APM_LEVEL}" != "" ]]
  56. then
  57. echo "restoring level ${HD_APM_LEVEL} for device ${DEVICE}"
  58. hdparm -B "${HD_APM_LEVEL}" "/dev/${DEVICE}"
  59. fi
  60. done
  61. ;;
  62. *)
  63. ;;
  64. esac
  65. exit $?