#!/bin/bash
##############################################################################
# Copyright (c) Members of the EGEE Collaboration. 2008.
# 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_lfc_dli
#
# DESCRIPTION : This function configures the Data Location Interface
#
# AUTHORS :     Akos.Frohner@cern.ch
#
# YAIM MODULE:  glite-yaim-lfc
#
##############################################################################

config_lfc_dli_check () {
 requires $1 LFC_HOST
 retcode=$?
 return ${retcode}
}

function config_lfc_dli () {

 ####@ If /etc/sysconfig/lfc-dli already exists, do not overwrite it with the template.
 ####@ Otherwise, only substitute the needed values

 if [ ! -f /etc/sysconfig/lfc-dli ]; then
        cp /etc/sysconfig/lfc-dli.templ /etc/sysconfig/lfc-dli
 fi

 sed -i "s/^.*LFC_HOST.*$/LFC_HOST=${LFC_HOST}/" /etc/sysconfig/lfc-dli

 ####@ Temporary fix in case RUN_DLIDAEMON="yes" is missing from the existing sysconfig file

 grep -q RUN_DLIDAEMON /etc/sysconfig/lfc-dli
 if [ $? -eq 1 ]; then
	echo "RUN_DLIDAEMON=\"yes\"" >> /etc/sysconfig/lfc-dli
 fi

 ####@ End of temporary fix


 /sbin/chkconfig --add lfc-dli
 /sbin/service lfc-dli restart
 /sbin/chkconfig lfc-dli on

 return 0

}

