#! /bin/sh
#
### BEGIN INIT INFO
# Provides:          athcool
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:
# Description:       enable powersaving mode for Athlon/Duron processors
### END INIT INFO
#
# skeleton	example file to build /etc/init.d/ scripts.
#		This file should be used to construct scripts for /etc/init.d.
#
#		Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian 
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#               Adapted for athcool by Nicolas Boullis <nboullis@debian.org>.
#
# Version:	@(#)skeleton  1.9  26-Feb-2001  miquels@cistron.nl
#

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
PROG=/usr/sbin/athcool

test -x $PROG || exit 0

# Source the init script configuration
if [ -f "/etc/default/athcool" ]; then
    . /etc/default/athcool
fi

set -e

case "$ATHCOOL_FIXUP" in
    [yY][eE][sS])
	FIXUP="fixup"
	;;
    *)
	FIXUP=""
	;;
esac


prog_on() {
    echo -n "Enabling Athlon powersaving mode..."
    if $PROG $FIXUP on > /dev/null; then
	echo "done."
    else
	echo "failed."
    fi
}
    
prog_off() {
    echo -n "Disabling Athlon powersaving mode..."
    if $PROG off > /dev/null; then
	echo "done."
    else
	echo "failed."
    fi
}

case "$1" in
    start)
	case "$ATHCOOL_REVERSED" in
	    [yY][eE][sS])
		prog_off
		;;
	    *)
		prog_on
		;;
	esac
	;;
    stop)
	case "$ATHCOOL_REVERSED" in
	    [yY][eE][sS])
		prog_on
		;;
	    *)
		prog_off
		;;
	esac
	;;
    restart|force-reload)
	$0 stop
	$0 start
	;;
    *)
	echo "Usage: /etc/init.d/athcool {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
