From 1177c234e4cdbdb5e226958fdca42228a5000198 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 14 Apr 2022 14:15:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20=E4=BD=BF=E7=94=A8ubuntu?= =?UTF-8?q?=E9=95=9C=E5=83=8F=EF=BC=8C=E4=BF=AE=E5=A4=8Dping=E4=B8=8D?= =?UTF-8?q?=E9=80=9A=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 10 ++++------ deploy.sh | 9 +-------- gen_world.sh | 14 -------------- init.sh | 47 +++++++++++++++++++++++++++++++++++++---------- patch/patch.py | 4 ++-- 5 files changed, 44 insertions(+), 40 deletions(-) delete mode 100644 gen_world.sh mode change 100644 => 100755 init.sh diff --git a/Dockerfile b/Dockerfile index a76d3fb..4fce79a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,8 @@ -FROM alpine:latest +FROM ubuntu:latest +ENV TZ=Asia/Shanghai \ + DEBIAN_FRONTEND=noninteractive -ADD ./init.sh /app/ -ADD ./gen_world.sh /app/ -ADD ./patch /opt/patch/ - -VOLUME ["/var/lib/zerotier-one/"] +Add . /app RUN cd /app && sh init.sh diff --git a/deploy.sh b/deploy.sh index a11b9a8..0026c93 100755 --- a/deploy.sh +++ b/deploy.sh @@ -15,11 +15,4 @@ docker build --network host -t $imageName . echo "启动服务" for i in $(lsof -i:9993 -t);do kill -2 $i;done docker run -d --network host --name $imageName -p 3443:3443 -p 9993:9993 -p 9993:9993/udp --restart unless-stopped $imageName - -sleep 10s -echo "生成世界" -docker exec -it $imageName sh /app/gen_world.sh -docker cp $imageName:/opt/ZeroTierOne/attic/world/world.bin /opt/planet - -echo "------------------" -echo "现在已经配置好了,planet文件在/opt/planet, 客户端连接时需要替换该planet" +docker cp zerotier-planet:/app/bin/planet /opt/planet diff --git a/gen_world.sh b/gen_world.sh deleted file mode 100644 index 2b86f08..0000000 --- a/gen_world.sh +++ /dev/null @@ -1,14 +0,0 @@ -cd /var/lib/zerotier-one && zerotier-idtool initmoon identity.public > moon.json - -# 添加补丁 -cd /opt/patch && python3 patch.py -cd /var/lib/zerotier-one && zerotier-idtool genmoon moon.json && mkdir moons.d && cp ./*.moon ./moons.d - -# 生成世界 -cd /opt/ZeroTierOne/attic/world/ -sh build.sh -sleep 5s -./mkworld - -ps -ef |grep 'zerotier-one -d' |grep -v grep |awk '{print $1}' |xargs kill -9 -zerotier-one -d \ No newline at end of file diff --git a/init.sh b/init.sh old mode 100644 new mode 100755 index 77f96ed..fe4080e --- a/init.sh +++ b/init.sh @@ -1,16 +1,43 @@ -sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories -apk update -apk add git python3 nodejs npm make g++ linux-headers zerotier-one +echo "update source" +echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal universe +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates universe +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal multiverse +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates multiverse +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security universe +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security multiverse"> /etc/apt/sources.list +apt update +apt upgrade -y +apt install -y tzdata +ln -fs /usr/share/zoneinfo/${TZ} /etc/localtime +echo ${TZ} > /etc/timezone +dpkg-reconfigure --frontend noninteractive tzdata +rm -rf /var/lib/apt/lists/* + +apt update +apt install git python3 npm make curl -y npm config set registry http://registry.npm.taobao.org && npm install -g node-gyp +curl -s https://install.zerotier.com | bash +cd /opt && git clone -v http://gh-proxy.markxu.vip/https://github.com/key-networks/ztncui.git +cd /opt && git clone -v http://gh-proxy.markxu.vip/https://github.com/zerotier/ZeroTierOne.git -echo "下载源码中,源码文件较大,请耐心等待;如果源码下载失败,请重新执行该脚本" -# 下载源码 -cd /opt && git clone http://gh-proxy.markxu.vip/https://github.com/key-networks/ztncui.git -cd /opt && git clone http://gh-proxy.markxu.vip/https://github.com/zerotier/ZeroTierOne.git - -# 配置ztncui -cd /opt/ztncui/src && npm install argon2 && npm install +cd /opt/ztncui/src +npm install cp -pv ./etc/default.passwd ./etc/passwd echo 'HTTP_PORT=3443' >.env echo 'NODE_ENV=production' >>.env echo 'HTTP_ALL_INTERFACES=true' >>.env + +cd /var/lib/zerotier-one && zerotier-idtool initmoon identity.public > moon.json +cd /app/patch && python3 patch.py +cd /var/lib/zerotier-one && zerotier-idtool genmoon moon.json && mkdir moons.d && cp ./*.moon ./moons.d +cd /opt/ZeroTierOne/attic/world/ && sh build.sh +sleep 5s + +cd /opt/ZeroTierOne/attic/world/ && ./mkworld +mkdir /app/bin -p && cp world.bin /app/bin/planet + +service zerotier-one restart diff --git a/patch/patch.py b/patch/patch.py index 8eeafdb..200a784 100644 --- a/patch/patch.py +++ b/patch/patch.py @@ -10,7 +10,7 @@ def get_moon(): def get_patch(): - with open("/opt/patch/patch.json", "r") as f: + with open("/app/patch/patch.json", "r") as f: return json.load(f) @@ -39,7 +39,7 @@ def patch(): text += f'\n roots.back().stableEndpoints.push_back(InetAddress("{i}"));' # 生成文件 - with open("/opt/patch/mkworld.cpp", "r") as cpp: + with open("/app/patch/mkworld.cpp", "r") as cpp: world = "".join(cpp.readlines()) world = world.replace("//__PATCH_REPLACE__", text)