#!/bin/sh
# @function install Qconf-Agent of gcc 6.3.0
function InstallQConfAgent63()
{
    ShowResult "[green]正在安装QConf配置管理Agent... [/green]" 1

    local info_=${_HOSTS_[SCM]:-${_HOSTS_[DBCTRL]}}
    
    if [ -z "${info_}" ]; then
        return
    fi
    local hostip_=`GetInfo "${info_}" ip` hostfull_= sn_=qconf-agent prefix_=/usr/local/qconf
    hostfull_=${hostip_}:2181
    
    # install libevent
    cd ${_PATH_COMPILATION_}
    eval rm -rf ./qconf-* ${_SYS_SHOW_INSTALL_DETAILS_}
    eval unzip ${_PATH_SOFTWARE_}/QConf-master.zip ${_SYS_SHOW_INSTALL_DETAILS_}
    eval cd QConf-master ${_SYS_SHOW_INSTALL_DETAILS_}
    eval cmake . ${_SYS_SHOW_INSTALL_DETAILS_}
    eval make ${_SYS_MAKE_EXT_} ${_SYS_SHOW_INSTALL_DETAILS_}
    eval make install ${_SYS_SHOW_INSTALL_DETAILS_}
    ShowStatus $? 1
    
    eval chmod +x ${prefix_}/bin/* ${_SYS_SHOW_INSTALL_DETAILS_}
    sed -ri "/^zookeeper.test/c \zookeeper\.test=${hostfull_}" ${prefix_}/conf/idc.conf
    ShowStatus $? 1
    
    if [ ! -f /etc/init.d/${sn_} ]; then
        eval \cp -f ${prefix_}/bin/agent-cmd.sh /etc/init.d/${sn_} ${_SYS_SHOW_INSTALL_DETAILS_}
        sed -ri '1i# chkconfig: 345 60 60\n# description: Activates/Deactivates QConf-Agent' /etc/init.d/${sn_}
        sed -ri '/^agentdir=/c \agentdir=\/usr\/local\/qconf' /etc/init.d/${sn_}
        eval chkconfig --add ${sn_} ${_SYS_SHOW_INSTALL_DETAILS_}
        ShowStatus $?
        eval service ${sn_} start ${_SYS_SHOW_INSTALL_DETAILS_}
    else
        ShowStatus 0
    fi
}