#!/bin/bash
# Setups Version of Postflight

# Set type and creator for EZ Setups
PLUGINS_PATH="$3/Library/Application Support/Final Cut Pro System Support/Plugins"

"$3/bin/rm" -rf "$PLUGINS_PATH/"KonaX*Enabler
"$1/Contents/Resources/SetFile" -c KeyG -t TEXT "$PLUGINS_PATH/"AJA*Enabler.txt

EZ_SETUPS_PATH="$3/Library/Application Support/Final Cut Pro System Support/Custom Settings"

# make sure no space before or after comma
DIRS="Kona 2 Easy Setups,Kona 3 Easy Setups,Kona LS Easy Setups,Kona LH Easy Setups,Kona LHI Easy Setups,Corvid Easy Setups"
IFS=,
for dir in $DIRS; do
CUR_PATH="$EZ_SETUPS_PATH/$dir"
	if [ -d "$CUR_PATH" ]; then
		FILES=`ls -m "$CUR_PATH" | tr -d '\n' | sed -e 's:, :,:g' -e 's:.DS_Store,::g'`
		for file in $FILES; do
			if [ -f "$CUR_PATH/$file" ]; then
				# file
				$1/Contents/Resources/SetFile -c KeyG -t KGPs "$CUR_PATH/$file"
				/bin/chmod 664 "$CUR_PATH/$file"
			else
				# folder
				$1/Contents/Resources/SetFile -c KeyG -t KGPs "$CUR_PATH/$file/"AJA*
				/bin/chmod 664 "$CUR_PATH/$file/"*.fcpre
			fi
		done
	fi
done

#copy the version plist to disk
"$3/bin/cp" "$1/Contents/Resources/com.aja.easysetups.plist" "$3/Library/Preferences/"
/bin/chmod 664 "$3/Library/Preferences/com.aja.easysetups.plist"
