#!/bin/sh

test "$ACTION" = "add" || exit 0
test -n "$DEVICE" -o -n "$DEVNAME" || exit 0 
test -e /var/run/openct/status || exit 0

# race condition in the kernel, $DEVICE might not exist now
sleep 1


if [ -n "$DEVICE" ]
then
	# if you see two ifdhandlers for one device, then you can
	# either comment out the next line here ...
	/usr/sbin/openct-control attach usb:$PRODUCT usb $DEVICE
	exit 0
fi

if [ -n "$DEVNAME" ]
then
	V="`cat /sys/$DEVPATH/device/idVendor |sed -e "s/^0*//"`"
	P="`cat /sys/$DEVPATH/device/idProduct|sed -e "s/^0*//"`"
	D="`cat /sys/$DEVPATH/device/bcdDevice |sed -e "s/^0*//"`"
	PRODUCT="$V/$P/$D"
	# or the following line. both should disable that effect.
	/usr/sbin/openct-control attach usb:$PRODUCT usb $DEVNAME
	exit 0
fi
