#!/bin/sh
#
# 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' /
#  'suspend'     prepare for suspend to RAM (sleep)
#  'resume'      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
# Logging is done by the pbbuttonsd daemon.

case "$1" in
  emergency)
    shutdown -h now "Low battery - system will go down now!"
    ;;
  *)
    cd `dirname $0`
    [ -d ${1}.d ] && run-parts --arg="$1" --arg="$2" ${1}.d
    run-parts --arg="$1" --arg="$2" event.d
    ;;
esac

exit 0

