#!/bin/sh

POWERSAVED_SUSPEND2DISK="dbus-send --system --dest=com.novell.powersave \
                         --print-reply /com/novell/powersave \
                         com.novell.powersave.action.SuspendToDisk"

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

if [ -x "/usr/bin/powersave" ] ; then
	$POWERSAVED_SUSPEND2DISK
	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
	unsupported
fi

exit $RET
