#!/bin/sh
#
# name        : apmd-compat
# author      : Guido Guenther <agx@sigxcpu.org>
# description : Execute scripts in /etc/apm for compatibility
#
# --- end of public part -- don't change below this line ---

. pmcs-config

[ -d "/etc/apm" ] || exit 0

case "$2" in
  battery)
	if [ -x /etc/apm/apmd_proxy ]; then 
		/etc/apm/apmd_proxy change power
	else
		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
	fi
  ;;
  ac)
	if [ -x /etc/apm/apmd_proxy ]; then 
		/etc/apm/apmd_proxy change power
	else
		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
	fi
  ;;
esac

case "$1" in
  suspend)
	if [ -x /etc/apm/apmd_proxy ]; then 
		/etc/apm/apmd_proxy $1 user
	else	
		run-parts --arg=$1 --arg=user /etc/apm/event.d
		if [ -d /etc/apm/$1.d ]; then
        		run-parts --arg=$1 --arg=user /etc/apm/$1.d
	    	fi
	fi
  ;;
  resume)
	if [ -x /etc/apm/apmd_proxy ]; then 
		/etc/apm/apmd_proxy $1 suspend
	else	
		run-parts --arg=$1 --arg=suspend /etc/apm/event.d
		if [ -d /etc/apm/$1.d ]; then
			run-parts --arg=$1 --arg=suspend /etc/apm/$1.d
	    	fi
	fi
  ;;
esac
