diff --git a/Dockerfile b/Dockerfile index 42a8676..8c4a3d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/re && apk update\ && mkdir -p /usr/include/nlohmann/ && cd /usr/include/nlohmann/ && wget https://ghself.markxu.online/https://github.com/nlohmann/json/releases/download/v3.10.5/json.hpp \ && apk add --no-cache git python3 npm make g++ zerotier-one linux-headers\ - && mkdir /app -p && cd /app && git clone --progress https://ghself.markxu.online/https://github.com/key-networks/ztncui.git\ + && mkdir /app /var/lib -p && cd /app && git clone --progress https://ghself.markxu.online/https://github.com/key-networks/ztncui.git\ && cd /app/ztncui/src \ && cp /app/patch/binding.gyp .\ && echo "开始配置npm环境"\ @@ -22,13 +22,17 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/re && 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 + && cp -v etc/default.passwd etc/passwd +#ADD ./pztier/zerotier-one* /var/lib/ +RUN cp -r /app/pztier/zerotier-one /var/lib/ || true + +#RUN ls -al /var/lib/ /var/lib/zerotier-one/ |grep -v zerotier && sleep 20 RUN cd /app && git clone --progress https://ghself.markxu.online/https://github.com/zerotier/ZeroTierOne.git --depth 1\ && zerotier-one -d && sleep 5s && ps -ef |grep zerotier-one |grep -v grep |awk '{print $1}' |xargs kill -9 \ - && cd /var/lib/zerotier-one && zerotier-idtool initmoon identity.public >moon.json\ + && cd /var/lib/zerotier-one && ( [ -f ./moon.json ] || 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 /var/lib/zerotier-one && zerotier-idtool genmoon moon.json && mkdir -p moons.d && cp ./*.moon ./moons.d \ && cd /app/ZeroTierOne/attic/world/ && sh build.sh \ && sleep 5s \ && cd /app/ZeroTierOne/attic/world/ && ./mkworld \ diff --git a/deploy.sh b/deploy.sh index d7f5b58..c4e1739 100755 --- a/deploy.sh +++ b/deploy.sh @@ -37,10 +37,11 @@ function install() { if [[ -n "$ipv6" ]]; then ipv6_entry="${ipv6}/${port}" endpoints="[\"$ipv4_entry\",\"$ipv6_entry\"]" - else + echo "[{\"stableEndpoints\":$endpoints}]" > ./patch/patch.json + elif [[ -n "$ipv4" ]]; then endpoints="[\"$ipv4_entry\"]" + echo "[{\"stableEndpoints\":$endpoints}]" > ./patch/patch.json fi - echo "{\"stableEndpoints\":$endpoints}" > ./patch/patch.json echo "配置内容为:" echo "`cat ./patch/patch.json`" @@ -92,9 +93,12 @@ case "$choice" in 1) echo "您选择了安装功能" install + docker cp zerotier-planet:/var/lib/zerotier-one/ ./pztier/ ;; 2) echo "您选择了更新功能" + [ -f ./pztier/zerotier-one/moon.json ] && docker cp ./pztier/zerotier-one/moon.json zerotier-planet:/var/lib/zerotier-one/moon.json + [ -f ./pztier/zerotier-one/planet ] && docker cp ./pztier/zerotier-one/planet zerotier-planet:/var/lib/zerotier-one/planet upgrade ;; 3) @@ -102,7 +106,7 @@ case "$choice" in docker cp zerotier-planet:/app/bin/planet . ;; *) - echo "谢谢使用!" + echo "多planet:各planet执行完1之后,将各planet的stableendpoint合并到moon.json中,编辑好patch.json,planet0上重新执行1,将moon.json planet放到其他各planet中,重新执行2.谢谢使用!" exit 0 ;; esac diff --git a/patch/patch.json b/patch/patch.json index 6cef3cd..0880243 100644 --- a/patch/patch.json +++ b/patch/patch.json @@ -1 +1 @@ -{"stableEndpoints":["175.29.122.43/9994"]} +[{"stableEndpoints":["175.29.122.43/9994"]},{"stableEndpoints":["t0.x.top/9994"]},{"stableEndpoints":["t1.x.top/9994"]}] diff --git a/patch/patch.py b/patch/patch.py index aa29827..a5baf70 100644 --- a/patch/patch.py +++ b/patch/patch.py @@ -1,5 +1,7 @@ import os import json +import re +from socket import getaddrinfo from re import M @@ -13,30 +15,34 @@ def get_patch(): with open("/app/patch/patch.json", "r") as f: return json.load(f) +def replace_domain(url): + domain = re.search(r'\w[\w\.-]+', url).group() + ip = getaddrinfo(domain, 80)[0][-1][0] + return url.replace(domain, ip) def patch(): - moon = get_moon() - patch = get_patch() - - identity = moon["roots"][0]["identity"] - moon["roots"][0]["stableEndpoints"] = patch["stableEndpoints"] - + moons = get_moon() + patches = get_patch() + text = '' + for moon, patch in zip(moons["roots"], patches): + identity = moon["identity"] + patch["stableEndpoints"] = [replace_domain(url) for url in patch["stableEndpoints"]] + moon["stableEndpoints"] = patch["stableEndpoints"] + + # 修改world + text += f""" + roots.push_back(World::Root()); + roots.back().identity = Identity("{identity}"); + """ + + for i in patch["stableEndpoints"]: + text += f'\n roots.back().stableEndpoints.push_back(InetAddress("{i}"));' # 修改moon with open("/var/lib/zerotier-one/moon.json", "w") as f: - f.write(json.dumps(moon,sort_keys=True, indent=2)) + f.write(json.dumps(moons,sort_keys=True, indent=2)) print("修改后的moon") - print(moon) - - # 修改world - moon["roots"][0]["stableEndpoints"] = get_patch()["stableEndpoints"] - text = f"""// Los Angeles - roots.push_back(World::Root()); - roots.back().identity = Identity("{identity}"); -""" - - for i in get_patch()["stableEndpoints"]: - text += f'\n roots.back().stableEndpoints.push_back(InetAddress("{i}"));' + print(moons) # 生成文件 with open("/app/patch/mkworld.cpp", "r") as cpp: