#!/bin/bash

#for debugging:
set -x

#set the permissions on the application bundle
sudo chmod -R 775 "$2/Universal Type Client.app"

#set the ownership of the application bundle
sudo chown -R root:wheel "$2/Universal Type Client.app"

#create UTC directory...
if [ ! -d "/Library/Extensis" ]; then
	sudo mkdir "/Library/Extensis"	
fi

#add the ACL so we can create/delete folders and files inside the Extensis directory
sudo chmod +a "everyone allow add_file,add_subdirectory,delete_child,directory_inherit" "/Library/Extensis"

#create UTC directory...
if [ ! -d "/Library/Extensis/UTC" ]; then
	sudo mkdir "/Library/Extensis/UTC"	
fi

#add the ACL so we can create/delete files and folders inside the UTC directory
sudo chmod +a "everyone allow add_file,add_subdirectory,delete_child,directory_inherit" "/Library/Extensis/UTC"

#copy the corecli app to the /usr/bin directory and change the permissions on it to: 755
#Doing this instead of adding it to the PackageMaker project because editing the project can cause "bad" stuff like the "relocatable bundle" issue.
if [ -e "$2/Universal Type Client.app/Contents/Resources/corecli" ]; then
	if [ -e "/usr/bin/corecli" ]; then
		sudo ditto --rsrc "$2/Universal Type Client.app/Contents/Resources/corecli" "/usr/bin/corecli"
		sudo chmod 755 "/usr/bin/corecli"
	fi
fi

#launch the Universal Type Client application
#sudo su "$thisuser" -c "'/Applications/Universal Type Client.app/Contents/MacOS/Universal Type Client' '-LaunchPluginManager' 'YES'" > /dev/null 2>&1 &

