#!/usr/bin/bash
# in private/centos
# down load install package to /data/EPM2/TOOL/monitor
# ./nodeExporterDeploy.sh
set -x
installPath=root
while [ $# -gt 0 ]; do
  COMMAND=$1
  case $COMMAND in
    -installPath)
      installPath=$2
      shift 2
      ;;
    *)
      break
      ;;
  esac
done

monitorPath=$installPath/MONITOR
mkdir -p $monitorPath

client='node-exporter.tar'
if test -e $client
then
    echo "client exist: $client"
else
    echo "client does not exist, get it: $client"
    wget http://tool.epm2demo.cn/monitor/$client
fi
tar zxf $client -C $monitorPath

client='node-exporter.service'
if test -e $client
then
    echo "client exist: $client"
    cp $client /etc/systemd/system/node-exporter.service
else
    echo "client does not exist, get it: $client"
    wget http://tool.epm2demo.cn/monitor/$client -O /etc/systemd/system/node-exporter.service
fi

systemctl daemon-reload
systemctl restart node-exporter
echo 'node-exporter started'