#!/bin/bash

if [ -f "/Library/Application Support/Todisk/Data/run.pid" ]
then
	PID=`cat "/Library/Application Support/Todisk/Data/run.pid"`
	RET=`ps -ef | grep  DownloadMac| grep MacOS |wc -l`
	if [ "$RET" -eq "1" ]
	then
	echo "##########################"
	echo "#  Download Program 종료 #"
	echo "##########################"
		sudo kill -9 $PID
	fi
fi

if [ -f /Library/LaunchAgents/com.todisk.startup.plist ]; then
	echo "##########################"
	echo "#  Support Program  종료 #"
	echo "##########################"
	sudo -u $USER /bin/launchctl unload /Library/LaunchAgents/com.todisk.startup.plist
fi

echo "##########################"
echo "#  Download Program 삭제 #"
echo "##########################"
#sudo rm -rf /Applications/TodiskDownMac.app


sudo rm -f /Applications/TodiskDownMac.app/Contents/Resources/Base.lproj/Main.storyboardc/Info.plist /Applications/TodiskDownMac.app/Contents/Resources/Base.lproj/Main.storyboardc/MainMenu.nib /Applications/TodiskDownMac.app/Contents/Resources/Base.lproj/Main.storyboardc/NSWindowController-B8D-0N-5wS.nib /Applications/TodiskDownMac.app/Contents/Resources/Base.lproj/Main.storyboardc/XfG-lQ-9wD-view-m2S-Jp-Qdl.nib /Applications/TodiskDownMac.app/Contents/Resources/AppIcon.icns /Applications/TodiskDownMac.app/Contents/Resources/Assets.car /Applications/TodiskDownMac.app/Contents/MacOS/TodiskDownMac /Applications/TodiskDownMac.app/Contents/_CodeSignature/CodeResources /Applications/TodiskDownMac.app//Contents/Info.plist /Applications/TodiskDownMac.app/Contents/PkgInfo

sudo rmdir /Applications/TodiskDownMac.app/Contents/MacOS
sudo rmdir /Applications/TodiskDownMac.app/Contents/_CodeSignature
sudo rmdir /Applications/TodiskDownMac.app/Contents/Resources/Base.lproj/Main.storyboardc
sudo rmdir /Applications/TodiskDownMac.app/Contents/Resources/Base.lproj
sudo rmdir /Applications/TodiskDownMac.app/Contents/Resources
sudo rmdir /Applications/TodiskDownMac.app/Contents
sudo rmdir /Applications/TodiskDownMac.app




echo "##########################"
echo "#  Support  Program 삭제 #"
echo "##########################"
sudo rm -f "/Library/LaunchAgents/com.todisk.startup.plist"
sudo rm -f "/Library/Application Support/Todisk/Data/data.fifo"
sudo rm -f "/Library/Application Support/Todisk/Data/run.pid"
sudo rm -f "/Library/Application Support/Todisk/Data/savepath"
sudo rm -f "/Library/Application Support/Todisk/Data/progoff"
sudo rm -f "/Library/Application Support/Todisk/LaunchDaemons/todiskd"
sudo rmdir "/Library/Application Support/Todisk/Data"
sudo rmdir "/Library/Application Support/Todisk/LaunchDaemons"
