#!/bin/bash

# Check are you root?
whoami | egrep "^root$l" >/dev/null

if [ $? -ne 0 ]; then
  echo "Warning: You are not root!"
  echo "         Uninstall Failed!"
  exit
fi

# Check what kind of the distribution is it!
if [ -f /etc/fedora-release ]; then
  read distribution < /etc/fedora-release
  version=$(echo $distribution|cut -c1-16)  
  if [ "$version" == "Fedora release 7" ]; then
    echo $distribution
  else
    echo "Warning: Your distribution is not Fedora 7"
    echo "         Uninstall Failed!"
    exit
  fi
else
  echo "Warning: Your distribution is not Fedora 7"
  echo "         Uninstall Failed!"
  exit
fi

# Check what kind of the X Server is!
if [ -f /var/log/Xorg.0.log ]; then
  PATH_XServerConfig=$(egrep "Using config file" /var/log/Xorg.0.log|cut -d" " -f5|cut -d\" -f2)
  echo "X Window Config is in $PATH_XServerConfig"
  PATH_XServerModule=$(egrep "ModulePath set to" /var/log/Xorg.0.log|cut -d" " -f5|cut -d\" -f2)
  echo "X Window Module Path is in $PATH_XServerModule"
else
  echo "Warning: Don't know where is your X Server config file."
  echo "         Uninstall Failed!"
  exit
fi

# Start to uninstall
rm -rf /etc/etandt

rm -f "$PATH_XServerModule"/input/ETouch_drv.so

if [ -f ${PATH_XServerConfig}.bak.touch ]; then
  cp ${PATH_XServerConfig}.bak.touch $PATH_XServerConfig
  rm -f ${PATH_XServerConfig}.bak.touch
fi

rm -f /usr/local/bin/Calibration
rm -f /usr/local/bin/Lift-off
rm -f /usr/local/bin/Swap

echo "Touch Driver Uninstall OK!"

choice=" "
while [ "$choice" != "y" ]; do
echo
echo -n "Do you want to Reboot now? (y/n):"
read choice
echo
case $choice in
      y|Y) echo 'Rebooting...'
           reboot
           echo;;
      n|N) echo 'It is recommaned to reboot after driver uninstalled'
           echo
           break;;
      *) ;;
esac
done

