#!/bin/bash
##############################################################################
# Copyright (c) Members of the EGEE Collaboration. 2011.
# 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_DPM_nfs
#
# DESCRIPTION : This function configures the DPM NFS server
#
# AUTHORS :     it-dep-gt-dms@cern.ch
#
# YAIM MODULE:  glite-yaim-dpm
#
##############################################################################


config_DPM_nfs_check () {
  requires $1 DPM_HOST DPM_NFS DPM_NFS_CONFIG
}


config_DPM_nfs () {
  if [ "$DPM_NFS" == "no" ]; then
    yaimlog WARNING "DPM_NFS set to no. NFS access to DPM will not be configured"
    return 0
  fi

  DPNS_HOST=${DPNS_HOST:-$DPM_HOST}
  
  # Modify sysconfig
  sed -i "s?CONFIGFILE=.*?CONFIGFILE=${DPM_NFS_CONFIG}?g"       "/etc/sysconfig/dpm-nfs"
  sed -i "s?GSS=.*?GSS=${DPM_NFS_GSS}?g"                        "/etc/sysconfig/dpm-nfs"
  
  # Modify dpm nfs configuration file
  sed -i "s?dpns_host.*=.*?dpns_host = ${DPNS_HOST};?g"          "${DPM_NFS_CONFIG}"
  sed -i "s?dpm_host.*=.*?dpm_host = ${DPM_HOST};?g"             "${DPM_NFS_CONFIG}"
  
  # Restart service (standard location under /etc/init.d)
  service dpm-nfs restart
  if [ $? -ne 0 ]; then
    yaimlog ERROR "Could not start the dpm-nfs daemon"
    return 1
  fi
  
  # Done
  return 0
}
