#!/bin/bash

#*****************************************************************
#                                                                *
#   Copyright (c) 2016 by FRIENDSHIP SYSTEMS AG                  *
#   Benzstr.2, D-14482 Potsdam                                   *
#   www.FRIENDSHIP-SYSTEMS.com                                   *
#                                                                *
#   This code and parts thereof are subject to                   *
#   license agreements. Unauthorized usage,                      *
#   modification, distribution, dissemination,                   *
#   and/or modification etc. is strictly prohibited.             *
#                                                                *
#   THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY            *
#   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, WITHOUT          *
#   LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY        *
#   AND FITNESS FOR A PARTICULAR PURPOSE.                        *
#                                                                *
#*****************************************************************
#
# Rel:   FRIENDSHIP-SYSTEMS 4.2.0
# arch:  Linux.x86_64

# TO DEBUG CAESES PLEASE INSTALL GDB AND CHANGE INTO THIS DIRECTORY
# execute this
# LD_LIBRARY_PATH=lib/Linux.x86_64/ gdb bin/Linux.x86_64/CAESES
# enter "run" + press Enter to start CAESES
# repeat the crash procedure 
# you will get a seg fault warning in gdb
# enter "bt" + press Enter to get the Backtrace
# send this output with the project file to us.


##### If you want to use a FLOAT LICENSE
##### FLOAT ACCOUNT DATA required only durring first startup!! 
##### After first startup, email and password is saved in user cfg file.
#ARGS="-float" #enable, if you want to start in (offline) float mode
#export FS_FLOAT_USER="youremail@yourdomain.com"
#export FS_FLOAT_PASSWORD=yourpassword
# optinal to set the LICID or NotesString
#export FS_FLOAT_LICID=1000
#export FS_FLOAT_LICID=MYFLOATLICENSE
#####

##### LOCAL FLOAT LICENSE
# export FS_LIC_SRV=IPofYOURlicenseSERVER:PORT
# or in this format
# export FS_LIC_SRV=PORT@IPofYOURlicenseSERVER
##### valid examples
# export FS_LIC_SRV=192.168.25.102 # default port 8443 is used
# export FS_LIC_SRV=192.168.25.102:8443
# export FS_LIC_SRV=8443@192.168.25.102
#####

##### If you have crashes, regarding the FileDialogs, try this
echo "If you have crashes using a custom file dialog (PDF generation or OpenProject) add \"-style plastique\" to your start script"

#ARGS=" -style plastique"
#####

# You can setup the proxy access data via environment, 
# this will override the saved settings.
#export FS_PROXY_SERVER=proxy
#export FS_PROXY_PORT=8080
#export FS_PROXY_USER=user
#export FS_PROXY_PASSWORD=passwd


if [ -f /etc/redhat-release ] ; then
  ARGS="$ARGS -style plastique" && echo "Using different window style, Red Hat detected"
else
  which lsb_release >& /dev/null && lsb_release -i | grep -i redhat && ARGS="$ARGS -style plastique" && echo "Using different window style, Red Hat detected"
fi



# if you want to try to load the GTK style
#ARGS="$ARGS -gtk"

abspath=$(cd ${0%/*} && echo $PWD/${0##*/})

# to get the path only - not the script name
FS_INSTALL_DIR=`dirname "$abspath"`


export FWORK=${FS_INSTALL_DIR}
if [ -z $FSBASE ] ; then
  export FSBASE=${FS_INSTALL_DIR}
fi
export FS_LIB_DIR=${FS_INSTALL_DIR}/lib/Linux.x86_64/:${FS_INSTALL_DIR}/tools/dakota/6.3.0/lib/
if [ -z $LD_LIBRARY_PATH ] ; then
  export LD_LIBRARY_PATH=$FS_LIB_DIR
else
  export LD_LIBRARY_PATH=$FS_LIB_DIR:$LD_LIBRARY_PATH
fi

# if you have "missing library" problems, uncomment the next line
# export LD_LIBRARY_PATH=${FS_INSTALL_DIR}/lib/Linux.x86_64/missing_libs/:$LD_LIBRARY_PATH

# please edit THIS line to define your system bus socket used by DBUS
export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/var/run/dbus/system_bus_socket


if [ -z ${FS_CAESES_LICENSE} ]; then
  export HOST=`hostname -s`
  [ ! -d ~/.friendship/lic ] && mkdir -p ~/.friendship/lic/
  
 # setup the license location:
 # export FS_CAESES_LICENSE=~/.friendship/lic/${HOST}_fslicense.dat
 #
fi

#####
# start the FRIENDSHIP-Framework with the given (script) arguments
${FS_INSTALL_DIR}/bin/Linux.x86_64/CAESES $ARGS "$@"
#####

exit $?


# FAQ:
# Please check our Helpdesk for common issues
#
# https://helpdesk.caeses.com/support/solutions


