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-suspend < prev    next >
Encoding:
Text File  |  2006-08-30  |  2.3 KB  |  91 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.  
  22. #SuSE and ALTLinux only support powersave
  23. if [ -f "/etc/altlinux-release" ] || [ -f "/etc/SuSE-release" ] ; then
  24.     if [ -x /usr/bin/powersave ] ; then
  25.             $POWERSAVED_SUSPEND2RAM
  26.         RET=$?
  27.     else
  28.         # TODO: add support
  29.         unsupported
  30.     fi
  31.  
  32. #RedHat/Fedora only support pm-utils
  33. elif [ -f "/etc/redhat-release" ] || [ -f "/etc/fedora-release" ] ; then
  34.     # TODO: fix pm-suspend to take a --wakeup-alarm argument
  35.     if [ $seconds_to_sleep != "0" ] ; then
  36.         alarm_not_supported
  37.     fi
  38.     # TODO: fixup pm-suspend to define erroc code (see alarm above) and throw
  39.     #       the appropriate exception
  40.     if [ -x "/usr/sbin/pm-suspend" ] ; then
  41.         /usr/sbin/pm-suspend
  42.         RET=$?
  43.     else
  44.         # TODO: add support
  45.         unsupported
  46.     fi
  47.  
  48. #Other distros just need to have *any* tools installed
  49. else
  50.     if [ -x "/usr/bin/powersave" ] ; then
  51.         $POWERSAVED_SUSPEND2RAM
  52.         RET=$?
  53.     elif [ -x "/usr/sbin/hibernate" ] ; then
  54.         # Use hibernate configured for suspend-to-ram
  55.         /usr/sbin/hibernate -F/etc/hibernate/ram.conf
  56.         RET=$?
  57.     elif [ -x "/usr/sbin/pmi" ] ; then
  58.         /usr/sbin/pmi action suspend force
  59.         RET=$?
  60.     elif  [ "$HAL_PROP_POWER_MANAGEMENT_TYPE" = "pmu" ]; then
  61.         #PMU systems cannot use /sys/power/state yet, so use a helper to issue an ioctl
  62.         hal-system-power-pmu sleep
  63.         RET=$?
  64.     elif [ -w "/sys/power/state" ] ; then
  65.         # Use the raw kernel sysfs interface
  66.         echo "mem" > /sys/power/state
  67.         RET=$?
  68.     else
  69.         # TODO: add other scripts support
  70.         unsupported
  71.         fi
  72.     fi
  73.  
  74. if [ $RET -ne 0 ]; then
  75.     echo "org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported" >&2
  76.     exit 1
  77. fi
  78.  
  79. #Refresh devices as a resume can do funny things
  80. for type in button battery ac_adapter
  81. do
  82.     devices=`hal-find-by-capability --capability $type`
  83.     for device in $devices
  84.     do
  85.         dbus-send --system --print-reply --dest=org.freedesktop.Hal \
  86.               $device org.freedesktop.Hal.Device.Rescan
  87.     done
  88. done
  89.  
  90. exit $RET
  91.