#!/bin/sh
# copy property lists to MacOS 10.6 (Snow Leopard)
################################

function CopyNonExecutable()
{
	cp -f  "${sourceFolder}/${fileName}" "${destinationFolder}"
	resultCode="$?"
	if [ "$resultCode" -ne 0 ]
	then
		echo "cannot copy ${sourceFolder}/${fileName} to ${destinationFolder}."
		return $resultCode
	fi

	chown -R root:admin "${destinationFolder}/${fileName}"
	resultCode="$?"
	if [ "$resultCode" -ne 0 ]
	then
		echo "cannot set ownership on ${destinationFolder}/${fileName}."
		return $resultCode
	fi

	chmod 0664 "${destinationFolder}/${fileName}"
	resultCode="$?"
	if [ "$resultCode" -ne 0 ]
	then
		echo "cannot set permissions on ${destinationFolder}/${fileName}."
		return $resultCode
	fi

	return 0
}


################################
thisScriptPath="$0"
packagePath=$1
targetLocation=$2
targetVolume=$3

echo "thisScriptPath  ${thisScriptPath}."
echo "packagePath  ${packagePath}."
echo "targetLocation  ${targetLocation}."
echo "targetVolume  ${targetVolume}."

applicationTitle=`defaults read "${packagePath}/Contents/Info" AppTitle -string`
applicationTitleFirstLetterLoverCase=`echo ${applicationTitle:0:1} | tr "[A-Z]" "[a-z]"`
applicationTitleCamelCase=`echo $applicationTitle | sed -e "s/ //g" -e "s/^./$applicationTitleFirstLetterLoverCase/g"`


destinationFolder="/Library/Image Capture/Devices/${applicationTitle}.app/Contents/Resources"


################################
echo "Installing 10.6 property list(s) to ${destinationFolder}..."

sourceFolder="$packagePath/Contents/Resources"

fileName="DeviceInfo.plist"
CopyNonExecutable
resultCode="$?"
if [ "$resultCode" -ne 0 ]
then
	echo "copying DeviceInfo.plist failed"
	exit 1
fi

fileName="DeviceMatchingInfo.plist"
CopyNonExecutable
resultCode="$?"
if [ "$resultCode" -ne 0 ]
then
	echo "copying DeviceMatchingInfo.plist failed"
	exit 1
fi

echo "OK."
