home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / hal / scripts / hal-system-power-hibernate < prev    next >
Encoding:
Text File  |  2006-08-30  |  1.7 KB  |  68 lines

  1. #!/bin/sh
  2.  
  3. POWERSAVED_SUSPEND2DISK="dbus-send --system --dest=com.novell.powersave \
  4.                          --print-reply /com/novell/powersave \
  5.                          com.novell.powersave.action.SuspendToDisk"
  6.  
  7. unsupported() {
  8.     echo org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported >&2
  9.     echo No hibernate script found >&2
  10.     exit 1
  11. }
  12.  
  13. #SuSE and ALTLinux only support powersave
  14. if [ -f /etc/altlinux-release ] || [ -f "/etc/SuSE-release" ] ; then
  15.     if [ -x /usr/bin/powersave ] ; then
  16.             $POWERSAVED_SUSPEND2DISK
  17.         RET=$?
  18.     else
  19.         unsupported
  20.     fi
  21.  
  22. #RedHat/Fedora only support pm-utils
  23. elif [ -f /etc/redhat-release ] || [ -f /etc/fedora-release ] ; then
  24.     if [ -x /usr/sbin/pm-hibernate ] ; then
  25.         /usr/sbin/pm-hibernate
  26.         RET=$?
  27.     else
  28.         unsupported
  29.     fi
  30.  
  31. #Other distros just need to have *any* tools installed
  32. else
  33.     if [ -x "/usr/bin/powersave" ] ; then
  34.             $POWERSAVED_SUSPEND2DISK
  35.         RET=$?
  36.     elif [ -x "/usr/sbin/pmi" ] ; then
  37.         /usr/sbin/pmi action hibernate force
  38.         RET=$?
  39.     elif [ -x "/usr/sbin/pm-hibernate" ] ; then
  40.         /usr/sbin/pm-hibernate
  41.         RET=$?
  42.     elif [ -x "/usr/sbin/hibernate" ] ; then
  43.         # Suspend2 tools installed
  44.         /usr/sbin/hibernate --force
  45.         RET=$?
  46.     elif [ -w "/sys/power/state" ] &&
  47.        [  "$HAL_PROP_POWER_MANAGEMENT_TYPE" != pmu ] ; then
  48.         # Use the raw kernel sysfs interface if possible (not on pmu yet)
  49.         echo "disk" > /sys/power/state
  50.         RET=$?
  51.     else
  52.         unsupported
  53.         fi
  54.     fi
  55.  
  56. #Refresh devices as a resume can do funny things
  57. for type in button battery ac_adapter
  58. do
  59.     devices=`hal-find-by-capability --capability $type`
  60.     for device in $devices
  61.     do
  62.         dbus-send --system --print-reply --dest=org.freedesktop.Hal \
  63.               $device org.freedesktop.Hal.Device.Rescan
  64.     done
  65. done
  66.  
  67. exit $RET
  68.