home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / boot / i386 / rescue / usr / lib / hal / scripts / linux / hal-system-power-hibernate-linux < prev    next >
Text File  |  2006-11-29  |  2KB  |  77 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. #Mandriva support suspend-scripts 
  14. if [ -f /etc/mandriva-release ] ; then 
  15.     if [ -x /usr/sbin/pmsuspend ] ; then 
  16.     /usr/sbin/pmsuspend disk 
  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 ] || [ -x /usr/sbin/pm-hibernate ] ; then
  24.     if [ -x /usr/sbin/pm-hibernate ] ; then
  25.          /usr/sbin/pm-hibernate
  26.         RET=$?
  27.     else
  28.         unsupported
  29.     fi
  30.  
  31. #SuSE and ALTLinux only support powersave
  32. elif [ -f /etc/altlinux-release ] || [ -f "/etc/SuSE-release" ] ; then
  33.     if [ -x /usr/bin/powersave ] ; then
  34.             $POWERSAVED_SUSPEND2DISK
  35.         RET=$?
  36.     else
  37.         unsupported
  38.     fi
  39.  
  40.  
  41. #Other distros just need to have *any* tools installed
  42. else
  43.     if [ -x "/usr/bin/powersave" ] ; then
  44.             $POWERSAVED_SUSPEND2DISK
  45.         RET=$?
  46.     elif [ -x "/usr/sbin/pmi" ] ; then
  47.         /usr/sbin/pmi action hibernate force
  48.         RET=$?
  49.     elif [ -x "/usr/sbin/pm-hibernate" ] ; then
  50.         /usr/sbin/pm-hibernate
  51.         RET=$?
  52.     elif [ -x "/usr/sbin/hibernate" ] ; then
  53.         # Suspend2 tools installed
  54.         /usr/sbin/hibernate --force
  55.         RET=$?
  56.     elif [ -w "/sys/power/state" ] ; then
  57.         # Use the raw kernel sysfs interface
  58.         echo "disk" > /sys/power/state
  59.         RET=$?
  60.     else
  61.         unsupported
  62.         fi
  63.     fi
  64.  
  65. #Refresh devices as a resume can do funny things
  66. for type in button battery ac_adapter
  67. do
  68.     devices=`hal-find-by-capability --capability $type`
  69.     for device in $devices
  70.     do
  71.         dbus-send --system --print-reply --dest=org.freedesktop.Hal \
  72.               $device org.freedesktop.Hal.Device.Rescan
  73.     done
  74. done
  75.  
  76. exit $RET
  77.