#!/bin/bash
###########################################################################
#                                                                         #
#                         Powersave Daemon                                #
#                                                                         #
#          Copyright (C) 2004,2005 SUSE Linux Products GmbH               #
#                                                                         #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the   #
# Free Software Foundation; either version 2 of the License, or (at you   #
# option) any later version.                                              #
#                                                                         #
# This program is distributed in the hope that it will be useful, but     #
# WITHOUT ANY WARRANTY; without even the implied warranty of              #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       #
# General Public License for more details.                                #
#                                                                         #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., #
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA                  #
#                                                                         #
###########################################################################

# 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

. $SYSCONF_DIR/sleep
HWCLOCK="/sbin/hwclock"
OPT="--hctosys"

# blank the "suspend console"
deallocvt 63

case "$1" in
    suspend2disk)
	echo disk > /sys/power/state
	RET=$?
	[ "$SUSPEND2DISK_RESTORE_CLOCK" == "yes" ] && $HWCLOCK $OPT
	;;
    suspend2ram)
	echo mem > /sys/power/state
	RET=$?
	[ "$SUSPEND2RAM_RESTORE_CLOCK" == "yes" ] && $HWCLOCK $OPT
	;;
    standby)
	echo standby > /sys/power/state
	RET=$?
	[ "$STANDBY_RESTORE_CLOCK" == "yes" ] && $HWCLOCK $OPT
	;;
    *)  echo "Wrong parameter in $0"
	RET=126
	;;
esac
exit $RET
