#!/bin/bash
#
# This script is invoked by pbbuttonsd to configure the system for a
# given power level. The script gets two arguments:
# $1 = 'profile', 'sleep' or 'wakeup'
# $2 = 'ac' or 'battery'
#
# The first argument tells the script that power profile has changed,
# the machine is preparing for sleep or has waken up again.
# The second argument contains the currently active power source.
#
# This script is a special wrapper based on the debian apmd-proxy
# script to be able to use the debian apm scripts with pbbuttonsd.
# This script was developed by
#      (c) 2004  Soeren Sonnenburg <bugreports@nn7.de>
# and kindly contributed to the pbbuttonsd package.

logger=/usr/bin/logger

$logger -p daemon.info -t pwrctl-local "$@"

case "$1" in
sleep)
	run-parts --arg="suspend" --arg="power" /etc/apm/event.d
	if [ -d /etc/apm/suspend.d ]; then
		run-parts --arg="suspend" --arg="power" /etc/apm/suspend.d
	fi
	;;
wakeup)
	if [ -d /etc/apm/resume.d ]; then
		run-parts --arg="resume" --arg="suspend" /etc/apm/resume.d
 	fi
	run-parts --arg="resume" --arg="suspend" /etc/apm/event.d
	;;
*)
	run-parts --arg="change" --arg="power" /etc/apm/event.d
	if [ -d /etc/apm/other.d ]; then
		run-parts --arg="change" --arg="power" /etc/apm/other.d
	fi

# this section is for special configurations only. Everything should
# be handled correctly by the scripts in /etc/apm. If in doubt write
# correnspondent scripts for /ets/apm instead of putting code here.
#	case "$2" in
#	ac)
#		/etc/power/laptop-mode.sh stop
#		/etc/init.d/overclock start
#		/etc/power/pwrctl maximum "$2"
#		;;
#	battery)
#		/etc/power/laptop-mode.sh start
#		/etc/init.d/overclock stop
#		/etc/power/pwrctl minimum "$2"
#		;;
#	*)
#		/etc/power/pwrctl $@
#		;;
#	esac

	;;
esac
exit 0
