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

NPPath="/usr/lib/npreal2"
driverPath="/usr/lib/npreal2/driver"
npreal2Rules="/etc/udev/rules.d/60-npreal2.rules"
OS="linux"

########################################################################
# 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
OS="linux"


# 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)}'

mkdir -p /usr/lib/npreal2/tmp > /dev/null 2>&1


if [ "$OS" = "linux" ]
then
     systemctl disable npreal2.service > /dev/null 2>&1
     rm -f /usr/lib/npreal2/driver/load_npreal2.sh > /dev/null 2>&1
     rm -f /etc/systemd/system/npreal2.service > /dev/null 2>&1
elif [ "$OS" = "debian" ]
then
    update-rc.d npreals remove
    rm -f /etc/init.d/npreals > /dev/null 2>&1
elif [ "$OS" = "SuSE" ]
then
    grep -v npreal2 /etc/rc.d/boot.local > /usr/lib/npreal2/tmp/nprtmp_rclocal2 2>&1
    cp -f /usr/lib/npreal2/tmp/nprtmp_rclocal2 /etc/rc.d/boot.local > /dev/null 2>&1
    rm -f /usr/lib/npreal2/tmp/nprtmp_rclocal2 > /dev/null 2>&1

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

rm -f /dev/ttyr* > /dev/null 2>&1
rm -f /dev/cur* > /dev/null 2>&1

rm -f $driverPath/* > /dev/null 2>&1
rm -f $driverPath/certificate/* > /dev/null 2>&1
rm -f $driverPath/local_cert/* > /dev/null 2>&1
rm -f $NPPath/tmp/* > /dev/null 2>&1
rm -f $NPPath/* > /dev/null 2>&1
rm -r -f $driverPath/certificate > /dev/null 2>&1
rm -r -f $driverPath/local_cert > /dev/null 2>&1
rm -r -f $driverPath > /dev/null 2>&1
rm -r -f $NPPath/tmp > /dev/null 2>&1
rm -r -f $NPPath > /dev/null 2>&1

rm -f $npreal2Rules > /dev/null 2>&1
udevadm control --reload

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 > /dev/null 2>&1

echo 'Complete'
echo ''



