#!/bin/bash
#
# Install Script for the  USB Smartcard reader series.
#
#
# check if module for this Kernel version exists
#
echo 
echo uninstall epass1000 driver
echo

#check whether the current user is root
if test $(id -ur) != 0; then
	echo
	echo "You should logon as root user!"
	echo 
	exit -1
fi


if [ -f Makefile ]; then
 make uninstall; make clean
 if [ $? != 0 ]; then
  echo Could not uninstall driver-module, exiting
  exit -1
 fi
fi

#
# check if pcsc-lite is installed
#
shlib=libifd_eps1k.so

if [ -f /usr/lib/libpcsclite.so ]; then
  pcsclib=/usr/lib
elif [ -f /usr/local/lib/libpcsclite.so ]; then
  pcsclib=/usr/local/lib
elif [ -d /usr/pcsc/lib ]; then
  pcsclib=/usr/pcsc/lib
elif [ -d /usr/local/pcsc/lib ]; then
  pcsclib=/usr/local/pcsc/lib
elif [ -d /usr/lib/pcsc ];then
  pcsclib=/usr/lib/pcsc 
fi

#
# uninstall the pcsc-shared library to its proper place
#
rm -rf $pcsclib/$shlib

declare -i start=0;
declare -i end=0;

start=`grep "FT VR1000" /etc/reader.conf -n | head -1 | cut -f1 -d:` 
while [ $start != 0 ];
do
mv /etc/reader.conf /etc/reader.bak
end=start+4
cat /etc/reader.bak|sed "$start","$end"d > /etc/reader.conf
start=`grep "FT VR1000" /etc/reader.conf -n | head -1 | cut -f1 -d:` 
rm -f /etc/reader.bak
done

echo 
echo Uninstall init-script
echo

iname=eps1k
if [ -f /etc/redhat-release ]; then
  rh=1
  initdir=/etc/init.d
  rlvldir=/etc/rc.d
  rm -rf $initdir/$iname
elif [ -f /etc/SuSE-release ]; then
  sus=1
  initdir=/etc/init.d
  rlvldir=/etc/init.d
  rm -rf $initdir/$iname
else
  initdir=/etc/init.d
  rlvldir=/etc
  rm -rf $initdir/$iname
fi
declare -i i=2
while [ $i -lt 6 ]; do
rm -rf $rlvldir/rc$i.d/*$iname;
  i=$((i+1))
done

# Finally, unload the kernel module
echo Attempting to remove $iname kernel module
/sbin/rmmod epass 2>/dev/null
echo "uninstall finished"
