#!/bin/bash


# 本脚本适合centos自动运行插件服务
# mkdir -p /home/kpl-serv && cd /home/kpl-serv && wget http://119.96.169.117:3000/kpl-release/plug-conf/plugs-vrs-serv.json -O plugs-conf.json
# 运行下载
# mkdir -p /home/kpl-serv && wget http://119.96.169.117:3000/kpl-release/release/kpl-install-kplserv.sh -O kpl-install-kplserv.sh &&sleep 1s&&chmod +x kpl-install-kplserv.sh && ./kpl-install-kplserv.sh &

# 下载自动运行脚本(需要提前准备好配置)
mkdir -p /home/kpl-serv && cd /home/kpl-serv && wget http://119.96.169.117:3000/kpl-release/release/kpl-runner-serv.sh -O kpl-runner-serv.sh
chmod +x kpl-runner-serv.sh


# 加入到自动运行脚本中
set search_cnt=0
if [ -f "/var/spool/cron/root" ]; then search_cnt=`crontab -l |grep -v 'grep' |grep -v 'no crontab' |grep -c kpl-runner-serv.sh`; fi

echo "crontab-kpl-runner-serv:$search_cnt"

if [[ $search_cnt -eq 0 ]]; then
  echo "*/1 * * * * /home/kpl-serv/kpl-runner-serv.sh" >>/var/spool/cron/root
  echo "*/1 * * * * /home/kpl-serv/kpl-runner-serv.sh"
fi

sleep 5s

# 更新服务器
cd /home/kpl-serv && rm -rf up-kpl-gnss-centos.sh&&wget http://119.96.169.117:3000/kpl-release/release/up-kpl-gnss-centos.sh&&sleep 5s&&chmod +x up-kpl-gnss-centos.sh&&./up-kpl-gnss-centos.sh kpl-serv-app :3000 plugs-conf.json
