#!/bin/sh
#
# pommed - Apple laptops hotkeys event handler
#
# chkconfig: 2345 36 90
# description:	pommed handles the hotkeys found on the Apple MacBook Pro \
#		and MacBook laptops and adjusts the LCD backlight, sound \
#		volume, keyboard backlight or ejects the CD-ROM drive \
#		accordingly.
# processname: pommed
# config: /etc/pommed.conf
# pidfile: /var/run/pommed.pid
### BEGIN INIT INFO
# Provides:       pommed
# Required-Start: $local_fs messagebus
# Required-Stop:  $local_fs messagebus
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6
# Short-Description: Apple laptops hotkeys event handler
# Description: pommed handles the hotkeys found on the Apple MacBook Pro \
#              and MacBook laptops and adjusts the LCD backlight, sound \
#              volume, keyboard backlight or ejects the CD-ROM drive \
#              accordingly.
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

PIDFILE=/var/run/pommed.pid
LOCKFILE=/var/lock/subsys/pommed
RETVAL=0

start()
{
	action "Loading applesmc kernel module:" modprobe applesmc
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- pommed
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- pommed
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	restart
} 

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user root -- pommed
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
