
################################################################################
# define value and default value setting
################################################################################

SECPath="/usr/lib/secreal2"
driverPath="/usr/lib/secreal2/driver"
OS=""

########################################################################
# Main procedures
# To read the shell program input argument and process it.
########################################################################


echo 'Driver Removal ... '

if [ -f /etc/redhat-release ]
then
    OS="linux"
elif [ -f /etc/SuSE-release ]
then
    OS="SuSE"
elif [ -f /etc/debian_version ]
then
    OS="debian"
fi



# stop the daemon & kill the process
ps -ef | grep secreal2 |
awk '$0 !~ /grep/ {system("kill -15 "$2)}'
ps -ef | grep secreal2 |
awk '$0 !~ /grep/ {system("kill -9 "$2)}'


if [ "$OS" = "linux" ]
then
    grep -v secreal2 /etc/rc.d/rc.local > /tmp/nprtmp_rclocal2 2>&1
    cp -f /tmp/nprtmp_rclocal2 /etc/rc.d/rc.local > /dev/null 2>&1
    rm -f /tmp/nprtmp_rclocal2 > /dev/null 2>&1

    grep -v 'secreal2d' /etc/rc.d/rc.local > /tmp/nprtmp_rclocal3
    cp -f /tmp/nprtmp_rclocal3 /etc/rc.d/rc.local > /dev/null 2>&1
    rm -f /tmp/nprtmp_rclocal3 > /dev/null 2>&1
    chmod 755 /etc/rc.d/rc.local > /dev/null 2>&1
elif [ "$OS" = "debian" ]
then
    grep -v secreal2 /etc/init.d/secreals > /tmp/nprtmp_rclocal2 2>&1
    cp -f /tmp/nprtmp_rclocal2 /etc/init.d/secreals > /dev/null 2>&1
    rm -f /tmp/nprtmp_rclocal2 > /dev/null 2>&1

    grep -v 'secreal2d' /etc/init.d/secreals > /tmp/nprtmp_rclocal3
    cp -f /tmp/nprtmp_rclocal3 /etc/init.d/secreals > /dev/null 2>&1
    rm -f /tmp/nprtmp_rclocal3 > /dev/null 2>&1
    chmod 755 /etc/init.d/secreals > /dev/null 2>&1
    update-rc.d secreals defaults 90
elif [ "$OS" = "SuSE" ]
then
    grep -v secreal2 /etc/rc.d/boot.local > /tmp/nprtmp_rclocal2 2>&1
    cp -f /tmp/nprtmp_rclocal2 /etc/rc.d/boot.local > /dev/null 2>&1
    rm -f /tmp/nprtmp_rclocal2 > /dev/null 2>&1

    grep -v 'secreal2d' /etc/rc.d/boot.local > /tmp/nprtmp_rclocal3
    cp -f /tmp/nprtmp_rclocal3 /etc/rc.d/boot.local > /dev/null 2>&1
    rm -f /tmp/nprtmp_rclocal3 > /dev/null 2>&1
    chmod 755 /etc/rc.d/boot.local
fi


rm -f $driverPath/* > /dev/null 2>&1
rm -f $SECPath/* > /dev/null 2>&1
rm -r -f $driverPath > /dev/null 2>&1
rm -r -f $SECPath > /dev/null 2>&1

rm -f /lib/modules/`uname -r`/kernel/drivers/char/secreal2.o
rm -f /lib/modules/`uname -r`/misc/secreal2.o
rm -f /lib/modules/`uname -r`/kernel/drivers/char/secreal2.ko
rm -f /lib/modules/`uname -r`/misc/secreal2.ko
rmmod secreal2

echo 'Complete'
echo ''



