#! /bin/sh
#
# iamt    Bring up/down Intel(R) Active Management Technology service
#
# chkconfig: 2345 10 90
# description: Bring up/down Intel(R) Active Management Technology service \
#              and create/remove the relevant /dev node.
#
# Copyright(c) 2004 - 2005 Intel Corporation. All rights reserved.
#

### BEGIN INIT INFO
# Provides:          iamt
# Required-Start:
# Should-Start:
# Required-Stop:
# Should-Stop:
# Default-Start:     2 3 5
# Default-Stop:      0 1 6
# Short-Description: Bring up/down Intel(R) Active Management Technology service
# Description: Bring up/down Intel(R) Active Management Technology service
#	and create/remove the relevant /dev node.
### END INIT INFO

. /etc/rc.status

# Reset status of this service
rc_reset

driver="iamt"
node="/dev/iamthif"

case "$1" in
    start)
	echo -n "Bringing up iamt driver:"

	modprobe ${driver}

	if [ $? != 0 ]; then
		rc_failed 1
		rc_status -v
		exit 1
	fi

	rc_status -v

	major=`cat /proc/devices | grep ${driver} | awk '{print $1}'`
	if [ "${major}" = "" ]; then
		echo "Error: can't find driver's major number"
		exit 1
	fi

	if [ -c ${node} ] ; then
		rm -f ${node}
	fi

	echo -n "Setting ${node} node:"

	mknod ${node} c ${major} 0

	if [ $? != 0 ]; then
		rc_failed 1
	fi

	rc_status -v
	;;
    stop)
	if [ -c ${node} ]; then
		echo -n "Removing ${node} node:"
		rm -f ${node}
		rc_status -v
	fi

	if [ `lsmod | grep ${driver} | awk '{print $1}'` ]; then
		echo -n "Shutting down iamt driver:"
		rmmod ${driver}
		rc_status -v
	fi
	;;
    reload|restart)
	## Stop the service and regardless of whether it was
	## running or not, start it again.
	$0 stop
	$0 start

	# Remember status and be quiet
	rc_status
	;;
    *)
	echo "Usage: $0 {start|stop|restart|reload}"
	exit 1
	;;
esac
rc_exit

