#!/bin/sh
#
# wdpcscd_v5     Starts the wdpcscd_v5 Daemon
#
# chkconfig:   2345 99 01
# 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: wdpcscd_v5
# config:      /etc/reader_wdv5.conf
#
### BEGIN INIT INFO
# Provides: wdpcscd_v5
# Required-Start: $local_fs $remote_fs $syslog haldaemon
# Required-Stop: $local_fs $remote_fs $syslog haldaemon
# Should-Start: openct
# Should-Stop: openct
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Daemon to access a smart card using PC/SC
# 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.
### END INIT INFO
#
# Note!  wdpcscd_v5 should be started after pcmcia, and shut down before it
# for smooth experience with PCMCIA readers.

# for Fedora , 李勃
# 启动时清除IPCDIR目录，避免因为上次关闭时没有清理导致无法启动pcscd

. /etc/init.d/functions

umask 077

TokenServerName=WDTokenServer_gdca
NAME=wdpcscd_gdca
exec=/usr/sbin/$NAME
prog=$(basename $exec)
lockfile=/var/lock/subsys/$prog
IPCDIR=/var/run/$NAME
PCSCD_OPTIONS=

# create $IPCDIR with correct access rights
rm -rf $IPCDIR
mkdir $IPCDIR
chmod a+x,a+r $IPCDIR

# Source config
if [ -f /etc/sysconfig/$NAME ] ; then
    . /etc/sysconfig/$NAME
fi

start() {
    echo -n $"Starting PC/SC smart card daemon ($prog): "
    daemon $prog $PCSCD_OPTIONS
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    
	# !!! 5.0新增加的。 李勃
	#/usr/sbin/$TokenServerName &   fedora25有权限问题，不能这么用了
	
    return $retval
}
stop() {
    echo -n $"Stopping PC/SC smart card daemon ($prog): "
    killproc $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
restart() {
    stop
    start
}


case "$1" in
    start|stop|restart)
        $1
        ;;
    reload|force-reload)
        restart
        ;;
    status)
        status $prog
        ;;
    condrestart|try-restart)
        [ ! -f $lockfile ] || restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}"
        exit 2
esac
