#!/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_user
#
# DESCRIPTION : This function creates the LFC manager user
#
# AUTHORS :     Akos.Frohner@cern.ch
#
# YAIM MODULE:  glite-yaim-lfc
#
##############################################################################

config_lfc_user_check () {
 requires $1 LFCMGR_USER_HOME LFCMGR_USER
 retcode=$?
 return ${retcode}
}


function config_lfc_user () {

  INSTALL_ROOT=${INSTALL_ROOT:-/opt}

  if [ "x${CONFIG_USERS}"="xyes" ]; then 
    if ( ! id ${LFCMGR_USER} > /dev/null 2>&1 ); then
        useradd -p "*NP*" -r -c "LFC user" -m -d ${LFCMGR_USER_HOME} ${LFCMGR_USER} > /dev/null 2>&1
    fi
  else 
    yaimlog WARNING "CONFIG_USERS is set to 'no'. User ${LFCMGR_USER} must exist in your system" 
    if ( ! id ${LFCMGR_USER} > /dev/null 2>&1 ); then
      yaimlog ERROR "User ${LFCMGR_USER} doesn't exist and CONFIG_USERS is set to 'no'. Please, create ${LFCMGR_USER} user" 
      yestr ${YEX_NOUSER} 
      yaimlog ERROR "${YERRORSTR}" 
      exit ${YEX_NOUSER} 
    fi 
  fi 

  return 0

}



