#!/bin/bash
##############################################################################
# Copyright (c) Members of the EGEE Collaboration. 2004. 
# See http://www.eu-egee.org/partners/ for details on the copyright 
# holders.  
#
# Licensed under the Apache License, Version 2.0 (the "License"); 
# you may not use this file except in compliance with the License. 
# You may obtain a copy of the License at 
#
#    http://www.apache.org/licenses/LICENSE-2.0 
#
# Unless required by applicable law or agreed to in writing, software 
# distributed under the License is distributed on an "AS IS" BASIS, 
# WITHOUT WARRANTIES OR CONDITIONS 
# OF ANY KIND, either express or implied. 
# See the License for the specific language governing permissions and 
# limitations under the License.
##############################################################################
#
# NAME :        config_glite_saga
#
# DESCRIPTION : This function caals the saga-adapter-setup script to
#               configure the SAGA adapters for gLite.
#
# AUTHORS :     yaim-contact@cern.ch
#
# NOTES :       
#
# YAIM MODULE:  glite-yaim-clients
#                 
##############################################################################

config_glite_saga_check () {

   if [ "x$CONFIG_SAGA" != "xyes" ]; then
     return 0
   fi

   requires $1 GLITE_LOCATION SAGA_LOCATION JAVA_SAGA_LOCATION
   return $?

}

config_glite_saga_setenv () {

 if [ "x${CONFIG_SAGA}" != "xyes" ]; then
    return 0
  fi

#  if [ -d ${GLITE_LOCATION}/lib ]; then
#    yaimgridpath_prepend LD_LIBRARY_PATH ${GLITE_LOCATION}/lib
#  fi
#  if [ -d ${SAGA_LOCATION}/lib ]; then
#    yaimgridpath_prepend LD_LIBRARY_PATH ${SAGA_LOCATION}/lib
#  fi
#  if [ -d ${SAGA_LOCATION}/boost_1_35_0/lib ]; then
#    yaimgridpath_prepend LD_LIBRARY_PATH ${SAGA_LOCATION}/boost_1_35_0/lib 
#  fi
  yaimgridenv_set SAGA_LOCATION ${SAGA_LOCATION}
  yaimgridenv_set JAVA_SAGA_LOCATION ${JAVA_SAGA_LOCATION} 

}

config_glite_saga () {

 if [ "s${CONFIG_SAGA}" != "xyes" ]; then
    return 0
  fi

  if [ -f ${GLITE_LOCATION}/sbin/saga-adapter-setup ]; then
    ${GLITE_LOCATION}/sbin/saga-adapter-setup --glite_location=${GLITE_LOCATION} --cpp_saga_location=${SAGA_LOCATION} --java_saga_location=${JAVA_SAGA_LOCATION}
    if [ $? -ne 0 ]; then
      yestr ${YEX_CONFFILE}
      yaimlog ERROR "${GLITE_LOCATION}/sbin/saga-adapter-setup returned with error !"
      yaimlog ERROR "${YERRORSTR}"
      exit ${YEX_CONFFILE}
    fi
  else
    yestr ${YEX_NOSUCHFILE}
    yaimlog ERROR "${GLITE_LOCATION}/sbin/saga-adapter-setup is probably not installed !"
    yaimlog ERROR "${YERRORSTR}"
    exit ${YEX_NOSUCHFILE}
  fi

  return 0

}

