#!/bin/bash

#locate the application bundle
name=$(basename "$0")
echo $name

dirn=$(dirname "$0")
echo $dirn

#locate application bundle subdirectories
bundle=$(cd "$dirn/../../" && pwd)
bundle_contents="$bundle"/Contents
bundle_res="$bundle_contents"/Resources

#make temporary directories
TMPDIR=`mktemp -d /tmp/BRPXXXXX`
mkdir -p "$TMPDIR"/modules

#create pango.modules file
echo $TMPDIR'/modules/pango-basic-coretext.so BasicScriptEngineCoreText PangoEngineShape PangoRenderCoreText common:' > $TMPDIR/pango.modules

#create pangorc file
echo '[Pango]
ModuleFiles = '$TMPDIR'/pango.modules' > $TMPDIR/pangorc

#create links to modules
ln -s  "$bundle_res"/pango/modules/* $TMPDIR/modules

# Help pango find pangorc
export PANGO_RC_FILE="$TMPDIR/pangorc"

#execute PRP-PACU binary
"$bundle_contents/MacOS/BRP_PACU"

#clean up
rm -rf $TMPDIR 
