#!/bin/bash
source ./install.ini
sc_dir=${DEPLOY_DIR}/search-center

if [ ! -d ${sc_dir} ];then
	sudo cp -rf search-center ${sc_dir}
fi

#将配置文件存入环境变量文件，使其全局生效
sudo cp ./install.ini ${sc_dir}/install.ini.example
#sudo echo '' >${sc_dir}/.env
env_context=$(cat ${sc_dir}/install.ini.example |grep -v "^#"|grep -v "^$")
echo "${env_context}">${sc_dir}/.env
source ${sc_dir}/.env
sudo ln -s ${sc_dir}/.env ${sc_dir}/install.ini 2>/dev/null

#是否使用外部组件
if [ ${ES_ISUSE_STATUS} != 'false' ];then
	echo -e " 使用外部ES\n即将修改配置...."
	grep -A 10 -w "es:" ${APP_CONF_DIR}/application.yml | \
	                 sed -e "s#host: .*#host: ${ES_HOST}#g"\
			     -e "s#username: .*#username: ${ES_USERNAME}#g"\
			     -e "s#password: .*#password: ${ES_PASSWORD}#g"\
			     -e "s#httpPort: .*#httpPort: ${ES_HTTP_PORT}#g"\
			     -e "s#tcpPort: .*#tcpPort: ${ES_TCP_PORT}#g"

	
fi
echo ${MQ_ISUSE_STATUS}
if [ ${MQ_ISUSE_STATUS} != 'false' ];then
        echo -e " 使用外部MQ\n即将修改配置...."
        grep -A 6 -w "rabbitmq:" ${APP_CONF_DIR}/application.yml | \
                         sed -e "s#host: .*#host: ${MQ_HOST}#g"\
                             -e "s#username: .*#username: ${MQ_USERNAME}#g"\
                             -e "s#password: .*#password: ${MQ_PASSWORD}#g"\
                             -e "s#virtual-host: .*#virtual-host: ${MQ_VHOST}#g"

fi


