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-suspend-linux < prev   
Text File  |  2006-11-29  |  3KB  |  112 lines

  1. #!/bin/sh
  2.  
  3. POWERSAVED_SUSPEND2RAM="dbus-send --system --dest=com.novell.powersave \
  4.                         --print-reply /com/novell/powersave \
  5.                         com.novell.powersave.action.SuspendToRam"
  6.  
  7. alarm_not_supported() {
  8.     echo org.freedesktop.Hal.Device.SystemPowerManagement.AlarmNotSupported >&2
  9.     echo Waking the system up is not supported >&2
  10.     exit 1
  11. }
  12.  
  13. unsupported() {
  14.     echo org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported >&2
  15.     echo No suspend method found >&2
  16.     exit 1
  17. }
  18.  
  19. read seconds_to_sleep
  20.  
  21. #PMU systems cannot use /sys/power/state yet, so use a helper to issue an ioctl
  22. if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "pmu" ]; then
  23.     hal-system-power-pmu sleep
  24.     if [ $? -ne 0 ]; then
  25.         echo "org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported" >&2
  26.         exit 1
  27.     fi
  28.     exit 0
  29. fi
  30.  
  31. #Mandriva supports suspend-scripts 
  32. if [ -f "/etc/mandriva-release" ] ; then 
  33.     # TODO: fix pmsuspend to take a --wakeup-alarm argument 
  34.     if [ $seconds_to_sleep != "0" ] ; then 
  35.     alarm_not_supported 
  36.     fi 
  37.     
  38.     if [ -x "/usr/sbin/pmsuspend" ] ; then 
  39.     /usr/sbin/pmsuspend memory
  40.     RET=$? 
  41.     else 
  42.         # TODO: add support 
  43.     unsupported 
  44.     fi 
  45.  
  46. #RedHat/Fedora only support pm-utils
  47. elif [ -f "/etc/redhat-release" ] || [ -f "/etc/fedora-release" ] || [ -x /usr/sbin/pm-suspend ] ; then
  48.      # TODO: fix pm-suspend to take a --wakeup-alarm argument
  49.     if [ $seconds_to_sleep != "0" ] ; then
  50.         alarm_not_supported
  51.     fi
  52.     # TODO: fixup pm-suspend to define erroc code (see alarm above) and throw
  53.     #       the appropriate exception
  54.     if [ -x "/usr/sbin/pm-suspend" ] ; then
  55.         /usr/sbin/pm-suspend
  56.         RET=$?
  57.     else
  58.         # TODO: add support
  59.         unsupported
  60.     fi
  61.  
  62. #SuSE and ALTLinux only support powersave
  63. elif [ -f "/etc/altlinux-release" ] || [ -f "/etc/SuSE-release" ] ; then
  64.     if [ -x /usr/bin/powersave ] ; then
  65.          $POWERSAVED_SUSPEND2RAM
  66.         RET=$?
  67.     else
  68.         # TODO: add support
  69.         unsupported
  70.     fi
  71.  
  72.  
  73. #FreeBSD uses zzz to suspend for both ACPI and APM
  74. elif [ "x`uname -s`" = "xFreeBSD" ] ; then
  75.     if [ -x /usr/sbin/zzz ] ; then
  76.         /usr/sbin/zzz
  77.         RET=$?
  78.     else
  79.         unsupported
  80.     fi
  81.  
  82. #Other distros just need to have *any* tools installed
  83. else
  84.     if [ -x "/usr/bin/powersave" ] ; then
  85.         $POWERSAVED_SUSPEND2RAM
  86.         RET=$?
  87.     elif [ -x "/usr/sbin/pmi" ] ; then
  88.         /usr/sbin/pmi action suspend force
  89.         RET=$?
  90.     elif [ -w "/sys/power/state" ] ; then
  91.         # Use the raw kernel sysfs interface
  92.         echo "mem" > /sys/power/state
  93.         RET=$?
  94.     else
  95.         # TODO: add other scripts support
  96.         unsupported
  97.         fi
  98.     fi
  99.  
  100. #Refresh devices as a resume can do funny things
  101. for type in button battery ac_adapter
  102. do
  103.     devices=`hal-find-by-capability --capability $type`
  104.     for device in $devices
  105.     do
  106.         dbus-send --system --print-reply --dest=org.freedesktop.Hal \
  107.               $device org.freedesktop.Hal.Device.Rescan
  108.     done
  109. done
  110.  
  111. exit $RET
  112.