#!/bin/bash

# Post install script to move incentive filter content in default location to user defined content location.
# Doug Lesan
# 05-11-05

# CHECK FIRST TO SEE IF THERE IS A MOTION.PLIST FILE
if [ -e ~/Library/Preferences/com.apple.motion.plist ]; then
	# IF THE FILE EXISTS THEN READ THE FILE USING DEFAULTS
	contentPath=`defaults read ~/Library/Preferences/com.apple.motion OZPreferenceManager::ContentPath`

	# SET THE FOUNDFILE FLAG TO TRUE
	foundFile=true
	whichPlistFile="motion"
else # IF THE MOTION.PLIST FILE DOES NOT EXIST THEN REVER TO THE INSTALLER FILE
	if [ -e /Library/Preferences/com.apple.proapps.plist ]; then
		# IF THE FILE EXISTS THEN READ THE FILE USING DEFAULTS AND STRIP OFF ALL OF THE UNNEEDED TEXT
		contentPath=`defaults read /Library/Preferences/com.apple.proapps 4B6F2047-22F5-11D9-8AE3-000393DB3D7C | grep ContentURL | cut -d= -f2 | sed -e 's#"file://localhost##g' -e 's#";##g' -e 's# ##g' -e 's#%20# #g'`
		# SET THE FOUNDFILE FLAG TO TRUE
		foundFile=true
		whichPlistFile="proapps"
	fi
fi
# IF FOUNDFILE IS TRUE THEN CONTINUE
if [ $foundFile=true ]; then
	if [ "$whichPlistFile" = "motion" ]; then
		motionVar=""
		else if [ "$whichPlistFile" = "proapps" ]; then
			motionVar="Motion"
		fi
	fi
	# IF THE CONTENT PATH IS DEFAULT (/Users/Shared/) THEN DO NOTHING, OTHERWISE CONTINUE
		if [ "$contentPath" = "/Users/Shared/" ]; then
			contentPath="/Users/Shared/Motion"
		fi

	
		if [ "$contentPath" != "/Users/Shared/Motion" ]; then
		# VERIFY THAT THE DESTINATION PATH EXISTS
			if [ -e "$contentPath" ]; then
			# APPEND THE CONTENTPATH WITH THE DIRECTORY PATHS
				movementBlurPath="$contentPath/$motionVar/Library/Filters.localized/Blur.localized/Movement Blur.mopr"
				InsectEyePath="$contentPath/$motionVar/Library/Filters.localized/Distortion.localized/Insect Eye.mopr"
				underWaterPath="$contentPath/$motionVar/Library/Filters.localized/Distortion.localized/Underwater.mopr"
			# VERIFY THAT EACH SOURCE DIRECTORY EXISTS IF SO EXECUTE THE MOVE
				if [ -e "/Users/Shared/Motion/Library/Filters.localized/Blur.localized/Movement Blur.mopr" ]; then
					mv "/Users/Shared/Motion/Library/Filters.localized/Blur.localized/Movement Blur.mopr" "$movementBlurPath"
				fi
				if [ -e "/Users/Shared/Motion/Library/Filters.localized/Distortion.localized/Insect Eye.mopr" ]; then
					mv "/Users/Shared/Motion/Library/Filters.localized/Distortion.localized/Insect Eye.mopr" "$InsectEyePath"
				fi
				if [ -e "/Users/Shared/Motion/Library/Filters.localized/Distortion.localized/Underwater.mopr" ]; then
					mv "/Users/Shared/Motion/Library/Filters.localized/Distortion.localized/Underwater.mopr" "$underWaterPath"
				fi
				
			fi
		fi
fi
exit 0
