#!/bin/sh
paramServerUrl=$1
tarFileName=$2
paramWgToken=$3
paramBindIp=$4

echo "serverUrl------${paramServerUrl}"
echo "tarFileName------${tarFileName}"
echo "wgToken------${paramWgToken}"
echo "bindIp------${paramBindIp}"

versionStr=${tarFileName:0-12:5}
dirName=${tarFileName//.tar.gz/}

echo "开始下载${tarFileName}------"
curl -k -o ${tarFileName} "https://www.wgstart.com/download/${versionStr}/${tarFileName}"
echo "下载完成------"
tar -xvf ${tarFileName}
cd ./${dirName}/


echo "修改config/application.properties的配置项serverUrl------"
sed -i "s#^serverUrl=.*#serverUrl=${paramServerUrl}#g"  ./config/application.properties
if [ -n "$paramWgToken" ]; then
 sed -i "s#^wgToken=.*#wgToken=${paramWgToken}#g"  ./config/application.properties
fi
if [ -n "$paramBindIp" ]; then
 sed -i "s#^bindIp=.*#bindIp=${paramBindIp}#g"  ./config/application.properties
fi
echo "修改完成------"

chmod +x start.sh

echo "部署下载已完成，开始启动agent------"

sh start.sh
