#!/bin/sh
#
# This shell script is called by the APM daemon (apmd) when the state
# of any power management function has changed.  The exact events that
# trigger the calling of apmd_proxy depend on how apmd was configured
# at compile time.
#
# Here are the calling sequences for apmd_proxy:
#
# apmd_proxy start              - APM daemon has started
# apmd_proxy stop               - APM daemon is shutting down
# apmd_proxy suspend system     - APM system has requested suspend mode
# apmd_proxy suspend critical   - APM system indicates critical suspend
# apmd_proxy standby system     - APM system has requested standby mode 
# apmd_proxy suspend user       - User has requested suspend mode
# apmd_proxy standby user       - User has requested standby mode
# apmd_proxy resume suspend     - System has resumed from suspend mode
# apmd_proxy resume standby     - System has resumed from standby mode
# apmd_proxy resume critical    - System has resumed from critical suspend
# apmd_proxy change battery     - APM system reported low battery
# apmd_proxy change power       - APM system reported AC/battery change
# apmd_proxy change time        - APM system reported need for time update
# apmd_proxy change capability  - APM system reported config. change
#

PATH=/bin:/sbin:/usr/bin:/usr/sbin

on_ac_power >/dev/null && PWR=ac || PWR=battery
cd `dirname $0`

case "$1" in
  start)
    if [ "$PWR" = "battery" ]; then
      run-parts --arg="powersave" --arg="$PWR" event.d
    else
      run-parts --arg="performance" --arg="$PWR" event.d
    fi
    ;;
  change)
    case "$2" in
      battery)
        wall "Low battery - system will go down now!"
        ;;
      power)
        if [ "$PWR" = "battery" ]; then
          run-parts --arg="powersave" --arg="$PWR" event.d
	else
          run-parts --arg="performance" --arg="$PWR" event.d
	fi
        ;;
    esac
    ;;
  suspend|standby)
    [ -d suspend.d ] && run-parts --arg="suspend" --arg="$PWR" --arg="ram" suspend.d
    run-parts --arg="suspend" --arg="$PWR" --arg="ram" event.d
    ;;
  resume)
    [ -d resume.d ] && run-parts --arg="resume" --arg="$PWR" --arg="ram" resume.d
    run-parts --arg="resume" --arg="$PWR" --arg="ram" event.d
    ;;
esac


