#!/bin/bash
# Kona Version of Preflight

function wipe {
	# Remove BM daemon
	"$3/bin/rm" -rf $3/$STARTUP_ITEMS/DeckLinkStartup
	"$3/bin/rm" -rf $3/$STARTUP_ITEMS/BlackmagicDaemon
	
	# Remove BM drivers
	"$3/bin/rm" -rf $3/$EXTENSIONS/Blackmagic_Driver.kext
	"$3/bin/rm" -rf $3/$EXTENSIONS/DeckLink_Driver.kext
	
	# Remove BM quicktime components
	"$3/bin/rm" -rf $3/$QUICKTIME/Blackmagic*

	# Remove BM RT Enabler for Final Cut Pro
	"$3/bin/rm" -rf "$3/$RTENABLER"/Blackmagic*
	"$3/bin/rm" -rf "$3/$RTENABLER"/AJA*
				
	# Remove BM Custom Settings
	"$3/bin/rm" -rf "$3/$CUSTOM_SETTINGS"/Kona*
	"$3/bin/rm" -rf "$3/$CUSTOM_SETTINGS"/Io*
	"$3/bin/rm" -rf "$3/$CUSTOM_SETTINGS"/DeckLink?Default?Settings
	"$3/bin/rm" -rf "$3/$CUSTOM_SETTINGS"/Blackmagic

	# Remove BM Preference Panes
	"$3/bin/rm" -rf $3/$PREFPANE/DeckLinkPrefsPanel.prefPane
	
	# Remove BM applications
	"$3/bin/rm" -rf $3/$APPLICATIONS/Blackmagic*
	"$3/bin/rm" -rf $3/Users/*/Desktop/Blackmagic

	# Remove FCP cache files which reference now-nonexistant BM files
	"$3/bin/rm" -rf "$3/Users/*/$FCP_USER_DATA/Final\ Cut\ Pro\ [0-9.]*\ Preferences"
	"$3/bin/rm" -rf "$3/Users/*/$FCP_USER_DATA/Final\ Cut\ Pro\ POA\ Cache"
	"$3/bin/rm" -rf "$3/Users/*/$FCP_USER_DATA/Final\ Cut\ Pro\ MOA\ Cache"

	# Remove BM receipts
	"$3/bin/rm" -rf $3/Library/Receipts/Blackmagic*

	# echo "Wipe Done."
}

APPLICATIONS="Applications"
LIBRARY="Library"
EXTENSIONS="System/Library/Extensions"
QUICKTIME="$LIBRARY/QuickTime"
RTENABLER="$LIBRARY/Application Support/Final Cut Pro System Support/Plugins"
FCP_USER_DATA="$LIBRARY/Preferences/Final Cut Pro User Data/"
CUSTOM_SETTINGS="$LIBRARY/Application Support/Final Cut Pro System Support/Custom Settings"
PREFPANE="$LIBRARY/PreferencePanes"
STARTUP_ITEMS="$LIBRARY/StartupItems"

wipe

"$3/bin/rm" -rf $3/System/Library/Extensions/*KHD.kext
"$3/bin/rm" -rf $3/System/Library/Extensions/*KSD.kext
"$3/bin/rm" -rf $3/System/Library/Extensions/*KONA.kext
"$3/bin/rm" -rf $3/System/Library/Extensions/*KONA2.kext
"$3/bin/rm" -rf $3/System/Library/Extensions/*KONA3.kext
"$3/bin/rm" -rf $3/System/Library/Extensions/*KONALH.kext
"$3/bin/rm" -rf $3/System/Library/Extensions/*KONALS.kext
"$3/bin/rm" -rf $3/System/Library/Extensions/*KONAOEM.kext
"$3/bin/rm" -rf $3/System/Library/Extensions/*KONA3OEM.kext
"$3/bin/rm" -rf $3/System/Library/Extensions/*KONALHOEM.kext
"$3/bin/rm" -rf $3/System/Library/Extensions/AJAOEM*.kext
"$3/bin/rm" -rf $3/System/Library/Extensions/AJAKONA*.kext
"$3/bin/rm" -rf $3/System/Library/Extensions/AJAIo*.kext
"$3/bin/rm" -rf $3/System/Library/Extensions/AJACorvid*.kext

"$3/bin/rm" -rf $3/Library/StartupItems/avksd
"$3/bin/rm" -rf $3/Library/StartupItems/avkhd
"$3/bin/rm" -rf $3/Library/StartupItems/AJAKonaStartupD

"$3/bin/rm" -rf $3/Library/Application\ Support/AJA/AJAAgent
"$3/bin/rm" -rf $3/Library/LaunchAgents/com.aja*.plist
"$3/bin/rm" -rf $3/Library/Application\ Support/AJA/AJADaemon
"$3/bin/rm" -rf $3/usr/libexec/ajad
"$3/bin/rm" -rf $3/Library/LaunchDaemons/com.aja*.plist

"$3/bin/rm" -rf $3/Library/PreferencePanes/Kona*Preferences.prefPane
"$3/bin/rm" -rf $3/Library/Preference/com.aja.Kona*.plist

"$3/bin/rm" -rf $3/Library/QuickTime/Kona*.component
"$3/bin/rm" -rf $3/Library/QuickTime/AJA*.component

"$3/bin/rm" -rf $3/Applications/Kona\ Utilities/AJA*
"$3/bin/rm" -f $3/Applications/Kona\ Utilities

"$3/bin/rm" -rf $3/Applications/AJA\ Kona\ Utilities/AJA*
"$3/bin/rm" -f $3/Applications/AJA\ Kona\ Utilities

"$3/bin/rm" -rf $3/Applications/AJA\ Utilities/AJA*
"$3/bin/rm" -f $3/Applications/AJA\ Utilities

 # older installers put this stuff in there
"$3/bin/rm" -rf $3/Applications/KHDWatcher.app
"$3/bin/rm" -rf $3/Applications/KSDWatcher.app
"$3/bin/rm" -rf $3/Applications/Kona*
"$3/bin/rm" -rf $3/Applications/AJA Utilities
"$3/bin/rm" -rf $3/Applications/AJA ControlPanel

# Remove receipts
"$3/bin/rm" -rf $3/Library/Receipts/AJA\ KONA*
"$3/bin/rm" -rf $3/Library/Receipts/AJA\ OEM*
"$3/bin/rm" -rf $3/Library/Receipts/AJA\ IoHD*
"$3/bin/rm" -rf $3/Library/Receipts/Kona3.pkg
"$3/bin/rm" -rf $3/Library/Receipts/Kona2.pkg
"$3/bin/rm" -rf $3/Library/Receipts/KonaLH.pkg
"$3/bin/rm" -rf $3/Library/Receipts/IoHD.pkg
"$3/bin/rm" -rf $3/Library/Receipts/KonaLHI.pkg
"$3/bin/rm" -rf $3/Library/Receipts/Corvid.pkg
"$3/bin/rm" -rf $3/Library/Receipts/IoExpress.pkg

"$3/bin/rm" -rf $3/Users/*/Library/Preferences/com.aja.application.k?dcontrolpanel.plist

