#!/bin/bash

#check installed ?
rpm -qa | grep 'umonitor3-agent-2.3.5-1.x86_64'
if [ $? -eq 0 ];then
rm install_umonitor3_agent.sh
exit 0
fi


#umonitor3-agent stop
/etc/init.d/agent-update stop
/opt/umonitor3/umonitor3-control stop agent

#download rpm
wget -N -t 3 -T 30 http://softlib.service.ucloud.cn/downloads/umonitor/agent_package/umonitor3-agent-2.3.5-1.x86_64.rpm

#check install
rpm -qa | grep 'umonitor3-agent-'
if [ $? -eq 0 ];then
  rpm -e `rpm -qa | grep umonitor3-agent-`
fi
# install umonitor3-agent
rpm -ivh --force umonitor3-agent-2.3.5-1.x86_64.rpm

#modify config zk
sed -i 's/@ZKSERVER/10.65.5.18:2181,10.65.5.19:2181,10.65.4.115:2181,10.65.4.114:2181,10.65.4.113:2181/g' /opt/umonitor3/agent/etc/cfg.json
sed -i 's/@ZKSERVER/10.65.5.18:2181,10.65.5.19:2181,10.65.4.115:2181,10.65.4.114:2181,10.65.4.113:2181/g' /opt/umonitor3/agent-update/etc/cfg.json

#start agent-update
/etc/init.d/agent-update start

#delete rpm
rm umonitor3-agent-2.3.5-1.x86_64.rpm
# check agent
ps -ef | grep umonitor3 | grep agent
/opt/umonitor3/agent/bin/agent  -v
/opt/umonitor3/agent-update/bin/agent-update  -v
/opt/umonitor3/umonitor3-control -v
#delete script
rm install_umonitor3_agent.sh
