#!/bin/sh
KERN=`uname -r | sed 's/BOOT//'`
KERN_VER=$1
KERN_DIR=$1$4
DRIVER=sii6512
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \\033[0;39m"
INIDIR=$PWD

# changes depending when your run
# e.g. /mnt/sysimage/root at fresh install time
#      or /root if run after installation
# WKR =/mnt/sysimage/root
WK=$2
WKR=/root
SUSE=$3

$SETCOLOR_NORMAL
echo "########################################################"
echo "#         Silicon Image SATARaid controller            #"
echo "#               RedHatLinux  Driver                    #"
echo "########################################################"
echo ""

echo "you are running $KERN  version of kernel (it may not matter)"
$SETCOLOR_WARNING
echo "Trying to find the correct driver for kernel $KERN_DIR"
echo "              THIS IS THE TARGET KERNEL"
$SETCOLOR_NORMAL
echo "MUST BE ROOT TO RUN THIS PROGRAM"
#echo "add 'smp' or 'custom' if necessary."
echo "Current working directory will be $WKR root if you have not rebooted"
#echo "e.g.  'sh ./setup-update smp' "
echo "Type carriage return to continue"
read nothing

echo "installing.."

mkdir -p $WKR/$DRIVER
cd       $WKR/$DRIVER
cp    $INIDIR/$SUSE/$DRIVER.o $PWD 
echo  "copying $INIDIR/$SUSE/$DRIVER.o $PWD "
mkdir -p $WKlib/modules/$KERN_DIR/kernel/drivers/scsi/$DRIVER.o
cp -f ./$DRIVER.o $WKlib/modules/$KERN_DIR/kernel/drivers/scsi/$DRIVER.o

echo "Modifying $WK/etc/sysconfig/kernel to include sii6512"
retry1:
if [ -f $WKetc/sysconfig/kernel ];then
    echo "file $WKetc/sysconfig/kernel detected..."
    sed -f $INIDIR/addsii.sed $WKetc/sysconfig/kernel > /tmp/ker.tmp
    echo "----------------------------------ORIGINAL FILE --------------------------------------"
    cat $WKetc/sysconfig/kernel
    echo "---------------------------------NEW KERNEL FILE -------------------------------------"
    cat /tmp/ker.tmp
    echo "--------------------------------------------------------------------------------------"
    echo ""
    echo "Type carriage return to continue.."
    read nothing
    mv -f $WKetc/sysconfig/kernel $WKetc/sysconfig/kernel.old
    mv -f /tmp/ker.tmp  $WKetc/sysconfig/kernel
else
    $SETCOLOR_FAILURE
    echo "FATAL error.. file $WKetc/sysconfig/kernel NOT FOUND.."
    read nothing
    goto retry1
fi

mkinitrd 
echo "Type carriage return to continue.."
read nothing

echo "$DRIVER is now inside the bootable kernel image"

$SETCOLOR_WARNING
echo "##########################################################"
echo "#       EJECT FLOPPY                                     #" 
echo "##########################################################"

#output result
$SETCOLOR_SUCCESS
echo ""
echo "##########################################################"
echo "#        SiI driver installed on your system             #"
echo "##########################################################"
echo ""
$SETCOLOR_NORMAL
 
echo "########################################################"
echo "#  Silicon Image, Inc (C) 2003                         #"
echo "########################################################"
