#!/bin/bash

. ./param_bash.ini

LB=$1
cd ${APP_HOME}/${SOFT_DIR}${SLOT_NUMBER}/install
cat conf_tml.dat | \
sed \
 -e "s@^_PROTOCOL_PDS *=.*@_PROTOCOL_PDS  =  ${PDS_PRO}@" \
 -e "s@^_PLATFORM_NAME *=.*@_PLATFORM_NAME  =  ${OS_TYPE}@" \
 -e "s@^_AL_COPY *=.*@_AL_COPY     =  ${SLOT_NUMBER}@" \
 -e "s@^_HOST_S *=.*@_HOST_S    =  $SERVER_HOST@" \
 -e "s@^_INST_ID *=.*@_INST_ID    =  $INST_ID@" \
 -e "s@^_ORA_SID *=.*@_ORA_SID    =  $ORACLE_SID@" \
 -e "s@^_ORA_OWN *=.*@_ORA_OWN    =  $ORACLE_USER@" \
 -e "s@^_HOST_WWW *=.*@_HOST_WWW    =  $SERVER_NAME@" \
 -e "s@^_HOST_DEP *=.*@_HOST_DEP    =  $DEPOSIT_SERVER@" \
 -e "s@^_HOST_REP *=.*@_HOST_REP    =  $REPOSIT_SERVER@" \
 -e "s@^_HOST_PER *=.*@_HOST_PER    =  $PERMANENT_SERVER@" \
 -e "s@^_HOST_DEL *=.*@_HOST_DEL    =  $DELIVERY_SERVER@" \
 -e "s@^_HOST_ORA *=.*@_HOST_ORA    =  $ORACLE_HOST@" \
 -e "s@^_ORA_VER *=.*@_ORA_VER     =  $ORACLE_VER@" \
 -e "s@^_ORA_DIR_VER *=.*@_ORA_DIR_VER     =  $ORACLE_DIR_VER@" \
 -e "s@^_HOST_DASHBOARD *=.*@_HOST_DASHBOARD    =  $REPOSIT_SERVER@" \
 -e "s@^_ORA_BASE *=.*@_ORA_BASE    =  ${ORACLE_BASE}@" \
 -e "s@^_ORA_INST_ID *=.*@_ORA_INST_ID    =  ${ORA_UPREFIX}@" \
 -e "s@^_OS *=.*@_OS          =  $OSN@" \
 -e "s@^_GRIDGAIN_JGROUPS_INITIAL_SERVERS *=.*@_GRIDGAIN_JGROUPS_INITIAL_SERVERS = ${GRID_JGRP}@" \
 -e "s@^_DELIVERY_SHARED *=.*@_DELIVERY_SHARED                =  $DELIVERY_SHARED@" \
 -e "s@^_DEPOSIT_REPOSITORY *=.*@_DEPOSIT_REPOSITORY          =  $DEPOSIT_REPOSITORY@" \
 -e "s@^_OPERATIONAL_SHARED *=.*@_OPERATIONAL_SHARED          =  $OPERATIONAL_SHARED@" \
 -e "s@^_OPERATIONAL_REPOSITORY *=.*@_OPERATIONAL_REPOSITORY  =  $OPERATIONAL_REPOSITORY@" \
 -e "s@^_PERMANENT_REPOSITORY *=.*@_PERMANENT_REPOSITORY      =  $PERMANENT_REPOSITORY@" \
> install_dps.tml
if [ "$?" != "0" ] ; then
        exit 1
