#!/bin/bash
# invoke acpi suspend and APM suspend to disk
#   the name of this script is a leftover from non-APM days...
# 
# return codes:
#   0 - successfully suspended
#   1 - error suspending
# 126 - unknown parameter

if [ -z "$1" ];then
    echo "This script is invoked by the powersave daemon, do not invoke from console"
    exit 126
fi

# blank the "suspend console"
deallocvt 63

case "$1" in
    suspend2disk)
	echo disk > /sys/power/state
	RET=$?
	;;
    suspend2ram)
	echo mem > /sys/power/state
	RET=$?
	;;
    standby)
	echo standby > /sys/power/state
	RET=$?
	;;
    *)  echo "Wrong parameter in $0"
	RET=126
	;;
esac
exit $RET
