# FRITZ!Card USB v2

card=usb2
loadfile1=fus2base.frm
loadfile2=fus3base.frm
pid1="1000"
pid2="1900"

BLACKFLAG=1

SCRIPTDIR=/etc/hotplug/usb

get_version () {

	local v0=`cat $1 | tr $ \\\\n | grep -a -e Version -e Revision | tr -d " "`
	local v1=`echo "$v0" | grep Version | cut -d: -f2`
	local v2=`echo "$v0" | grep Project | cut -d: -f2`

	echo1 "$1, version $v1 ($v2)"
}

initialize() {

	local ver
	local nver
	if test -f /proc/bus/usb/devices; then
		echo1 "USB bus check:"
		local ID="P:.*Vendor=057c.*ProdID=1[09]00"
		if ! cat /proc/bus/usb/devices | grep "$ID" >> $LOGFILE 2>&1; then
			echo2 ""
			echo2 "FRITZ!Card USB v2.x not found! Please attach"
			echo2 "FRITZ!Card USB v2.x and restart this installer"
			echo2 "again..."
			echo2 ""
			return 1
		fi
		ver=`cat /proc/bus/usb/devices | grep "^S:.*Product=FRITZ" | cut -d" " -f5`
		nver=`cat /proc/bus/usb/devices | grep "^S:.*Product=FRITZ" | wc -l`
		if [ $nver -ne 1 ]; then
			echo2 ""
			echo2 "Found more than one FRITZ!Card! You can only"
			echo2 "run one passive CAPI controller. Please remove"
			echo2 "the second controller and restart the installer"
			echo2 "again..."
			echo2 ""
			return 2
		fi
		if [ "$ver" != "v2.0" -a "$ver" != "v2.1" ]; then
			echo2 ""
			echo2 "Found unknown controller..."
			echo2 ""
			return 3
		fi
	else
		echo2 ""
		echo2 "Could not find USB information - USB available?"
		echo2 ""
		return 4
	fi

	return 0
}

install_card() {

	get_version $loadfile1
	get_version $loadfile2
}


finalize() {

	echo -e "\nReady."
}

