#!/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.
#
# Authors: 
#      Akos Frohner <Akos.Frohner@cern.ch>
#
# Configuration script for the gLite FTA channel agent

USAGE="$0 channel_name [--type urlcopy|srmcopy] [--dao oracle]"

PACKAGE='glite-data-transfer-agents'
CONFIGPREFIX='glite-transfer-channel-agent'

source $(dirname $0)/glite-data-config-service-common
check_NAME
assert_noconfig
guess_DAO
guess_TYPE TransferType
check_TYPE ${CONFIGPREFIX}-${TYPE}-${DAO}.config.xml
check_USER

$DRYRUN $GLITE_LOCATION/bin/glite_data_config_generator \
    -f $TEMPLATEDIR/${CONFIGPREFIX}-${TYPE}-${DAO}.config.xml \
    -o $CONFIGDIR/${CONFIGPREFIX}-${NAME}.properties.xml \
    -l $CONFIGDIR/${CONFIGPREFIX}-${NAME}.log-properties \
    -O transfer-channel-agent.Name=${NAME} \
    -O log.FileName=/var/log/glite/${CONFIGPREFIX}-${NAME}.log \
    $PROPERTYOPT

# cleanup
if [ $? -ne 0 ]; then
    echo "Error: configuration failed, cleanup." >&2
    rm $CONFIGDIR/${CONFIGPREFIX}-${NAME}.properties.xml \
       $CONFIGDIR/${CONFIGPREFIX}-${NAME}.log-properties
fi
