#!/bin/bash
#
# This script is invoked by pbbuttonsd to configure the system for a
# given power level. The script gets two arguments:
# The first argument is a command and could contain 
#  'powersave'   \
#  'custom'       power policies transfered to slave scripts
#  'performance' /
#  'sleep'       prepare for suspend to RAM (sleep)
#  'wakeup'      after wakeup
#  'emergency'   battery is critically low -> shutdown.
#
# The second argument contains the current powersource of the laptop
#  'ac'
#  'battery'
#
# The command 'emergency' is handled directly. All other commands
# will be transfered to the slave scripts which hopefully will do
# the work.

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

case "$1" in
  emergency)
    wall "Low battery - system will go down now!"
    shutdown -h now
    ;;
  *)
    cd `dirname $0`
    run-parts --arg="$1" --arg="$2" active
    ;;
esac

exit 0

