#!/bin/sh


function StopStudent()
{
sysVersion=$(uname -r)
sysMajorVersion=${sysVersion%%.*}

	if [ $sysMajorVersion -ge 9 ]; then
		echo "StopStudent on Leopard or above..."
             	/usr/bin/osascript -e "tell application \"System Events\"" -e "do shell script \"launchctl unload -S Aqua /Library/LaunchAgents/com.lanschool.student.plist\"" -e "end tell"
        else
       		echo "StopStudent on Tiger..."
		/usr/bin/sudo /usr/bin/killall student
	fi
}


function StopDaemon()
{
	if [ -f "/Library/LaunchDaemons/com.lanschool.lsdaemon.plist" ]; then
		/usr/bin/sudo /bin/launchctl unload /Library/LaunchDaemons/com.lanschool.lsdaemon.plist
	fi
}


echo "daemon pkg preflight"

StopDaemon
StopStudent

# delete other forms of the plist
plist="/Library/Preferences/com.faronics.student.settings.plist"
if [ -f ${plist} ]; then
        echo "removing old plist file ${plist}"
        rm ${plist}
fi

plist="/Library/Preferences/com.landesk.student.settings.plist"
if [ -f ${plist} ]; then
        echo "removing old plist file ${plist}"
        rm ${plist}
fi


plist="/var/tmp/lskdata.bin"
if [ -f ${plist} ]; then
        echo "removing old data file ${plist}"
        rm ${plist}
fi

exit 0

