mirror of
https://github.com/xubiaolin/docker-zerotier-planet.git
synced 2025-01-22 12:48:14 -05:00
feat: 🎸 支持更换端口 (#55)
Co-authored-by: xubiaolin <xubiaolin2014@xiaochuankeji.cn>
This commit is contained in:
parent
5aa7aaa260
commit
460fa6dc1c
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
.idea
|
||||
patch/patch.json
|
||||
|
@ -1,5 +1,7 @@
|
||||
FROM alpine:latest
|
||||
|
||||
ARG ZT_PORT
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
WORKDIR /app
|
||||
@ -17,6 +19,8 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/re
|
||||
&& echo 'HTTP_PORT=3443' >.env \
|
||||
&& echo 'NODE_ENV=production' >>.env \
|
||||
&& echo 'HTTP_ALL_INTERFACES=true' >>.env \
|
||||
&& echo "ZT_ADDR=localhost:${ZT_PORT}" >>.env\
|
||||
&& echo "${ZT_PORT}" >/app/zerotier-one.port \
|
||||
&& cp -v etc/default.passwd etc/passwd
|
||||
|
||||
RUN cd /app && git clone -v https://ghproxy.com/https://github.com/zerotier/ZeroTierOne.git --depth 1\
|
||||
@ -32,4 +36,4 @@ RUN cd /app && git clone -v https://ghproxy.com/https://github.com/zerotier/Zero
|
||||
&& echo "ZT_TOKEN=$TOKEN">> /app/ztncui/src/.env
|
||||
|
||||
|
||||
CMD /bin/sh -c "zerotier-one -d; cd /app/ztncui/src;npm start"
|
||||
CMD /bin/sh -c "cd /var/lib/zerotier-one && ./zerotier-one -p`cat /app/zerotier-one.port` -d; cd /app/ztncui/src;npm start"
|
||||
|
28
README.md
28
README.md
@ -70,11 +70,11 @@ cd docker-zerotier-planet
|
||||
|
||||
根据提示来选择即可,操作完成后会自动部署
|
||||
```
|
||||
-------------------------------------------
|
||||
您当前公网ip为:8.8.8.8, 使用当前ip请输入:y
|
||||
-------------------------------------------
|
||||
使用其他ip请输入要使用的ip,例如1.1.1.1
|
||||
-------------------------------------------
|
||||
欢迎使用zerotier-planet脚本,请选择需要执行的操作:
|
||||
1. 安装
|
||||
2. 更新
|
||||
其他任意键退出
|
||||
|
||||
```
|
||||
|
||||
整个脚本预计需要 3-10 分钟,具体需要看网络与机型
|
||||
@ -82,15 +82,17 @@ cd docker-zerotier-planet
|
||||
|
||||
当您看到类似如下字样时,表示安装成功
|
||||
```
|
||||
Step 6/6 : CMD /bin/sh -c "zerotier-one -d; cd /tmp/ztncui/src;npm start"
|
||||
---> Running in 13b4acf043ce
|
||||
Removing intermediate container 13b4acf043ce
|
||||
---> f66b3f73437e
|
||||
Successfully built f66b3f73437e
|
||||
Successfully tagged zerotier-planet:latest
|
||||
启动服务
|
||||
WARNING: Published ports are discarded when using host network mode
|
||||
7782066b89fb217bf53ae57b139c73c3d6df79fecf887d1571aa8eed2433ba75
|
||||
3b59df95edabeabbf19aa6605b28704608710719bdf7c6e7612d75d01ede8f48
|
||||
Preparing to copy...
|
||||
Copying from container - 512B
|
||||
Copying from container - 769B
|
||||
Copying from container - 1.024kB
|
||||
Copying from container - 1.536kB
|
||||
Successfully copied 2.048kB to /tmp/planet
|
||||
planet文件路径为 /tmp/planet
|
||||
planet server端口为: 9994, 请在防火墙放行该端口的tcp和udp协议
|
||||
enjoy~
|
||||
```
|
||||
|
||||
|
||||
|
126
deploy.sh
126
deploy.sh
@ -2,88 +2,102 @@
|
||||
|
||||
imageName="zerotier-planet"
|
||||
|
||||
function deploy() {
|
||||
function install() {
|
||||
read -p "请输入要使用的端口号(数字): " port
|
||||
|
||||
# 处理ip信息
|
||||
curr_ip=$(curl -s cip.cc | grep http | awk -F '/' '{print $4}')
|
||||
# 确保端口号是数字
|
||||
while ! [[ "$port" =~ ^[0-9]+$ ]]; do
|
||||
read -p "端口号必须是数字,请重新输入端口号: " port
|
||||
done
|
||||
|
||||
echo "-------------------------------------------"
|
||||
echo "支持使用域名或者ip,默认端口为9993,暂不支持修改"
|
||||
echo "请输入 ip 或者 域名"
|
||||
echo ""
|
||||
echo "您当前公网ip为:"$curr_ip",使用当前ip请输入:y"
|
||||
echo "-------------------------------------------"
|
||||
read -p "是否自动获取公网IP地址?(y/n)" use_auto_ip
|
||||
|
||||
ip=""
|
||||
read c
|
||||
if [[ "$use_auto_ip" =~ ^[Yy]$ ]]; then
|
||||
ipv4=$(curl -s https://ipv4.icanhazip.com/)
|
||||
ipv6=$(curl -s https://ipv6.icanhazip.com/)
|
||||
|
||||
if [ "$c" = 'y' ]; then
|
||||
ip=$curr_ip
|
||||
echo "获取到的IPv4地址为: $ipv4"
|
||||
echo "获取到的IPv6地址为: $ipv6"
|
||||
|
||||
read -p "是否使用上面获取到的IP地址?(y/n)" use_auto_ip_result
|
||||
|
||||
if [[ "$use_auto_ip_result" =~ ^[Nn]$ ]]; then
|
||||
read -p "请输入IPv4地址: " ipv4
|
||||
read -p "请输入IPv6地址(可留空): " ipv6
|
||||
fi
|
||||
else
|
||||
ip=$c
|
||||
|
||||
# 要求用户手动输入IP地址
|
||||
read -p "请输入IPv4地址: " ipv4
|
||||
read -p "请输入IPv6地址(可留空): " ipv6
|
||||
fi
|
||||
|
||||
echo "----------------------------"
|
||||
echo "部署的ip为:$ip, 是否继续? y/n"
|
||||
read or
|
||||
if [ "$or" = "y" ]; then
|
||||
echo "{
|
||||
\"stableEndpoints\": [
|
||||
\"$ip/9993\"
|
||||
]
|
||||
}
|
||||
" >./patch/patch.json
|
||||
# 输出使用的端口号和IP地址
|
||||
ipv4_entry="${ipv4}/${port}"
|
||||
if [[ -n "$ipv6" ]]; then
|
||||
ipv6_entry="${ipv6}/${port}"
|
||||
endpoints="[\"$ipv4_entry\",\"$ipv6_entry\"]"
|
||||
else
|
||||
exit -1
|
||||
endpoints="[\"$ipv4_entry\"]"
|
||||
fi
|
||||
echo "{\"stableEndpoints\":$endpoints}" > ./patch/patch.json
|
||||
|
||||
# 开始安装程序
|
||||
echo "配置内容为:"
|
||||
echo "`cat ./patch/patch.json`"
|
||||
|
||||
echo "开始安装..."
|
||||
echo "清除原有内容"
|
||||
rm /tmp/planet
|
||||
rm -rf /tmp/planet
|
||||
docker stop $imageName
|
||||
docker rm $imageName
|
||||
docker rmi $imageName
|
||||
|
||||
echo "打包镜像"
|
||||
docker build --network host -t $imageName .
|
||||
echo "使用的端口为:${port}"
|
||||
docker build --no-cache --build-arg ZT_PORT=$port --network host -t $imageName .
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "镜像打包失败,请重试"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "启动服务"
|
||||
for i in $(lsof -i:9993 -t); do kill -2 $i; done
|
||||
docker run -d -p 9993:9993 -p 9993:9993/udp -p 3443:3443 --name $imageName --restart unless-stopped $imageName
|
||||
for i in $(lsof -i:$port -t); do kill -2 $i; done
|
||||
docker run -d -p $port:$port -p $port:$port/udp -p 3443:3443 --name $imageName --restart unless-stopped $imageName
|
||||
docker cp zerotier-planet:/app/bin/planet /tmp/planet
|
||||
|
||||
echo "planet文件路径为 /tmp/planet"
|
||||
echo "planet server端口为: $port, 请在防火墙放行该端口的tcp和udp协议"
|
||||
echo "enjoy~"
|
||||
}
|
||||
|
||||
function upgrade(){
|
||||
function upgrade() {
|
||||
echo "准备更新zerotier服务"
|
||||
docker exec $imageName sh -c "apt update && apt upgrade zerotier-one -y || apk upgrade zerotier-one"
|
||||
docker restart $imageName
|
||||
echo "done!"
|
||||
}
|
||||
|
||||
function menu() {
|
||||
echo
|
||||
echo "=============功能菜单============="
|
||||
echo "| 1 - 安装"
|
||||
echo "| 2 - 更新"
|
||||
#echo "| 3 - 卸载"
|
||||
echo "| q - 退出"
|
||||
echo "---------------------------------"
|
||||
printf "请选择菜单:"
|
||||
read -n 1 n
|
||||
echo
|
||||
if [[ "$n" = "1" ]]; then
|
||||
echo "安装"
|
||||
deploy
|
||||
# 显示菜单
|
||||
echo "欢迎使用zerotier-planet脚本,请选择需要执行的操作:"
|
||||
echo "1. 安装"
|
||||
echo "2. 更新"
|
||||
echo "其他任意键退出"
|
||||
|
||||
elif [ "$n" = "2" ]; then
|
||||
# 读取用户输入
|
||||
read choice
|
||||
|
||||
# 根据用户输入执行相应操作
|
||||
case "$choice" in
|
||||
1)
|
||||
echo "您选择了安装功能"
|
||||
install
|
||||
;;
|
||||
2)
|
||||
echo "您选择了更新功能"
|
||||
upgrade
|
||||
#elif [ "$n" = "3" ]; then
|
||||
# echo $n
|
||||
elif [ "$n" = "q" ]; then
|
||||
echo 退出
|
||||
return
|
||||
else
|
||||
echo "错误选项"
|
||||
fi
|
||||
}
|
||||
menu
|
||||
;;
|
||||
*)
|
||||
echo "谢谢使用!"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
Loading…
Reference in New Issue
Block a user