#!/bin/sh
#
# pcscd		PC/SC Smartcard daemon
#
# chkconfig:	2345 12 88
#
# description: The PC/SC smart card daemon is a resource manager for the \
#              PC/SC lite and Musclecard frameworks.  It coordinates \
#              communications with smart card readers, smart cards, and \
#              cryptographic tokens that are connected to the system.
#
# processname: pcscd
# config:      /etc/reader.conf
#
# $Id: pcsc-lite-pcscd.init,v 1.8 2008/11/17 16:56:52 qboosh Exp $


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

umask 077

# Set defaults
LOGGING="yes"

# Get service config - may override defaults
[ -f /etc/sysconfig/pcscd ] && . /etc/sysconfig/pcscd

if is_yes "${LOGGING}"; then
	LOGOPT="-d"
else
	LOGOPT=""
fi

start() {
	if [ ! -f /var/lock/subsys/pcscd ]; then
		msg_starting pcscd
		/usr/sbin/update-reader.conf && daemon pcscd $LOGOPT
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/pcscd
	else
		msg_already_running pcscd
	fi
}

stop() {
	if [ -f /var/lock/subsys/pcscd ]; then
		msg_stopping pcscd
		killproc pcscd
		rm -f /var/lock/subsys/pcscd
	else
		msg_not_running pcscd
	fi
}

condrestart() {
	if [ -f /var/lock/subsys/pcscd ]; then
		stop
		start
	else
		msg_not_running pcscd
		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)
	# pcscd doesn't support reloading on HUP
	condrestart 7
	;;
  status)
	status pcscd
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
	exit 3
esac

exit $RETVAL

# This must be last line !
# vi:syntax=sh:tw=78:ts=8:sw=4
