#!/bin/sh
#
#
# ACP start script for UNIX platforms setting the ANSYSLIC_DIR
#
# Copyright (C) 2012 by
# EVEN - Evolutionary Engineering AG
#

setenv ()
{
   envname="$1"
   envval="$2"
   eval "$envname=$envval;export $envname"
   if [ "$listenv" = "y" ]; then
      echo "$envname=$envval"
   fi
}


# R.Walker 2015-09-29
# reset the LD_LIBRARY_PATH
# its not allowed to extend library path --> can lead to crashes
# WB is setting LD_LIBRARY_PATH and we therefore have an issue on RHEL 7 (freetype lib shipped with ansys is to old)
setenv LD_LIBRARY_PATH ""

# Attempt to self locate
pwdpath="pwd"
currdir="`$pwdpath`"
calldir=`echo $0 | sed 's!/[a-zA-Z0-9_\.]*$!!'`
if test "$calldir" = "$0"
then
   calldir="`$pwdpath`"
fi

cd "$calldir"
calldir=`pwd`
cd "$currdir"

# find ANSYS licensing dir

if [ ! -n "${ANSYSLIC_DIR+x}" ]; then
  ansyslic_dir="$calldir/../../shared_files/licensing"
  if [ ! -d $ansyslic_dir ]; then
    echo "ANSYS License directory \"$ansyslic_dir\" not found."
    exit 0
  fi
  setenv ANSYSLIC_DIR $ansyslic_dir
fi


# add arguments to ACP exe

# fix for path with spaces rwalker 2015-05-18
args=
for arg in "$@";
do
  args="$args '$arg'"
done

exename="$calldir/ACP"
stat=0
if [ -x $exename ]; then
   eval $exename $args
   stat="$?"
else
   echo "$exename does not exist!"
   stat=1
fi

exit $stat
