#!/usr/bin/bash
echo 'auto install frpc'

if [ -e frp_0.35.0_linux_amd64 ]; then
	echo 'file exist, skip download'
else
	echo 'file does not exist, download it'
	curl -fL http://tool.epm2demo.cn/others/frp_0.35.0_linux_amd64.tar.gz --output frpc.tar.gz
	tar zxf frpc.tar.gz
fi

CUR=`pwd`
echo "Install to $CUR"

cd frp_0.35.0_linux_amd64
sed -i "s/server_addr.*/server_addr = www.epmsquare.cn/g" frpc.ini
sed -i "s/server_port.*/server_port = 3023/g" frpc.ini

sed -i "s@ExecStart=.*@ExecStart=$CUR\/frp_0.35.0_linux_amd64\/frpc -c $CUR\/frp_0.35.0_linux_amd64\/frpc.ini@g" systemd/frpc.service
sed -i "s@ExecReload=.*@ExecReload=$CUR/frp_0.35.0_linux_amd64/frpc reload -c $CUR/frp_0.35.0_linux_amd64/frpc.ini@g" systemd/frpc.service

cp systemd/frpc.service /etc/systemd/system/frpc.service
systemctl daemon-reload
systemctl enable frpc
systemctl start frpc