#!/bin/bash


# 下载自动运行脚本(需要提前准备好配置)
# 加入到自动运行脚本中
set search_cnt=0
if [ -f "/var/spool/cron/root" ]; then search_cnt=`crontab -l |grep -v 'grep' |grep -v 'no crontab' |grep -c kplcors-ntripauth-runner.sh`; fi

echo "crontab-kplcors-ntripauth-runner:$search_cnt"

mkdir -p /home/kpl-cors/ntripauth && cd /home/kpl-cors/ntripauth && wget http://119.96.169.117:3000/kpl-release/release/kplcors-ntripauth-runner.sh -O kplcors-ntripauth-runner.sh
chmod +x kplcors-ntripauth-runner.sh
if [[ $search_cnt -eq 0 ]]; then
  crontab -l > crontab.tmp && echo "*/1 * * * * /home/kpl-cors/ntripauth/kplcors-ntripauth-runner.sh" >> crontab.tmp && crontab crontab.tmp && rm -f crontab.tmp
  echo "*/1 * * * * /home/kpl-cors/ntripauth/kplcors-ntripauth-runner.sh"
fi

sleep 5s

mkdir -p /home/kpl-cors/ntripauth && cd /home/kpl-cors/ntripauth &&

runflag=1
if [ ! -f "plugs-conf.json" ]; then
  wget http://119.96.169.117:3000/kpl-release/plug-conf/plugs-conf-ntripauth.json -O plugs-conf.json
  runflag=0
  echo "请修改配置文件,然后运行"
fi

# 更新服务器
cd /home/kpl-cors/ntripauth && 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 kplcors-ntripauth :50154 plugs-conf.json 1 $runflag
