#!/bin/sh

SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")

OMS_LIB_DIR="${SCRIPTPATH}/../lib/x86_64-linux-gnu"

# Add the oms install lib directory to PYTHONPATH.
if [ -z "$PYTHONPATH" ]; then export PYTHONPATH="${OMS_LIB_DIR}:${OMS_LIB_DIR}/omc"; else export PYTHONPATH="${OMS_LIB_DIR}:${OMS_LIB_DIR}/omc":$PYTHONPATH; fi

# On Linux, add the oms install LIB dir to LD_LIBRARY_PATH. That is where the shard lib is installed to.
# On Windows, add the oms install BIN dir to PATH. That is where the dll is installed to.
detected_OS="$(uname -s)"
case "${detected_OS}" in
  (Linux*)
    if [ -z "$LD_LIBRARY_PATH" ]; then export LD_LIBRARY_PATH="${OMS_LIB_DIR}"; else export LD_LIBRARY_PATH="${OMS_LIB_DIR}":$LD_LIBRARY_PATH; fi
    ;;
  (MINGW*)
    if [ -z "$PATH" ]; then export PATH="$SCRIPTPATH"; else export PATH="$SCRIPTPATH":$PATH; fi
    ;;
esac

# A ".py" argument is run as a driver script, as before. Anything else (e.g. a
# .ssp or .fmu model file) is handed to the OMSimulator CLI module instead.
case "$1" in
  (*.py)
    python3 "$@"
    ;;
  (*)
    python3 -m OMSimulator "$@"
    ;;
esac
