#!/bin/sh
#
# openct	OpenCT card service
#
# chkconfig:	2345 37 65
#
# description:	OpenCT is a library for accessing smart card terminals.

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

start() {
	if [ ! -f /var/lock/subsys/openct ]; then
		show "Initializing OpenCT status"
		busy
		openct-control init
		RETVAL=$?
		if [ $RETVAL -eq 0 ]; then
			ok
			touch /var/lock/subsys/openct
		else
			fail
		fi
	else
		msg_already_running openct
	fi
}

stop() {
	if [ -f /var/lock/subsys/openct ]; then
		show "Shutting down OpenCT"
		busy
		openct-control shutdown >/dev/null
		ok
		rm -f /var/lock/subsys/openct /var/run/openct/* >/dev/null 2>&1
	else
		msg_not_running openct
	fi
}

condrestart() {
	if [ -f /var/lock/subsys/openct ]; then
		stop
		start
	else
		msg_not_running openct
		RETVAL=$1
	fi
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  force-reload)
	condrestart 7
	;;
  status)
	status openct
	RETVAL=$?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
	exit 3
	;;
esac

exit $RETVAL
