#!/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.1.0
# arch:  Linux.x86_64


##### 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
##### valid examples
# export FS_LIC_SRV=192.168.25.102
# export FS_LIC_SRV=192.168.25.102:8443
#####

# 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

export FS_USER_DIR="$HOME/.friendship"
#unset FS_USER_DIR # unset the variable,
                   # if you want to start with temporary USERDIR
                   # check code below

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

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


export FWORK=${HERE}
if [ -z $FSBASE ] ; then
  export FSBASE=${HERE}
fi
export FS_LIB_DIR=${HERE}/lib/Linux.x86_64/:${HERE}/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=${HERE}/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_FRAMEWORK_LICENSE} ]; then
  export HOST=`hostname -s`
  [ ! -d ~/.friendship/lic ] && mkdir -p ~/.friendship/lic/
#  export FS_FRAMEWORK_LICENSE=~/.friendship/lic/${HOST}_fslicense.dat
fi

if [ -z ${FS_USER_DIR} ]; then
  export FS_USER_DIR=/tmp/FFW_${USER}_$$
  ${HERE}/bin/Linux.x86_64/CAESES_crt "$@"
  rm -rf ${FS_USER_DIR}
else
    ${HERE}/bin/Linux.x86_64/CAESES_crt "$@"
fi


exit $?



# LINUX FAQ:

# Q: I can't use ALT+left click to select an object in ObjectTree?
# A: That's a feature of your window manager. If you're on GNOME using Metacity
# (default WM), you can go to System > Preferences > Windows and change the
# "Movement Key" (this will just map it to another combination, of course).
#
# A: If you're on KDE goto "System Settings" then in the Personal section "->Desktop->Window Behavior"
# There will be "Window Actions" change your setting for "Modifier Key + left Button"
# from "Move" to "Nothing" or change your modifier Key to Meta instead of Alt.

# Q: Can I save the license file in a differant directory?
# A: Use the environment variable FS_FRAMEWORK_LICENSE
#    for example: export FS_FRAMEWORK_LICENSE=/somewhere/mylic.dat && ./CAESES_crt

# Q: I can't see icons in the menu.
# A: If you use Gnome 2.28+ you have to enable the icons via the GConf-Tool. Open a shell and execute 
# 
# gconftool-2 --type boolean --set /desktop/gnome/interface/menus_have_icons true
# 
# or use the gui program gconf-editor and navigate to 
# Desktop -> Gnome -> Interface -> Menus have Icons and enable it.


