#!/bin/bash
#
# Install Script for the OMNIKEY CardMan CCID Smartcard reader series.
#
# Version 1.2.0 
# OMNIKEY AG
# http://www.omnikey.com
#

echo
echo Installing OMNIKEY CardMan USB CCID Smartcard reader driver ...
echo

#
# check if pcsc-lite is installed
#
pcsclib=""
if [ -f /usr/lib/libpcsclite-core.so ]; then
  pcsclib=/usr/lib
elif [ -f /usr/local/lib/libpcsclite-core.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 [ -f /usr/local/lib/libpcsclite.so ]; then
  pcsclib=/usr/local/lib
elif [ -f /usr/local/lib/libpcsclite.a ]; then
  pcsclib=/usr/local/lib
else
  echo PCSC-Lite is not installed.
  echo Go visit http://www.linuxnet.com
  echo and install the latest version of pcsc-lite.
fi

if [ "${pcsclib}" != "" ]; then

#
# copy the pcsc-shared library to its proper place
#
  if [ "$1" = "-d" ]; then
    dropdir=$2
  fi

  if [ "${dropdir}" = "" ]; then
    dropdir="/usr/local/pcsc/drivers/"
  fi

  if [ ! -d "$dropdir" ]; then 
    mkdir -p $dropdir
  fi

 # Delete older driver versions
  rm -rf ${dropdir}/ifdokccid*;

  bundle=`ls -A | grep -e *.bundle`;
  echo Copying ${bundle} to ${dropdir} ...
  cp -r ./${bundle} ${dropdir}

else
  echo Skiping installation of driver files!
fi

echo
echo Installation finished!