fi
mv conf_tml.dat conf_tml.dat.$DD
mv install_dps.tml conf_tml.dat
if [ "${LB}" = "Y" ] ; then
    if [ "${DEP_LB_PORT}" = "80" ] ; then
        #export DEP_LB_PORT=""
        export LB_DEP=${DEP_LB}
    else
        export LB_DEP="${DEP_LB}:${DEP_LB_PORT}"
    fi
    if [ "${DEL_LB_PORT}" = "80" ] ; then
        #export DEL_LB_PORT=""
        export LB_DEL=${DEL_LB}
    else
        export LB_DEL="${DEL_LB}:${DEL_LB_PORT}"
    fi
    if [ "${REP_LB_PORT}" = "80" ] ; then
        #export REP_LB_PORT=""
        export LB_REP=${REP_LB}
    else
        export LB_REP="${REP_LB}:${REP_LB_PORT}"
    fi
    if [ "${PER_LB_PORT}" = "80" ] ; then
        #export PER_LB_PORT=""
        export LB_PER=${PER_LB}
    else
        export LB_PER="${PER_LB}:${PER_LB_PORT}"
    fi
    if [ "${PDS_LB_PORT}" = "80" ] ; then
        #export PDS_LB_PORT=""
        export LB_PDS=${PDS_LB}
    else
        export LB_PDS="${PDS_LB}:${PDS_LB_PORT}"
    fi
    cat conf_tml.dat | \
    sed \
    -e "s@^_HOST_PDS *=.*@_HOST_PDS    = ${PDS_LB}@" \
    -e "s@^_DEL_SERVERS_LIST *=.*@_DEL_SERVERS_LIST    = ${DEL_LIST}@" \
    -e "s@^_DEP_SERVERS_LIST *=.*@_DEP_SERVERS_LIST    = ${DEP_LIST}@" \
    -e "s@^_REP_SERVERS_LIST *=.*@_REP_SERVERS_LIST    = ${REP_LIST}@" \
    -e "s@^_PER_SERVERS_LIST *=.*@_PER_SERVERS_LIST    = ${PER_LIST}@" \
    -e "s@^_HOST_LB_DEP *=.*@_HOST_LB_DEP = ${DEP_LB}@" \
    -e "s@^_DEP_LB_PORT *=.*@_DEP_LB_PORT = ${DEP_LB_PORT}@" \
    -e "s@^_HOST_LB_DEL *=.*@_HOST_LB_DEL = ${DEL_LB}@" \
    -e "s@^_DEL_LB_PORT *=.*@_DEL_LB_PORT = ${DEL_LB_PORT}@" \
    -e "s@^_HOST_LB_REP *=.*@_HOST_LB_REP = ${REP_LB}@" \
    -e "s@^_REP_LB_PORT *=.*@_REP_LB_PORT = ${REP_LB_PORT}@" \
    -e "s@^_HOST_LB_PER *=.*@_HOST_LB_PER = ${PER_LB}@" \
    -e "s@^_PER_LB_PORT *=.*@_PER_LB_PORT = ${PER_LB_PORT}@" \
    -e "s@^_HOST_LB_PDS *=.*@_HOST_LB_PDS = ${PDS_LB}@" \
    -e "s@^_PDS_LB_PORT *=.*@_PDS_LB_PORT = ${PDS_LB_PORT}@" \
    -e "s@^_LB_DEP *=.*@_LB_DEP = ${LB_DEP}@" \
    -e "s@^_LB_DEL *=.*@_LB_DEL = ${LB_DEL}@" \
    -e "s@^_LB_REP *=.*@_LB_REP = ${LB_REP}@" \
    -e "s@^_LB_PER *=.*@_LB_PER = ${LB_PER}@" \
    -e "s@^_LB_PDS *=.*@_LB_PDS = ${LB_PDS}@" \
    > install_dps.tml
    if [ "$?" != "0" ] ; then
        exit 1
    fi
    mv conf_tml.dat conf_tml.dat.$DD
    mv install_dps.tml conf_tml.dat
fi
if [ "${ORAC}" = "Y" ] ; then
    cat conf_tml.dat | \
    sed \
    -e "s#^_ORA_URL *=.*#_ORA_URL     =  ${RAC_JDBC}#" \
    > install_dps.tml
    if [ "$?" != "0" ] ; then
        exit 1
    fi
    mv conf_tml.dat conf_tml.dat.$DD
    mv install_dps.tml conf_tml.dat
fi
perl utml -s >> $gen_log 2>&1 
exit 0
