#!/bin/sh
echo -n "IT8212 Driver Installation."
if [ ! -f modules.cgz ]; then
   echo "failed"
   echo "This is not IT8212 Driver Disk for Turbo Linux"
   exit 1
fi

if [ -d /tmp/.ft_mod ]; then
   rm -rf /tpm/.ft_mod
fi
mkdir -p /tmp/.ft_mod

cp -f modules.cgz /tmp/.ft_mod
if [ $? -ne 0 ]; then
   echo "failed"
   echo "Runtime error..setup abort!!(disk full or no permission?)"
   exit 1
fi
cd /tmp/.ft_mod
echo -n "."

zcat modules.cgz |cpio -id >/dev/null 2>&1
if [ $? -ne 0 ]; then
   echo "failed"
   echo "Runtime error..setup abort!!(corrupt file)"
   exit 1
fi
echo -n "."

for i in `\ls -d *`
do
    if [ ! -d /lib/modules/${i} ]; then
       continue
    fi
    
    cp -f ${i}/iteraid.o /lib/modules/${i}/kernel/drivers/scsi/ >/dev/null 2>&1
    echo -n "."

done

if [ -f /etc/lilo.conf ]; then
   if [ ! -f /etc/lilo.conf.orig ]; then
      cp -f /etc/lilo.conf /etc/lilo.conf.orig >/dev/null 2>&1
   fi
fi
##GRUB
if [ -f /boot/grub/grub.conf ]; then
   if [ ! -f /boot/grub/grub.conf.orig ]; then
      cp -f /boot/grub/grub.conf /boot/grub/grub.conf.orig >/dev/null 2>&1
   fi
fi

echo -n "."

if grep 'BOOT_IMAGE' /proc/cmdline >/dev/null 2>&1; then
   lilo >/dev/null 2>&1
fi
echo -n "."

echo "done"

depmod -a >/dev/null 2>&1
insmod iteraid >/dev/null 2>&1

RC=`grep 'rc.modules$' /etc/rc.d/rc.sysinit`
if ! grep '^insmod iteraid' ${RC} >/dev/null 2>&1; then
   echo -n "Do you want to bind IT8212 module into linux booting?(Y/N) "
   read key

   case ${key} in
       Y|y)
           echo "" >> `echo ${RC}`
           echo "#ITE IT8212 Driver" >> `echo ${RC}`
           echo "insmod iteraid >/dev/null 2>&1" >> `echo ${RC}`
           chmod 755 ${RC}
           ;;
       N|n)
           echo ""
           echo "The iteraid driver module can be loaded automatically"
           echo "by appending the following command to ${RC}"
           echo ""
           echo "   insmod iteraid"
           ;;
       *)
         echo ""
         ;;
   esac
fi
echo ""
echo "setup is complete."
echo ""
echo "-------------------------------"
echo "Integrated Technology Express, Inc (C)2003"
