#! /bin/sh
# pmud	       Power Manager daemon for Apple powerbooks
#
# chkconfig: 2345 40 60
# description: pmud is a daemon which periodically polls the PMU \
#              (power manager) and performs functions such as enabling \
#              or disabling devices appropriately when the power source \
#              changes.
# processname: pmud
#
### BEGIN INIT INFO
# Provides: apmd
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 5
# Default-Stop:
# Description: APM-Daemon
### END INIT INFO

. /etc/rc.config

base=${0##*/}
link=${base#*[SK][0-9][0-9]}

test $link = $base && START_PMUD=yes
test "$START_PMUD" = yes || exit 0

return=$rc_done

# Source power daemon options
[ -f /etc/sysconfig/power ] && . /etc/sysconfig/power

# See how we were called.
case "$1" in
  start)
	echo -n "Starting pmud daemon: "
	pmud $PMUD_FLAGS
	echo -e "$return"
	touch /var/lock/subsys/pmud
	;;
  stop)
	echo -n "Stopping pmud daemon: "
	killproc pmud
	echo -e "$return"
	rm -f /var/lock/subsys/pmud
	;;
  restart|reload)
	$0 stop && $0 start || return=$rc_failed
	;;
  status)
	checkproc /sbin/pmud && echo "OK" || echo "pmud down"
	;;
  *)
	echo "Usage: pmud {start|stop|restart|reload|status}"
	exit 1
esac

test "$return" = "$rc_done" || exit 1
exit 0
