######################################################################
#### function: generate_config
####author:danial_chen
####create date:2019-11-07
####modify date:2019-11-07
######################################################################
#/bin/bash

pd=$PWD
cp -rf $pd/kingdee_hosts_template $pd/kingdee_hosts

## 生成kingdee_hosts文件，配置各[XXXXXX]下的内容 ##
eval $(cat $pd/config | grep -v "^#" | sed -n '/^\[K8S_MASTER\]/,/^$/p' | awk -F' ' '/^[0-9]/ {i++;S[i]=$0;print "S["i"]=" "\""S[i]"\""}')
k8s_master=${#S[@]}

eval $(cat $pd/config | grep -v "^#" | sed -n '/^\[K8S_NODE\]/,/^$/p' | awk -F' ' '/^[0-9]/ {j++;T[j]=$0;print "T["j"]=" "\""T[j]"\""}')
k8s_node=${#T[@]}

eval $(cat $pd/config | grep -v "^#" | sed -n '/^\[mysql\]/,/^$/p' | awk -F' ' '/^[0-9]/ {j++;M[j]=$0;print "M["j"]=" "\""M[j]"\""}')
mysql=${#M[@]}

eval $(cat $pd/config | grep -v "^#" | sed -n '/^\[zookeeper\]/,/^$/p' | awk -F' ' '/^[0-9]/ {j++;Z[j]=$0;print "Z["j"]=" "\""Z[j]"\""}')
zookeeper=${#Z[@]}

eval $(cat $pd/config | grep -v "^#" | sed -n '/^\[rabbitmq\]/,/^$/p' | awk -F' ' '/^[0-9]/ {j++;R[j]=$0;print "R["j"]=" "\""R[j]"\""}')
rabbitmq=${#R[@]}

eval $(cat $pd/config | grep -v "^#" | sed -n '/^\[redis_cache\]/,/^$/p' | awk -F' ' '/^[0-9]/ {j++;C[j]=$0;print "C["j"]=" "\""C[j]"\""}')
redis_cache=${#C[@]}

eval $(cat $pd/config | grep -v "^#" | sed -n '/^\[redis_session\]/,/^$/p' | awk -F' ' '/^[0-9]/ {j++;B[j]=$0;print "B["j"]=" "\""B[j]"\""}')
redis_session=${#B[@]}

eval $(cat $pd/config | grep -v "^#" | sed -n '/^\[redis_algo\]/,/^$/p' | awk -F' ' '/^[0-9]/ {j++;A[j]=$0;print "A["j"]=" "\""A[j]"\""}')
redis_algo=${#A[@]}

eval $(cat $pd/config | grep -v "^#" | sed -n '/^\[nginx\]/,/^$/p' | awk -F' ' '/^[0-9]/ {j++;N[j]=$0;print "N["j"]=" "\""N[j]"\""}')
nginx=${#N[@]}

eval $(cat $pd/config | grep -v "^#" | sed -n '/^\[mdd\]/,/^$/p' | awk -F' ' '/^[0-9]/ {j++;D[j]=$0;print "D["j"]=" "\""D[j]"\""}')
mdd=${#D[@]}

eval $(cat $pd/config | grep -v "^#" | sed -n '/^\[mservice\]/,/^$/p' | awk -F' ' '/^[0-9]/ {j++;I[j]=$0;print "I["j"]=" "\""I[j]"\""}')
mservice=${#I[@]}

eval $(cat $pd/config | grep -v "^#" | sed -n '/^\[mc\]/,/^$/p' | awk -F' ' '/^[0-9]/ {j++;Y[j]=$0;print "Y["j"]=" "\""Y[j]"\""}')
mc=${#Y[@]}

eval $(cat $pd/config | grep -v "^#" | sed -n '/^\[mservice-qing\]/,/^$/p' | awk -F' ' '/^[0-9]/ {j++;Q[j]=$0;print "Q["j"]=" "\""Q[j]"\""}')
qing=${#Q[@]}

eval $(cat $pd/config | grep -v "^#" | sed -n '/^\[fileserver\]/,/^$/p' | awk -F' ' '/^[0-9]/ {j++;F[j]=$0;print "F["j"]=" "\""F[j]"\""}')
fileserver=${#F[@]}

eval $(cat $pd/config | grep -v "^#" | sed -n '/^\[kafka\]/,/^$/p' | awk -F' ' '/^[0-9]/ {j++;K[j]=$0;print "K["j"]=" "\""K[j]"\""}')
kafka=${#K[@]}

eval $(cat $pd/config | grep -v "^#" | sed -n '/^\[elasticsearch\]/,/^$/p' | awk -F' ' '/^[0-9]/ {j++;E[j]=$0;print "E["j"]=" "\""E[j]"\""}')
elasticsearch=${#E[@]}

eval $(cat $pd/config | grep -v "^#" | sed -n '/^\[logstash\]/,/^$/p' | awk -F' ' '/^[0-9]/ {j++;L[j]=$0;print "L["j"]=" "\""L[j]"\""}')
logstash=${#L[@]}

for j in `seq 1 ${k8s_master}`;do
	ip=`echo ${S[j]} | awk -F' ' '{print $1}'` 
	hostname[$j]=`ansible $ip -i $pd/config -m shell -a "hostname" | sed -n "2, 1p" | awk '{print $1}'`
done

for j in `seq 1 ${k8s_node}`;do
	ip=`echo ${T[j]} | awk -F' ' '{print $1}'` 
	hostname2[$j]=`ansible $ip -i $pd/config -m shell -a "hostname" | sed -n "2, 1p" | awk '{print $1}'`
done

for ((s=${k8s_master}; s>0; s--))
do
	k8s_master_node="${S[s]} hostname=${hostname[s]} order=${s} kporder=${s}"
    sed "/\[K8S_MASTER\]/a\\${k8s_master_node}" -i $pd/kingdee_hosts
done

for ((t=${k8s_node}; t>0; t--))
do
	k8s_node_node="${T[t]} hostname=${hostname2[t]} k8s_node_order=${t}"
    sed "/\[K8S_NODE\]/a\\${k8s_node_node}" -i $pd/kingdee_hosts
done

for ((m=${mysql}; m>0; m--))
do
	mysql_node="${M[m]} mysql_order=${m}"
    sed "/\[mysql\]/a\\${mysql_node}" -i $pd/kingdee_hosts
done

for ((z=${zookeeper}; z>0; z--))
do
	zookeeper_node="${Z[z]} zookeeper_order=${z}"
	sed "/\[zookeeper\]/a\\${zookeeper_node}" -i $pd/kingdee_hosts
done

for ((r=${rabbitmq}; r>0; r--))
do
	rabbitmq_node="${R[r]} rabbitmq_order=${r}"
	sed "/\[rabbitmq\]/a\\${rabbitmq_node}" -i $pd/kingdee_hosts
done

for ((c=${redis_cache}; c>0; c--))
do
	redis_cache_node="${C[c]} redis_cache_order=${c}"
	sed "/\[redis_cache\]/a\\${redis_cache_node}" -i $pd/kingdee_hosts
done

for ((b=${redis_session}; b>0; b--))
do
	redis_session_node="${B[b]} redis_session_order=${b}"
	sed "/\[redis_session\]/a\\${redis_session_node}" -i $pd/kingdee_hosts
done

for ((a=${redis_algo}; a>0; a--))
do
	redis_algo_node="${A[a]} redis_algo_order=${a}"
	sed "/\[redis_algo\]/a\\${redis_algo_node}" -i $pd/kingdee_hosts
done

if [ ${nginx} = 1 ];then
    sed "/\[nginx\]/a\\${N[1]} nginx_order=0" -i $pd/kingdee_hosts
else
for ((n=${nginx}; n>0; n--))
do
	nginx_node="${N[n]} nginx_order=${n}"
	sed "/\[nginx\]/a\\${nginx_node}" -i $pd/kingdee_hosts
done
fi

for ((d=${mdd}; d>0; d--))
do
	mdd_node="${D[d]} mdd_order=${d}"
	sed "/\[mdd\]/a\\${mdd_node}" -i $pd/kingdee_hosts
done

for ((i=${mservice}; i>0; i--))
do
	mservice_node="${I[i]} mservice_order=${i}"
	sed "/\[mservice\]/a\\${mservice_node}" -i $pd/kingdee_hosts
done

for ((y=${mc}; y>0; y--))
do
	mc_node="${Y[y]} mc_order=${y}"
	sed "/\[mc\]/a\\${mc_node}" -i $pd/kingdee_hosts
done

for ((q=${mservice-qing}; q>0; q--))
do
	qing_node="${Q[q]} qing_order=${q}"
	sed "/\[mservice-qing\]/a\\${qing_node}" -i $pd/kingdee_hosts
done

for ((f=${fileserver}; f>0; f--))
do
	fileserver_node="${F[f]} fileserver_order=${f}"
	sed "/\[fileserver\]/a\\${fileserver_node}" -i $pd/kingdee_hosts
done

for ((k=${kafka}; k>0; k--))
do
	kafka_node="${K[k]} kafka_order=${k}"
	sed "/\[kafka\]/a\\${kafka_node}" -i $pd/kingdee_hosts
done

for ((e=${elasticsearch}; e>0; e--))
do
	es_node="${E[e]} es_order=${e}"
	sed "/\[elasticsearch\]/a\\${es_node}" -i $pd/kingdee_hosts
done

for ((l=${logstash}; l>0; l--))
do
	logstash_node="${L[l]} logstash_order=${l}"
	sed "/\[logstash\]/a\\${logstash_node}" -i $pd/kingdee_hosts
done

## 用于判断config文件中clustername、tenantid、nginx_vip、nginx_ierpport、sharePath、mysql_vip的值是否为空 ##
clustername_value=`cat $pd/config |grep clustername= |awk -F "=" '{print $2}'|sed 's/[ ]*$//g'`
tenantid_value=`cat $pd/config |grep tenantid= |awk -F "=" '{print $2}'|sed 's/[ ]*$//g'`
nginx_vip_value=`cat $pd/config |grep nginx_vip= |awk -F "=" '{print $2}'|sed 's/[ ]*$//g'`
elb_host_value=`cat $pd/config |grep elb_host= |awk -F "=" '{print $2}'|sed 's/[ ]*$//g'`
nginx_ierpport_value=`cat $pd/config |grep nginx_ierpport= |awk -F "=" '{print $2}'|sed 's/[ ]*$//g'`
sharePath_value=`cat $pd/config |grep sharePath= |awk -F "=" '{print $2}'|sed 's/[ ]*$//g'`
mysql_vip_value=`cat $pd/config |grep mysql_vip= |awk -F "=" '{print $2}'|sed 's/[ ]*$//g'`
k8s_vip_value=`cat $pd/config |grep k8s_vip= |awk -F "=" '{print $2}'|sed 's/[ ]*$//g'`
mdd_vip_value=`cat $pd/config |grep mdd_vip= |awk -F "=" '{print $2}'|sed 's/[ ]*$//g'`
keepalivedIf_value=`cat $pd/config | grep -v \#.*keepalived | grep keepalivedIf= |awk -F "=" '{print $2}'|sed 's/[ ]*$//g'`

## 用于获取kingdee_hosts中自行安装组件的IP地址 ##
k8smaster_hosts=(`cat $pd/kingdee_hosts |awk '/\[K8S_MASTER\]/,/\[K8S_NODE\]/' |grep order|awk '{print $1}'`)
k8snode_hosts=(`cat $pd/kingdee_hosts |grep k8s_node_order|awk '{print $1}'`)
k8s_nodes=( "${k8smaster_hosts[@]}" "${k8snode_hosts[@]}" )
mysql_master_ip=`cat $pd/kingdee_hosts |grep mysql_order=1 |awk '{print $1}'`
zookeeper_ip=(`cat $pd/kingdee_hosts |grep zookeeper_order|awk '{print $1}'`)
mq_ip=(`cat $pd/kingdee_hosts |grep rabbitmq_order|awk '{print $1}'`)
cache_ip=(`cat $pd/kingdee_hosts |grep redis_cache_order|awk '{print $1}'`)
session_ip=(`cat $pd/kingdee_hosts |grep redis_session_order|awk '{print $1}'`)
algo_ip=(`cat $pd/kingdee_hosts |grep redis_algo_order|awk '{print $1}'`)
nginx_ip=(`cat $pd/kingdee_hosts |grep nginx_order|awk '{print $1}'`)
mddhost=`cat $pd/kingdee_hosts |grep mdd_order=1 |awk '{print $1}'`
ierp_hosts=(`cat $pd/kingdee_hosts |grep mservice_order|awk '{print $1}'`)
mc_hosts=(`cat $pd/kingdee_hosts |grep mc_order|awk '{print $1}'`)
fileserver_hosts=(`cat $pd/kingdee_hosts |grep fileserver_order|awk '{print $1}'`)
kafka_ip=`cat $pd/kingdee_hosts |grep kafka_order|awk '{print $1}'`
es_ip=`cat $pd/kingdee_hosts |grep es_order|awk '{print $1}'`
#k8e_ip=`cat $pd/kingdee_hosts |grep k8e_order|awk '{print $1}'`

#获取、配置自行安装组件相关参数函数
function Get_Autonomous_Value()
{
for i in "$@"
do
eval ${i}_value=`awk '/^\[K8S_MASTER\]/,/^\[provide\]/' $pd/config|grep -v ^#|grep $i=|awk -F "=" '{print $2}'|sed 's/[ ]*$//g'|sed -e 's/&/\\\\\\\\\\\&/g' -e 's/\//\\\\\\\\\//g'`
if [ -z "`eval echo '$'"$i"_value`" ];then
    eval ${i}_value=`cat $pd/default.config|grep -v ^#|grep $i=|awk -F "=" '{print $2}'|sed 's/[ ]*$//g'`
fi
sed -i  "s/$i\=/&\"`eval echo '$'"$i"_value`\"/"  $pd/kingdee_hosts
done
}

#获取、配置已提供组件相关参数函数
function Get_Provide_Value()
{
for i in "$@"
do
eval ${i}_value=`awk '/provide:/,/aaaaaaaaaa/' $pd/config|grep -v ^#|grep $i=|awk -F "=" '{print $2}'|sed 's/[ ]*$//g'|sed -e 's/&/\\\\\\\\\\\&/g' -e 's/\//\\\\\\\\\//g'`
if [ -z "`eval echo '$'"$i"_value`" ];then
    echo "Please enter $i in config!"
	exit 1
fi
sed -i  "s/$i\=/&\"`eval echo '$'"$i"_value`\"/"  $pd/kingdee_hosts
done
}

#判断各组件是否容器部署的函数
function Service_isk8s()
{
for i in "$@"
do
eval ${i}_value=`cat $pd/kingdee_hosts |grep ${i}_order |wc -l`
if [ `eval echo '$'"$i"_value` -eq 0 ];then
    sed "s/${i}_isk8s\=/&1/" -i $pd/kingdee_hosts
else
    sed "s/${i}_isk8s\=/&0/" -i $pd/kingdee_hosts
fi
done
}

## 配置kingdee_hosts中[all:var]下配置项的值 ##
## [all:var] ##
if [ -n "$clustername_value" ];then
    sed "s/clustername\=/&\"$clustername_value\"/" -i $pd/kingdee_hosts
else
    echo "Please enter clustername in config!"
    exit 1
fi

if [ -n "$tenantid_value" ];then
    sed "s/tenantid\=/&\"$tenantid_value\"/" -i $pd/kingdee_hosts
else
    echo "Please enter tenantid in config!"
    exit 1
fi

if [ -n "$nginx_ierpport_value" ];then
    sed "s/nginx_ierpport\=/&\"$nginx_ierpport_value\"/" -i $pd/kingdee_hosts
else
    if [ ${nginx} != 0 ];then
        echo "Please enter nginx_ierpport in config!"
        exit 1
    fi
fi

if [[ ${nginx} = 1 ]];then
    sed "s/nginx_vip\=/&\"$nginx_ip\"/" -i $pd/kingdee_hosts
    sed "s/elb_host\=/&\"null\"/" -i $pd/kingdee_hosts
elif [[ ${nginx} > 1 && -n "$nginx_vip_value" ]];then
    sed "s/nginx_vip\=/&\"$nginx_vip_value\"/" -i $pd/kingdee_hosts
    if [ -n "$elb_host_value" ];then
        sed "s/elb_host\=/&\"$elb_host_value\"/" -i $pd/kingdee_hosts
    else
            sed "s/elb_host\=/&\"null\"/" -i $pd/kingdee_hosts
    fi
elif [[ ${nginx} > 1 && -z "$nginx_vip_value" ]];then
    if [ -n "$elb_host_value" ];then
        sed "s/elb_host\=/&\"$elb_host_value\"/" -i $pd/kingdee_hosts
    else
        echo "Please enter nginx_vip or elb_host in config!"
        exit 1
    fi
fi

sharePath_value=`cat $pd/config |grep sharePath= |awk -F "=" '{print $2}'|sed 's/[ ]*$//g'`
if [[ -n "$sharePath_value" && ${nginx} > 1 ]];then
    sed "s#sharePath\=#&\"$sharePath_value\"#" -i $pd/kingdee_hosts
elif [[ -z "$sharePath_value" && ${nginx} > 1 ]];then
    echo "Please enter sharePath in config!"
    exit 1
fi

if [ ${mysql} -gt 0 ];then
    if [ -z "$mysql_vip_value" ];then
        sed "s/mysql_vip\=/&\"mysql_vip\"/" -i $pd/kingdee_hosts
        sed "s/db_host\=/&\"$mysql_master_ip\"/" -i $pd/kingdee_hosts
	else
		sed "s/mysql_vip\=/&\"$mysql_vip_value\"/" -i $pd/kingdee_hosts
	    sed "s/db_host\=/&\"$mysql_vip_value\"/" -i $pd/kingdee_hosts
	fi
    Get_Autonomous_Value db_port db_user db_password
fi

if [ ${k8s_master} -gt 0 ];then
    if [ -z "$k8s_vip_value" ];then
        sed "s/k8s_vip\=/&\"k8s_vip\"/" -i $pd/kingdee_hosts
	else
		sed "s/k8s_vip\=/&\"$k8s_vip_value\"/" -i $pd/kingdee_hosts
	fi
fi

if [ ${k8s_master} -gt 0 ];then
    if [ -z "$keepalivedIf_value" ];then
        sed "s/keepalivedIf\=/&\"keepalivedIf\"/" -i $pd/kingdee_hosts
    elif [ ${keepalivedIf_value} == "1" ];then
        echo "K8S_VIP=$k8s_vip_value" >> $pd/kingdee_hosts
    fi
fi

if [ ${mdd} -gt 0 ];then
    if [ -z "$mdd_vip_value" ];then
        sed "s/mdd_vip\=/&\"mdd_vip\"/" -i $pd/kingdee_hosts
	else
		sed "s/mdd_vip\=/&\"$mdd_vip_value\"/" -i $pd/kingdee_hosts
	fi
fi

zk_hosts=${zookeeper_ip[@]}
sed "s/zk_hosts\=/&\"$zk_hosts\"/" -i $pd/kingdee_hosts

if [ ${zookeeper} -gt 0 ];then
    for ((zk=${#zookeeper_ip[@]}; zk>0; zk--))
    do
        zkconfig=",${zookeeper_ip[zk-1]}:2181"
        sed "s/zkconfig\=/&\\$zkconfig/" -i $pd/kingdee_hosts
    done
    sed "s/zkconfig=,/zkconfig=/g" -i $pd/kingdee_hosts
elif [ ${zookeeper} -eq 0 ];then
    Get_Provide_Value zkconfig
fi

if [ ${rabbitmq} -gt 0 ];then
    mq_host=${mq_ip[@]}
    sed "s/mq_host\=/&\"$mq_host\"/" -i $pd/kingdee_hosts
    sed "s/mq_port\=/&\"5672\"/" -i $pd/kingdee_hosts
    Get_Autonomous_Value mq_user mq_password mq_ierp_vhost mq_mc_vhost
elif [ ${rabbitmq} -eq 0 ];then
    Get_Provide_Value mq_host mq_port mq_user mq_password mq_ierp_vhost mq_mc_vhost
fi

if [ ${redis_cache} -gt 0 ] || [ ${redis_session} -gt 0 ] || [ ${redis_algo} -gt 0 ];then
    Get_Autonomous_Value redis_password
	redis_password=`cat $pd/kingdee_hosts |grep redis_password= |awk -F "=" '{print $2}'|sed 's/[ ]*$//g'|sed  's/"//g'|sed -e 's/&/\\\&/g' -e 's/\//\\\\\//g'`
fi

if [ ${redis_cache} -eq 1 ];then
    sed "s/redis_Cache_config\=/&\"redis:$cache_ip:6379\/$redis_password\"/" -i $pd/kingdee_hosts
elif [ ${redis_cache} -gt 1 ];then
    sed "s/redis_Cache_config\=/&\/$redis_password\"/" -i $pd/kingdee_hosts
    for ((rc=${#cache_ip[@]}; rc>0; rc--))
    do
        redis_Cache_config=",${cache_ip[rc-1]}:7505"
        sed "s/redis_Cache_config\=/&\\$redis_Cache_config/" -i $pd/kingdee_hosts
    done
    sed "s/redis_Cache_config=,/redis_Cache_config=\"sentinel:/g" -i $pd/kingdee_hosts
elif [ ${redis_cache} -eq 0 ];then
    Get_Provide_Value redis_Cache_config
fi

if [ ${redis_session} -eq 1 ];then
    sed "s/redis_Session_config\=/&\"redis:$session_ip:6380\/$redis_password\"/" -i $pd/kingdee_hosts
elif [ ${redis_session} -gt 1 ];then
    sed "s/redis_Session_config\=/&\/$redis_password\"/" -i $pd/kingdee_hosts
    for ((rc=${#session_ip[@]}; rc>0; rc--))
    do
        redis_Session_config=",${session_ip[rc-1]}:7506"
        sed "s/redis_Session_config\=/&\\$redis_Session_config/" -i $pd/kingdee_hosts
    done
    sed "s/redis_Session_config=,/redis_Session_config=\"sentinel:/g" -i $pd/kingdee_hosts
elif [ ${redis_session} -eq 0 ];then
    Get_Provide_Value redis_Session_config
fi

if [ ${redis_algo} -eq 1 ];then
    sed "s/redis_Algo_config\=/&\"redis:$algo_ip:6381\/$redis_password\"/" -i $pd/kingdee_hosts
elif [ ${redis_algo} -gt 1 ];then
    sed "s/redis_Algo_config\=/&\/$redis_password\"/" -i $pd/kingdee_hosts
    for ((rc=${#algo_ip[@]}; rc>0; rc--))
    do
        redis_Algo_config=",${algo_ip[rc-1]}:7507"
        sed "s/redis_Algo_config\=/&\\$redis_Algo_config/" -i $pd/kingdee_hosts
    done
    sed "s/redis_Algo_config=,/redis_Algo_config=\"sentinel:/g" -i $pd/kingdee_hosts
elif [ ${redis_algo} -eq 0 ];then
    redis_Algo_config=`cat $pd/kingdee_hosts |grep redis_Cache_config= |awk -F "=" '{print $2}'|sed 's/[ ]*$//g'|sed  's/"//g'|sed -e 's/&/\\\&/g' -e 's/\//\\\\\//g'`
    sed "s/redis_Algo_config\=/&\"$redis_Algo_config\"/" -i $pd/kingdee_hosts
fi

if [ ${mservice} -gt 0 ];then
    mservice_hosts=${ierp_hosts[@]}
    sed "s/mservice_hosts\=/&\"$mservice_hosts\"/" -i $pd/kingdee_hosts
elif [[ ${mservice} -eq 0 && ${#k8s_nodes[@]} -gt 0 ]];then
    mservice_hosts=${k8s_nodes[@]}
    sed "s/mservice_hosts\=/&\"$mservice_hosts\"/" -i $pd/kingdee_hosts
elif [[ ${mservice} -eq 0 && ${k8s_node} -eq 0 ]];then
    sed "s/mservice_hosts\=/&\"127.0.0.1\"/" -i $pd/kingdee_hosts
fi

if [ ${mc} -gt 0 ];then
    mc_hosts=${mc_hosts[@]}
    sed "s/mc_hosts\=/&\"$mc_hosts\"/" -i $pd/kingdee_hosts
elif [[ ${mc} -eq 0 && ${#k8s_nodes[@]} -gt 0 ]];then
    mc_hosts=${k8s_nodes[@]}
    sed "s/mc_hosts\=/&\"$mc_hosts\"/" -i $pd/kingdee_hosts
elif [[ ${mc} -eq 0 && ${k8s_node} -eq 0 ]];then
    sed "s/mc_hosts\=/&\"127.0.0.1\"/" -i $pd/kingdee_hosts
fi

if [ ${fileserver} -gt 0 ];then
    fileserver_hosts=${fileserver_hosts[@]}
    sed "s/fileserver_hosts\=/&\"$fileserver_hosts\"/" -i $pd/kingdee_hosts
elif [[ ${fileserver} -eq 0 && ${#k8s_nodes[@]} -gt 0 ]];then
    fileserver_hosts=${k8s_nodes[@]}
    sed "s/fileserver_hosts\=/&\"$fileserver_hosts\"/" -i $pd/kingdee_hosts
elif [[ ${fileserver} -eq 0 && ${k8s_node} -eq 0 ]];then
    sed "s/fileserver_hosts\=/&\"127.0.0.1\"/" -i $pd/kingdee_hosts
fi

if [ ${mdd} -gt 0 ];then
    sed "s/mddhost\=/&\"$mddhost\"/" -i $pd/kingdee_hosts
else
	sed "s/mddhost\=/&\"127.0.0.1\"/" -i $pd/kingdee_hosts
fi

if [ ${kafka} -gt 0 ];then
    sed "s/kafka_ip_port\=/&\"$kafka_ip:9092\"/" -i $pd/kingdee_hosts
else 
    Get_Provide_Value kafka_ip_port
fi

if [ ${elasticsearch} -gt 0 ];then
    sed "s/es_ip_port\=/&\"$es_ip:9200\"/" -i $pd/kingdee_hosts
    Get_Autonomous_Value es_user es_password start_essrv_user
elif [ ${elasticsearch} -eq 0 ];then
    Get_Provide_Value es_ip_port es_user es_password
fi

if [ ${k8s_master} -gt 0 ];then
    k8s_master_hosts=${k8smaster_hosts[@]}
    sed "s/k8s_master_hosts\=/&\"$k8s_master_hosts\"/" -i $pd/kingdee_hosts
else
    sed "s/k8s_master_hosts\=/&\"127.0.0.1\"/" -i $pd/kingdee_hosts
fi

sed -i "s#POD_CIDR=.*#$(grep -v ^# $pd/config | grep 'POD_CIDR=')#" $pd/kingdee_hosts
sed -i "s#SVC_CIDR=#$(grep -v ^# $pd/config | grep 'SVC_CIDR=')#" $pd/kingdee_hosts
sed -i "s#NETWORK_INTERFACE=#$(grep -v ^# $pd/config | grep 'NETWORK_INTERFACE=')#" $pd/kingdee_hosts
sed -i "s#DOCKER_DIR=.*#DOCKER_DIR=${1}/docker#g" $pd/kingdee_hosts

##判断组件是否容器部署
Service_isk8s mservice fileserver
