#!/bin/sh
# this scripts comments the line in the CCID (ifd-ccid.bundle) driver 
# and uncomments the relevant lines in the VSR(aks-ifdh,bundle) files
# the device 0529:0620 

if [ -d /usr/libexec/SmartCardServices/drivers/ifd-ccid.bundle/Contents ] ; then
	pushd . > /dev/null 2>&1
	cd /usr/libexec/SmartCardServices/drivers/ifd-ccid.bundle/Contents > /dev/null 2>&1
	arrays=""
	i=0
	for x in $(grep -n "<array>" Info.plist | cut -f1 -d:)
	do
		arrays[i]=$x
		i=`expr $i + 1`
	done

	for y in $(grep -n "0529" Info.plist | cut -f1 -d:)
	do
		sed   -e "${y}s/^\(.*\)<string>\(.*\)<\/string>/\1<\!--string>\2<\/string-->/" -i "" Info.plist
		y1=$((${arrays[1]}+y-${arrays[0]}))
		sed   -e "${y1}s/^\(.*\)<string>\(.*\)<\/string>/\1<\!--string>\2<\/string-->/" -i "" Info.plist
		y2=$((${arrays[2]}+y-${arrays[0]}))
		sed   -e "${y2}s/^\(.*\)<string>\(.*\)<\/string>/\1<\!--string>\2<\/string-->/" -i "" Info.plist
	done
	popd > /dev/null 2>&1
fi 

if [ -d /usr/libexec/SmartCardServices/drivers/aks-ifdh.bundle/Contents ] ; then
	pushd . > /dev/null 2>&1
	cd /usr/libexec/SmartCardServices/drivers/aks-ifdh.bundle/Contents > /dev/null 2>&1
	arrays=""
	i=0
	for x in $(grep -n "<array>" Info.plist | cut -f1 -d:)
	do
		arrays[i]=$x
		i=`expr $i + 1`
	done

	y=$((${arrays[1]}+5))
	sed   -e "${y}s/^\(.*\)<\!--string>\(.*\)<\/string-->/\1<string>\2<\/string>/" -i "" Info.plist
	y1=$((${arrays[2]}+5))
	sed   -e "${y1}s/^\(.*\)<\!--string>\(.*\)<\/string-->/\1<string>\2<\/string>/" -i "" Info.plist
	y2=$((${arrays[3]}+5))
	sed   -e "${y2}s/^\(.*\)<\!--string>\(.*\)<\/string-->/\1<string>\2<\/string>/" -i "" Info.plist
	popd > /dev/null 2>&1
fi 


