#!/bin/sh
read value

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

#SuSE and ALTLinux only support powersave
if [ -f /etc/altlinux-release ] || [ -f /etc/SuSE-release ] ; then
	if [ -x "/usr/bin/powersave" ] ; then
		if [ $value = "true" ]; then
			/usr/bin/powersave -e Powersave
			RET=$?
		elif [ $value = "false" ]; then
			/usr/bin/powersave -e Performance
			RET=$?
		fi
	else
		unsupported
	fi

#RedHat/Fedora only support pm-utils
elif [ -f /etc/redhat-release ] || [ -f /etc/fedora-release ] ; then
	if [ -x "/usr/sbin/pm-powersave" ] ; then
		if [ $value = "true" ]; then
			/usr/sbin/pm-powersave on
			RET=$?
		elif [ $value = "false" ]; then
			/usr/sbin/pm-powersave off
			RET=$?
		fi
	else
		unsupported
	fi

else
	# cannot set proc stuff here, so error out
	unsupported
	fi 

exit $RET

