#!/bin/sh

# $Id: uninstall.sh,v 1.2 2005/09/21 02:08:43 phaddad Exp $

# removes all installed components, including prefs file, resulting from a Razer DeathAdder v1.0 install
# note this does not remove the SystemLoginItem entry in the system prefs

clear

echo ""
echo "This script removes resources installed with Razer DeathAdder."
echo "You may need to enter your administrator password to continue."
echo "It is needed to remove a system extension and preference pane."
echo ""

# driver
if [ -d /System/Library/Extensions/RazerDeathAdderDriver.kext/ ]; then
    sudo rm -r /System/Library/Extensions/RazerDeathAdderDriver.kext
    echo "Removed DeathAdder kernel extension"
else
    echo "DeathAdder kernel extension was not found... continue"
fi


# daemon
if [ -d "/Library/Application Support/Razer/RazerDeathAdderDaemon.app" ] || [ -d /Library/PrivilegedHelperTools/RazerDeathAdderDaemon.app ]; then
    if [ -d "/Library/Application Support/Razer/RazerDeathAdderDaemon.app" ]; then
    	sudo rm -r "/Library/Application Support/Razer/RazerDeathAdderDaemon.app"
    	echo "Removed DeathAdder daemon"
    fi
    if [ -d /Library/PrivilegedHelperTools/RazerDeathAdderDaemon.app ]; then
    	sudo rm -r /Library/PrivilegedHelperTools/RazerDeathAdderDaemon.app
    	echo "Removed DeathAdder daemon"
        if [ -f /Library/LaunchAgents/com.razer.DeathAdder.Daemon.plist ]; then
            sudo rm /Library/LaunchAgents/com.razer.DeathAdder.Daemon.plist
            echo "Removed DeathAdder launchd agent"
        fi
    fi
else
    echo "DeathAdder daemon was not found... continue"
fi


# application
if [ -d /Applications/RazerDeathAdder.app ]; then
    sudo rm -r /Applications/RazerDeathAdder.app
    echo "Removed DeathAdder settings application"
else
    echo "DeathAdder settings application was not found... continue"
fi


# prefs file
if [ -f ~/Library/Preferences/com.razer.DeathAdder.plist ]; then
    rm -f ~/Library/Preferences/com.razer.DeathAdder.plist
    echo "Removed DeathAdder preference file"
else
    echo "DeathAdder preference file was not found... continue"
fi


# remove receipt
sudo rm -rf "/Library/Receipts/Razer DeathAdder"*
sudo rm -rf /private/var/db/receipts/com.razer.pkg.DeathAdder.*

# uninstaller
if [ -f /Applications/Utilities/RazerDeathAdderUninstaller.command ]; then
    sudo rm -r /Applications/Utilities/RazerDeathAdderUninstaller.command
    echo "Removed DeathAdder uninstaller"
else
    echo "DeathAdder uninstaller was not found... continue"
fi



echo ""
echo "Razer DeathAdder uninstall complete!"
echo ""
echo "It is recommended that you reboot after uninstalling DeathAdder."
echo "Do you want to reboot now? (yes or no)"
echo ""

read reboot

if [ $reboot = "yes" ] || [ $reboot = "y" ]; then
	sudo reboot
fi