#!/bin/bash

ACT_KERNEL=`uname -r`
GFX="LynxEM4+ Family"
OS="RHEL5.4 32bit"			#Can modify to any OS name
OS_KERNEL="2.6.27.19-5-default"  #Can modify to any kernel version


##### Driver name definition 
SMI_X_DRV="siliconmotion_drv.so"
SMI_X_CONF="xorg.conf.smi"

##### Driver path definition
LIB_PATH="/usr/lib"
LIB_PATH2="/usr/X11R6/lib"
X_PATH="/usr/lib/xorg/modules/drivers"
X_CONF_PATH="/etc/X11/xorg.conf"

check_root()
{
   USER=`whoami`
   if [ "$USER" != "root" ] ; then
	echo "Error:"
 	echo "  This script only can be executed by \"root\" user."
	echo "  Please swith user to \"root\" and try again."
	exit
   fi
}

##### Sub function - Backup system default drivers/libraries 
backup()
{
  echo "*** Backup related defualt files"

  if [ -f "$X_PATH/$SMI_X_DRV" ] ; then
     mv $X_PATH/$SMI_X_DRV $X_PATH/$SMI_X_DRV.orig
  fi
}
##### Sub function - Driver installation
drv_install()
{
  echo "*** Start to install driver binaries"

#==============================================================#

  cp ${SMI_X_DRV} ${X_PATH}
  echo "*** Driver binaries were installed!"
  
}


##### Sub function - Modify xorg.conf/modprobe.conf
modify_conf()
{
  ### Modify /etc/X11/xorg.conf
  mv ${X_CONF_PATH}  $X_CONF_PATH.orig
  cp ${SMI_X_CONF} ${X_CONF_PATH}

  echo "*** Modified!"      
}

##### Main program
echo "====== SiliconMotion $GFX Display Driver for $OS ======"
echo "====== Installation Program ======"

#if [ "${ACT_KERNEL}" != "${OS_KERNEL}" ] ; then
#   echo "Error:"
#   echo "  This driver package is only support the default kernel"
#   echo "  \"${OS_KERNEL}\" for ${OS}"
#else
   check_root
   backup
   drv_install
   modify_conf
   echo "====== Installation completed!! ======"
#fi


