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

NPPath="/usr/lib/npreal2"
driverPath="/usr/lib/npreal2/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 npreal2 |
awk '$0 !~ /grep/ {system("kill -15 "$2)}'
ps -ef | grep npreal2 |
awk '$0 !~ /grep/ {system("kill -9 "$2)}'


if [ "$OS" = "linux" ]
then
    grep -v npreal2 /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 'npreal2d' /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 npreal2 /etc/init.d/npreals > /tmp/nprtmp_rclocal2 2>&1
    cp -f /tmp/nprtmp_rclocal2 /etc/init.d/npreals > /dev/null 2>&1
    rm -f /tmp/nprtmp_rclocal2 > /dev/null 2>&1

    grep -v 'npreal2d' /etc/init.d/npreals > /tmp/nprtmp_rclocal3
    cp -f /tmp/nprtmp_rclocal3 /etc/init.d/npreals > /dev/null 2>&1
    rm -f /tmp/nprtmp_rclocal3 > /dev/null 2>&1
    chmod 755 /etc/init.d/npreals > /dev/null 2>&1
    update-rc.d npreals defaults 90
elif [ "$OS" = "SuSE" ]
then
    grep -v npreal2 /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 'npreal2d' /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 $NPPath/* > /dev/null 2>&1
rm -r -f $driverPath > /dev/null 2>&1
rm -r -f $NPPath > /dev/null 2>&1

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

echo 'Complete'
echo ''



