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

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


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

    grep -v 'oncellreald' /etc/rc.d/rc.local > /tmp/ocrtmp_rclocal3
    cp -f /tmp/ocrtmp_rclocal3 /etc/rc.d/rc.local > /dev/null 2>&1
    rm -f /tmp/ocrtmp_rclocal3 > /dev/null 2>&1
    chmod 755 /etc/rc.d/rc.local > /dev/null 2>&1
elif [ "$OS" = "debian" ]
then
    grep -v oncellreal /etc/init.d/oncellreals > /tmp/ocrtmp_rclocal2 2>&1
    cp -f /tmp/ocrtmp_rclocal2 /etc/init.d/oncellreals > /dev/null 2>&1
    rm -f /tmp/ocrtmp_rclocal2 > /dev/null 2>&1

    grep -v 'oncellreald' /etc/init.d/oncellreals > /tmp/ocrtmp_rclocal3
    cp -f /tmp/ocrtmp_rclocal3 /etc/init.d/oncellreals > /dev/null 2>&1
    rm -f /tmp/ocrtmp_rclocal3 > /dev/null 2>&1
    chmod 755 /etc/init.d/oncellreals > /dev/null 2>&1
    update-rc.d oncellreals defaults 90
elif [ "$OS" = "SuSE" ]
then
    grep -v oncellreal /etc/rc.d/boot.local > /tmp/ocrtmp_rclocal2 2>&1
    cp -f /tmp/ocrtmp_rclocal2 /etc/rc.d/boot.local > /dev/null 2>&1
    rm -f /tmp/ocrtmp_rclocal2 > /dev/null 2>&1

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


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

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

echo 'Complete'
echo ''



