All pastes #88823 Raw Edit

Miscellany

public text v1 · immutable
#88823 ·published 2006-07-15 10:39 UTC
rendered paste body
#! /bin/bash

scriptname=$(basename "$0")
statefile=/sys/power/state
lcdfile=/proc/omnibook/lcd
lockfile=/var/lock/restabit.lock
powerlock=/var/lock/acpi_power

function usage() {
        cat >&2 <<USAGE
${scriptname} [--mem|--disk]
    --mem  Suspend-to-RAM
    --disk Suspend-to-DISK
USAGE
        exit 0
}

# Don't even bother proceeding unless we are root
if [ $EUID -ne 0 ]; then
        echo "Only root can suspend the machine :("
        exit -1
fi

# Ensure that we prevent the multiple-suspend problem some people complain and warn about...
if ! dotlockfile -l -p -r 0 "${lockfile}"; then
        echo "Another restabit process is already in progress!"
        exit -1
fi
trap "dotlockfile -u -p -r0 '${lockfile}'" EXIT

method=""

while [ $# != 0 ]; do
        case "$1" in
                --mem)
                        method="mem"
                ;;
                --disk)
                        method="disk"
                ;;
                --help)
                        usage
                ;;
        esac
        shift
done

[ -z "${method}" ] && usage

# Hack to de-activate the power button while we are suspended...
touch "${powerlock}"
trap "rm '${powerlock}'" EXIT

# Perform actual suspension ...
echo "${method}" > "${statefile}"


# Sometimes the LCDs brightness is incorrect, this attempts to fix that.
if [ -f "${lcdfile}" ]; then
        cur=$(awk '{ print $NF }' < "${lcdfile}")
        [ "${cur}" -eq 1 ] && tmp=2 || tmp=1
        echo "${tmp}" > "${lcdfile}"
        echo "${cur}" > "${lcdfile}"
fi

# For the sake of any hacks ...
sleep 1