#!/bin/bash

# pgModeler startup script for MacOSX bundle application
# usage: startapp [executable]
# Where [executable]  can be pgmodeler | pgmodeler-cli | crashhandler

PWD="${0%/*}"
EXE=$PWD/$1

# Checking if the parameter contains the name of any pgModeler executables
res=$(echo $1 | grep -E \(pgmodeler\|pgmodeler-cli\|pgmodeler-ch\))

# If not contains the executable name the default is call pgmodeler (GUI)
if [ -z $res ]; then
  echo "Please specify one module: pgmodeler | pgmodeler-cli | pgmodeler-ch"
  exit 1
fi

# Export the necessary environment variables
export DYLD_FRAMEWORK_PATH=../Frameworks
export DYLD_LIBRARY_PATH=../Frameworks
export PGMODELER_SCHEMAS_DIR=$PWD/schemas
export PGMODELER_CONF_DIR=$PWD/conf
export PGMODELER_LANG_DIR=$PWD/lang
export PGMODELER_PLUGINS_DIR=$PWD/plugins
export PGMODELER_TMP_DIR=$PWD/tmp
export PGMODELER_CHANDLER_PATH=$PWD/pgmodeler-ch
export PGMODELER_CLI_PATH=$PWD/pgmodeler-cli

#Calls the executable redirecting the parameters to it
$EXE ${@:2:20}
exit $?
