#!/bin/bash
### BEGIN INIT INFO
# Provides: pcscd
# Required-Start:    udev
# Required-Stop:     udev
# X-Start-Before:    uevent
# Should-Start:      $syslog
# Should-Stop:       $syslog
# Default-Start:     3 4 5
# Default-Stop:
# Short-Description: Daemon to access a smart card using PC/SC
# Description:       The PC/SC daemon is used to dynamically
#                    allocate/deallocate reader drivers at runtime and manage
#                    connections to the readers.
### END INIT INFO

. /etc/init.d/functions
. /etc/init.d/template

NAME=pcscd
IPCDIR=/var/run/pcscd
PIDFILE="$IPCDIR/$NAME.pid"
ARGS="--lockfile $LOCKFILE --pidfile $PIDFILE --name $NAME"


start()
{
	# create $IPCDIR with correct access rights
	[ -d "$IPCDIR" ] ||
		mkdir -- "$IPCDIR"
	chmod 0755 "$IPCDIR"

	start_daemon $ARGS -- "$NAME"

	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon $ARGS --retry 3 -- "$NAME"
	RETVAL="$?"
	return $RETVAL
}

switch "${1-}"
