#!/bin/bash

################################################################################
################################################################################
# Copyright 2023-2025 by NI SP Software GmbH, All rights reserved.
# Copyright 1999-2023 by Nice, srl., All rights reserved.
#
# This software includes confidential and proprietary information
# of NI SP Software GmbH ("Confidential Information").
# You shall not disclose such Confidential Information
# and shall use it only in accordance with the terms of
# the license agreement you entered into with NI SP Software.
################################################################################
################################################################################
################################################################################
# $EF_ROOT/plugins/lsf/bin/common - common settings for LSF Plugin
################################################################################


#-------------------------------------------------------------------------------
# Avoid recursive loops
#-------------------------------------------------------------------------------
if [ -n "$EF_LSF_DO_NOT_RECURSE" ] ; then
  exit 0
fi

EF_LSF_DO_NOT_RECURSE="true"
export EF_LSF_DO_NOT_RECURSE


EF_PLUGIN_NAME="EnginFrame LSF Plug-in"
export EF_PLUGIN_NAME

EF_PLUGIN_FILE="EFLSF"
export EF_PLUGIN_FILE

EF_PLUGIN_ROOT="${EF_ROOT}/plugins/lsf"
export EF_PLUGIN_ROOT

#-------------------------------------------------------------------------------
# Load common EnginFrame functions and environment
#-------------------------------------------------------------------------------

. "${EF_ROOT}/plugins/ef/lib/functions"

ef_init_environment "$@"


#-------------------------------------------------------------------------------
# Load LSF Plug-in configuration
#-------------------------------------------------------------------------------

. "${EF_ROOT}/plugins/lsf/bin/lsf.commands"

# Special settings for LSF MultiCluster
if [ ! "${LSF_MULTICLUSTER}" = "true" ] ; then
    LSF_MULTICLUSTER="false"
fi


#-------------------------------------------------------------------------------
# Check LSF is up and store cluster name
#-------------------------------------------------------------------------------

_lsid=`${EF_LSF_LSID} 2>&1`
if [ "$?" != "0" ] ; then
    ef_error "${_lsid}" "EnginFrame LSF Plugin Error" "${EF_LSF_LSID}"
    exit 1
fi

LSF_CLUSTER_ID=`echo "${_lsid}" | sed -n 's/^My cluster name is \(.*\)$/\1/p'`
EF_MYLSFMASTER=`echo "${_lsid}" | sed -n 's/^My master name is \(.*\)$/\1/p'`
export LSF_CLUSTER_ID EF_MYLSFMASTER


#-------------------------------------------------------------------------------
# Get and export LSF version numbers
#-------------------------------------------------------------------------------

LSF_BHOSTS_VERSION=`"${EF_LSF_BHOSTS}" -V 2>&1`

if [ -z "${LSF_IS_OPENLAVA}" ]; then
  LSF_VERSION_MAJOR=`echo "${LSF_BHOSTS_VERSION}" | sed '/ LSF /!d;s/^[a-zA-Z ]* \([0-9]*\).\([0-9]*\).*$/\1/'`
  LSF_VERSION_MINOR=`echo "${LSF_BHOSTS_VERSION}" | sed '/ LSF /!d;s/^[a-zA-Z ]* \([0-9]*\).\([0-9]*\).*$/\2/'`
  if [ ${LSF_VERSION_MAJOR} -le 6 -a ${LSF_VERSION_MINOR} -lt 2 ]; then
    EF_LSF_BHOSTS_X=""
    export EF_LSF_BHOSTS_X
  fi
  EF_LSF_LSLOAD_W="-w ${LSF_CLUSTER_ID}"
  export EF_LSF_LSLOAD_W
else
  LSF_VERSION_MAJOR=`echo "${LSF_BHOSTS_VERSION}" | sed '/[Oo]pen[Ll]ava /!d;s/^[a-zA-Z ]* \([0-9]*\).\([0-9]*\).*$/\1/'`
  LSF_VERSION_MINOR=`echo "${LSF_BHOSTS_VERSION}" | sed '/[Oo]pen[Ll]ava /!d;s/^[a-zA-Z ]* \([0-9]*\).\([0-9]*\).*$/\2/'`
fi

export LSF_VERSION_MAJOR LSF_VERSION_MINOR


#-------------------------------------------------------------------------------
# Load common LSF Plugin functions
#-------------------------------------------------------------------------------

. "${EF_ROOT}/plugins/lsf/bin/functions.lib.sh"

#
# vi: ts=4 sw=4 et syntax=sh 
#

