##############################################################################
# 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_hydra
#
# DESCRIPTION : This function configures HYDRA.
#
# AUTHORS :     Akos.Frohner@cern.ch
#
# NOTES :       -- 
#
# YAIM MODULE:  glite-yaim-hydra
#                 
##############################################################################

config_hydra_check () {

    requires $1 HYDRA_INSTANCES MYSQL_PASSWORD
    return $?

}


config_hydra () {

if [ -z "$HYDRA_DB_HOSTNAME" -o "$HOSTNAME" = "$HYDRA_DB_HOSTNAME" ]; then
    yaimlog INFO "The DB server is on this host: starting it"
    start_mysql || return 1
fi

echo "$MYSQL_PASSWORD" | grep -q '@'
if [ $? -eq 0 ]; then
     yaimlog ERROR "The MySQL password cannot contain the '@' character!"
     return 1
fi

yaimlog INFO "Setting the root password in MySQL"
set_mysql_passwd || return 1

yaimlog INFO "Installing the MySQL JDBC driver"
JAVA_HOME=/usr/lib/jvm/java build-jar-repository /var/lib/tomcat5/common/lib mysql-connector-java

${GLITE_LOCATION_ETC}/hydra-service/configure --values ${SITE_INFO} --withpass ${MYSQL_PASSWORD}

/sbin/service tomcat5 condrestart

return 0

}

