#!/bin/sh

CHIPCARDC_CONF=/etc/chipcard/client/chipcardc.conf
CHIPCARD_TOOL="/usr/bin/chipcard-tool"
lcc_resmgr=$(sed -n 's/^\s*char\s\+resmgr="\([^"]\+\)"/\1/p' $CHIPCARDC_CONF)


exec >&3
if [ ! -z $lcc_resmgr ]; then
	echo "Configured resource manager in $(basename $CHIPCARDC_CONF) is: $lcc_resmgr"
fi

if [ "$lcc_resmgr" != "pcsc" ]; then
	if [ -x $CHIPCARD_TOOL ]; then
	        echo 'Available chipcard readers (output of "chipcard-tool list"):'
		$CHIPCARD_TOOL list | sed -e '/^Server:.*$/d'
	else
		echo "$CHIPCARD_TOOL is not executable. No information available."
	fi
fi

dpkg-query -f='Status of package pcscd (${Version}): ${Status}' --show pcscd
if [ -x /usr/bin/pgrep ]; then
	if [ "$(pgrep -cU root pcscd)" = "1" ]; then
		echo " and apparently running"
	else
		echo " and apparently stopped"
	fi
else	# simply terminate the line
	echo
fi
