2022-08-23 08:00:25 -04:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2023-02-15 22:29:41 -05:00
|
|
|
|
imageName="zerotier-planet"
|
|
|
|
|
|
2022-08-23 08:00:25 -04:00
|
|
|
|
function deploy() {
|
|
|
|
|
|
|
|
|
|
# 处理ip信息
|
|
|
|
|
curr_ip=$(curl -s cip.cc | grep http | awk -F '/' '{print $4}')
|
|
|
|
|
|
|
|
|
|
echo "-------------------------------------------"
|
2023-02-23 01:06:01 -05:00
|
|
|
|
echo "支持使用域名或者ip,默认端口为9993,暂不支持修改"
|
|
|
|
|
echo "请输入 ip 或者 域名"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "您当前公网ip为:"$curr_ip",使用当前ip请输入:y"
|
2022-08-23 08:00:25 -04:00
|
|
|
|
echo "-------------------------------------------"
|
|
|
|
|
|
|
|
|
|
ip=""
|
|
|
|
|
read c
|
|
|
|
|
|
|
|
|
|
if [ "$c" = 'y' ]; then
|
|
|
|
|
ip=$curr_ip
|
|
|
|
|
else
|
|
|
|
|
ip=$c
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "----------------------------"
|
2023-02-23 01:06:01 -05:00
|
|
|
|
echo "部署的ip为:$ip, 是否继续? y/n"
|
2022-08-23 08:00:25 -04:00
|
|
|
|
read or
|
|
|
|
|
if [ "$or" = "y" ]; then
|
|
|
|
|
echo "{
|
2022-04-15 08:24:11 -04:00
|
|
|
|
\"stableEndpoints\": [
|
|
|
|
|
\"$ip/9993\"
|
|
|
|
|
]
|
|
|
|
|
}
|
2022-08-23 08:00:25 -04:00
|
|
|
|
" >./patch/patch.json
|
|
|
|
|
else
|
|
|
|
|
exit -1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# 开始安装程序
|
|
|
|
|
echo "清除原有内容"
|
2023-02-23 01:06:01 -05:00
|
|
|
|
rm /tmp/planet
|
2022-08-23 08:00:25 -04:00
|
|
|
|
docker stop $imageName
|
|
|
|
|
docker rm $imageName
|
|
|
|
|
docker rmi $imageName
|
|
|
|
|
|
|
|
|
|
echo "打包镜像"
|
|
|
|
|
docker build --network host -t $imageName .
|
|
|
|
|
|
|
|
|
|
echo "启动服务"
|
|
|
|
|
for i in $(lsof -i:9993 -t); do kill -2 $i; done
|
2022-10-29 01:25:30 -04:00
|
|
|
|
docker run -d -p 9993:9993 -p 9993:9993/udp -p 3443:3443 --name $imageName --restart unless-stopped $imageName
|
2023-02-15 01:01:32 -05:00
|
|
|
|
docker cp zerotier-planet:/app/bin/planet /tmp/planet
|
2022-08-23 08:00:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-15 22:29:41 -05:00
|
|
|
|
function upgrade(){
|
|
|
|
|
echo "准备更新zerotier服务"
|
2023-02-23 01:17:44 -05:00
|
|
|
|
docker exec $imageName sh -c "apt update && apt upgrade zerotier-one -y || apk upgrade zerotier-one"
|
2023-02-15 22:29:41 -05:00
|
|
|
|
docker restart $imageName
|
|
|
|
|
echo "done!"
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-23 08:00:25 -04:00
|
|
|
|
function menu() {
|
|
|
|
|
echo
|
|
|
|
|
echo "=============功能菜单============="
|
|
|
|
|
echo "| 1 - 安装"
|
2023-02-15 22:29:41 -05:00
|
|
|
|
echo "| 2 - 更新"
|
2022-08-30 08:22:35 -04:00
|
|
|
|
#echo "| 3 - 卸载"
|
2022-08-23 08:00:25 -04:00
|
|
|
|
echo "| q - 退出"
|
|
|
|
|
echo "---------------------------------"
|
|
|
|
|
printf "请选择菜单:"
|
|
|
|
|
read -n 1 n
|
|
|
|
|
echo
|
|
|
|
|
if [[ "$n" = "1" ]]; then
|
|
|
|
|
echo "安装"
|
|
|
|
|
deploy
|
|
|
|
|
|
2023-02-15 22:29:41 -05:00
|
|
|
|
elif [ "$n" = "2" ]; then
|
|
|
|
|
upgrade
|
2022-08-30 08:22:35 -04:00
|
|
|
|
#elif [ "$n" = "3" ]; then
|
|
|
|
|
# echo $n
|
2022-08-23 08:00:25 -04:00
|
|
|
|
elif [ "$n" = "q" ]; then
|
|
|
|
|
echo 退出
|
|
|
|
|
return
|
|
|
|
|
else
|
|
|
|
|
echo "错误选项"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
menu
|