#!/bin/bash
#
# taken from libgphoto2
#
# Sets up newly plugged in card reader so that only members of the
# group can access it from user space. (Replace scard with the name
# of the group you want to have access to the card reader.)

GROUP=scard

# Note that for this script to work, you'll need all of the following:
# a) a line in the file /etc/hotplug/gnupg-ccid.usermap that corresponds
#    to the card reader you are using.
# b) a group "scard" where all users allowed access to the
#    card reader are listed
# c) a Linux kernel supporting hotplug and usbdevfs
# d) the hotplug package (http://linux-hotplug.sourceforge.net/)
#
# In the usermap file, the first field "usb module" should be named
# "gnupg-ccid" like this script.
#

set -e

# Only do this if x2gothinclientd is default display manager
# or if the package x2gothinclient-minidesktop is installed.
#
# Otherwise this makes no sense...

if ps ax | grep x2gothinclient | grep thinclientd 1>/dev/null || [ -d "/usr/share/doc/x2gothinclient-minidesktop" ]; then

	DEV=`echo ${DEVICE} | sed 's/proc/dev/'`

	if [ "${ACTION}" = "add" ]; then
		sleep 2
		chown :${GROUP} "${DEV}"
		chmod g+rw,o-rwx "${DEV}"
	fi

fi

exit 0
