Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,5 @@ A:我也不知道
A: 该项目剔除了官方服务器,只保留了自定义的Planet节点

## 4. Q:我更换了IP需要怎么处理?
A: 如果IP更换了,则需要重新部署,相当于全新部署
A: 在原版的基础上添加了迁移功能

48 changes: 42 additions & 6 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

imageName="zerotier-planet"

function deploy() {
imageName="zerotier-planet"

# 处理ip信息
curr_ip=$(curl -s cip.cc | grep http | awk -F '/' '{print $4}')
Expand Down Expand Up @@ -48,16 +49,49 @@ function deploy() {

echo "启动服务"
for i in $(lsof -i:9993 -t); do kill -2 $i; done
docker run -d --network host --name $imageName --restart unless-stopped $imageName
docker run -d --network host --name $imageName --restart unless-stopped --volume ztncui:/opt/key-networks/ztncui/etc/ --volume zt1:/var/lib/zerotier-one/ $imageName
docker cp zerotier-planet:/app/bin/planet /opt/planet
}

function migrate() {

echo "-------------------------------------------"
echo PS: 请事先确保对端主机满足以下条件:
echo a. ssh用户可以免密sudo
echo b. selinux关闭
echo c. 对端已经安装了docker/podman-docker
echo 另外,替换了planet的主机需要自行手动下载新的planet文件进行替换
echo "-------------------------------------------"
echo "请输入对端ip:"

read remote_ip

echo "----------------------------"
echo "对端ip为:$remote_ip, 请输入对端端口:"

read remote_port

echo "----------------------------"
echo "对端ip为:$remote_ip, 对端端口为:$remote_port, 请输入对端用户:"

read remote_user

docker stop $imageName
docker run --rm --volume ./ztncui:/from alpine ash -c "cd /from ; tar -cf - . " | ssh $remote_user@$remote_ip -p $remote_port 'sudo docker run --rm -i --volume ztncui:/to alpine ash -c "cd /to ; tar -xpvf - " '
docker run --rm --volume ./zt1:/from alpine ash -c "cd /from ; tar -cf - . " | ssh $remote_user@$remote_ip -p $remote_port 'sudo docker run --rm -i --volume zt1:/to alpine ash -c "cd /to ; tar -xpvf - " '

echo "----------------------------"
echo 迁移完成,请在对端主机执行部署命令:
echo "git clone https://github.com/m4d3bug/docker-zerotier-planet && ./docker-zerotier-planet/deploy.sh"
echo "----------------------------"
}

function menu() {
echo
echo "=============功能菜单============="
echo "| 1 - 安装"
#echo "| 2 - 更新"
#echo "| 3 - 卸载"
echo "| 2 - 迁移"
#echo "| 3 - 更新"
echo "| q - 退出"
echo "---------------------------------"
printf "请选择菜单:"
Expand All @@ -67,8 +101,10 @@ function menu() {
echo "安装"
deploy

#elif [ "$n" = "2" ]; then
# echo $n
elif [ "$n" = "2" ]; then
echo "迁移"
migrate

#elif [ "$n" = "3" ]; then
# echo $n
elif [ "$n" = "q" ]; then
Expand Down