#!/bin/sh

KERNELRELEASE=`uname -r`
KERNELDIR="/lib/modules/$KERNELRELEASE"

PLATFORM=`uname -i`

echo ""
echo "WiNRADiO G526 driver and API uninstaller"
echo ""

echo "If the WiNRADiO G526 driver and API are uninstalled,"
echo "the applications that use them will not work."
echo -n "Are you sure you want to uninstall G526 driver and API? [n] "
read ANSWER

case $ANSWER in
    "y")
      break;;
    "Y")
      break;;
    *)
      exit 0
esac

echo ""


api=""

MODULELOADED=`/sbin/lsmod | grep wrg526 | wc -l`

if [ $MODULELOADED -ne 0 ]; then
    /sbin/rmmod wrg526 >/dev/null 2>&1
    if [ $? != 0 ]; then
	echo "ERROR: Unable to unload wrg526 kernel module."
	echo "Please close all the applications that use the module."
	echo ""
	echo "Press ENTER to exit."
	read
	exit 1
    fi
fi

if [ -f "$KERNELDIR/kernel/drivers/WiNRADiO/wrg526.ko" ]; then
    rm -f "$KERNELDIR/kernel/drivers/WiNRADiO/wrg526.ko" >/dev/null 2>&1
    /sbin/depmod -a
    echo "WiNRADiO G526 kernel module uninstalled."    
fi

if [ -f "/usr/lib/wrg526api.so" ]; then
    rm -f "/usr/lib/wrg526api.so" >/dev/null 2>&1
    
    if [ $? != 0 ]; then
	echo "ERROR: Unable to remove G526 API /usr/lib/wrg526api.so."
	echo ""
	echo "Press ENTER to exit."
	read
	exit 1
    fi
    
    api="1"    
fi

if [ "$PLATFORM" = "x86_64" ] && [ -f "/usr/lib64/wrg526api.so" ]; then
    rm -f "/usr/lib64/wrg526api.so" >/dev/null 2>&1

    if [ $? != 0 ]; then
	echo "ERROR: Unable to remove G526 API (64bit) /usr/lib64/wrg526api.so."
	echo ""
	echo "Press ENTER to exit."
	read
	exit 1
    fi
    
    api="1"
fi

if [ "$api" != "" ]; then
    echo "WiNRADiO G526 API uninstalled."
fi


echo ""
echo "Done."
echo ""
echo "Press ENTER to exit."
read

exit 0


