hal-system-power-* scripts

Richard Hughes hughsient at gmail.com
Fri Sep 16 07:39:18 PDT 2005


After talking lots with wrobell (PLD Linux), we've come to the
conclusion that the current "filter by distro" is broken, as only a few
distros work, and may have different options installed.

We've come up with perhaps the next version of scripts:

Feedback welcome.

Richard

SUSPEND ---------------------------------------------------------------

#!/bin/sh

alarm_not_supported() {
    echo
"org.freedesktop.Hal.Device.SystemPowerManagement.AlarmNotSupported" >&2
    echo "Waking the system up is not supported" >&2
    exit 1
}

unsupported() {
    echo "org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported"
>&2
    echo "No suspend script found" >&2
    exit 1
}

read seconds_to_sleep

if [ -x /usr/bin/powersave ] ; then
    # Currently ALTLinux and SuSE
    /usr/bin/powersave --suspend-to-ram
    RET=$?
elif [ -x /usr/sbin/pmi ] ; then
    # Currently Ubuntu
    /usr/sbin/pmi action suspend force
    RET=$?
elif [ -x /usr/sbin/pm-suspend ] ; then
    # Currently RedHat and Fedora
    # TODO: fix pm-suspend to take a --wakeup-alarm argument
    if [ $seconds_to_sleep != "0" ] ; then
        alarm_not_supported
    fi
    /usr/sbin/pm-suspend
    # TODO: fixup pm-suspend to define error code (see alarm above) and
throw
    #       the appropriate exception
    RET=$?
elif [ -w /sys/power/state ] ; then
    # Use the raw kernel sysfs interface
    echo mem > /sys/power/state
    RET=$?
else
    # TODO: add other scripts support
    unsupported
    fi

exit $RET

HIBERNATE -------------------------------------------------------------

#!/bin/sh

unsupported() {
    echo "org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported"
>&2
    echo "No hibernate script found" >&2
    exit 1
}

if [ -x /usr/bin/powersave ] ; then
    # Currently ALTLinux and SuSE
    /usr/bin/powersave --suspend-to-disk
    RET=$?
elif [ -x /usr/sbin/pmi ] ; then
    # Currently Ubuntu
    /usr/sbin/pmi action hibernate force
    RET=$?
elif [ -x /usr/sbin/pm-hibernate ] ; then
    # Currently RedHat and Fedora
    /usr/sbin/pm-hibernate
    RET=$?
elif [ -x /usr/sbin/hibernate ] ; then
    # Suspend2 tools installed
    /usr/sbin/hibernate --force
    RET=$?
elif [ -w /sys/power/state ] ; then
    # Use the raw kernel sysfs interface
    echo disk > /sys/power/state
    RET=$?
else
    # TODO: add other scripts support
    unsupported
    fi

exit $RET

POWERSAVE --------------------------------------------------------------

#!/bin/sh
read value

unsupported() {
    echo "org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported"
>&2
    echo "No powersave script found" >&2
    exit 1
}

if [ -x /usr/bin/powersave ] ; then
    # Currently ALTLinux and SuSE
    if [ $value = "true" ]; then
        /usr/bin/powersave -e Powersave
        RET=$?
    elif [ $value = "false" ]; then
        /usr/bin/powersave -e Performance
        RET=$?
    fi
    RET=$?
elif [ -x /usr/sbin/pm-powersave ] ; then
    # Will be RedHat and Fedora
    /usr/sbin/pm-powersave $value
    RET=$?
else
    # TODO: add other scripts support
    unsupported
    fi

exit $RET
---------------------------------------------------------------------------




More information about the hal mailing list