#!/bin/bash
#
# Script run on test machine to unload driver
# Must be run with root perimission, typically via 'sudo <scriptname>'.

if [ -f ~/Library/Preferences/com.apogee.Maestro.plist ]; then
	rm -f  ~/Library/Preferences/com.apogee.Maestro.plist
fi

if [ -f ~/Library/Preferences/com.apogee.maestro.plist ]; then
	rm -f  ~/Library/Preferences/com.apogee.maestro.plist
fi

if [ -f ~/Library/Preferences/com.apogee.DuetPopUp.plist ]; then
	rm -f ~/Library/Preferences/com.apogee.DuetPopUp.plist
fi

if [ -f /Library/LaunchDaemons/com.duetDaemon.plist ]; then
	launchctl unload /Library/LaunchDaemons/com.duetDaemon.plist
	rm -f /Library/LaunchDaemons/com.duetDaemon.plist
fi

if [ -f /System/Library/Extensions/DuetPlugIn.bundle/Contents/DuetPopUp.app/LogInItem ]; then
	/System/Library/Extensions/DuetPlugIn.bundle/Contents/DuetPopUp.app/LogInItem global remove /System/Library/Extensions/DuetPlugIn.bundle/Contents/DuetPopUp
fi

if [ -f /System/Library/Extensions/DuetPlugIn.bundle/Contents/DuetPopUp.app/LogInShared ]; then
	/System/Library/Extensions/DuetPlugIn.bundle/Contents/DuetPopUp.app/LogInShared remove /System/Library/Extensions/DuetPlugIn.bundle/Contents/DuetPopUp
fi

if [ -d /System/Library/Extensions/DuetPlugIn.bundle ]; then
	rm -Rf /System/Library/Extensions/DuetPlugIn.bundle
fi

if [ -d /System/Library/Extensions/DuetFWOverideDriver.kext ]; then
	rm -Rf /System/Library/Extensions/DuetFWOverideDriver.kext
fi

if [ -d /Applications/Maestro.app ]; then
	rm -Rf /Applications/Maestro.app
fi

if [ -d /Applications/Apogee\ Maestro.app ]; then
	rm -rf /Applications/Apogee\ Maestro.app
fi


touch /System/Library/Extensions

rm -rf /Library/Receipts/Maestro*
rm -rf /Library/Receipts/DuetDaemon*
rm -rf /Library/Receipts/duetDaemon*
rm -rf /Library/Receipts/mAEstroLink*

