From ddfce29c28731a17e7b5263e7d6e2c00b5fcad6d Mon Sep 17 00:00:00 2001 From: Markxu <51899048+xubiaolin@users.noreply.github.com> Date: Sat, 6 Jan 2024 21:07:05 +0800 Subject: [PATCH] fix-authtoken (#119) --- .gitignore | 1 + Dockerfile | 2 +- build.sh | 3 +++ deploy.sh | 4 ++-- entrypoint.sh | 60 +++++++++++++++++++++++++-------------------------- 5 files changed, 36 insertions(+), 34 deletions(-) create mode 100755 build.sh diff --git a/.gitignore b/.gitignore index 485dee6..11b13dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea +/data \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e19db46..bd0b08f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,7 +61,7 @@ COPY --from=builder /app/http_server.js /app/http_server.js RUN set -x ;sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \ && apk update \ - && apk add --no-cache npm curl jq\ + && apk add --no-cache npm curl jq openssl\ && mkdir /app/config -p diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..41efcb6 --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker build -t xubiaolin/zerotier-planet:latest . \ No newline at end of file diff --git a/deploy.sh b/deploy.sh index 469f1cb..2d5bbcc 100755 --- a/deploy.sh +++ b/deploy.sh @@ -19,7 +19,7 @@ function install() { fi docker rm -f myztplanet - rm -f $(pwd)/data/zerotier + rm -rf $(pwd)/data/zerotier ZT_PORT=9994 API_PORT=3443 @@ -218,7 +218,7 @@ function update() { -e API_PORT=${API_PORT} \ -e FILE_SERVER_PORT=${FILE_PORT} \ -v $(pwd)/data/zerotier/dist:/app/dist \ - -v $(pwd)/data/zerotier/ztncui:/app/ztncui -v $(pwd)/data/zerotier/one:/var/lib/zerotier-one -v /data/config:/app/config xubiaolin/zerotier-planet:latest + -v $(pwd)/data/zerotier/ztncui:/app/ztncui -v $(pwd)/data/zerotier/one:/var/lib/zerotier-one -v $(pwd)/data/config:/app/config xubiaolin/zerotier-planet:latest } function menu() { diff --git a/entrypoint.sh b/entrypoint.sh index f99b616..19093b0 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -9,26 +9,15 @@ function start() { cd /app/ztncui/src && npm start || exit 1 } -function check_ztncui() { - mkdir -p /app/ztncui - if [ "$(ls -A /app/ztncui)" ]; then - echo "${API_PORT}" >/app/config/ztncui.port - echo "/app/ztncui is not empty, start directly" +function check_file_server(){ + if [ ! -f "/app/config/file_server.port" ]; then + echo "file_server.port is not exist, generate it" + echo "${FILE_SERVER_PORT}" >/app/config/file_server.port + echo "${FILE_SERVER_PORT}" else - echo "/app/ztncui is empty, init data" - cp -r /bak/ztncui/* /app/ztncui/ - - echo "config ztncui" - mkdir -p /app/config - echo "${API_PORT}" >/app/config/ztncui.port - cd /app/ztncui/src - echo "HTTP_PORT=${API_PORT}" >.env && - echo 'NODE_ENV=production' >>.env && - echo 'HTTP_ALL_INTERFACES=true' >>.env && - echo "ZT_ADDR=localhost:${ZT_PORT}" >>.env && echo "${ZT_PORT}" >/app/config/zerotier-one.port && - cp -v etc/default.passwd etc/passwd && TOKEN=$(cat /var/lib/zerotier-one/authtoken.secret) && - echo "ZT_TOKEN=$TOKEN" >>.env && - echo "make ztncui success!" + echo "file_server.port is exist, read it" + FILE_SERVER_PORT=$(cat /app/config/file_server.port) + echo "${FILE_SERVER_PORT}" fi } @@ -44,6 +33,7 @@ function check_zerotier() { cd /var/lib/zerotier-one echo "start mkmoonworld" + openssl rand -hex 16 > authtoken.secret ./zerotier-idtool initmoon identity.public >moon.json @@ -54,10 +44,8 @@ function check_zerotier() { echo "IP_ADDR6=$IP_ADDR6" ZT_PORT=$(cat /app/config/zerotier-one.port) - API_PORT=$(cat /app/config/ztncui.port) echo "ZT_PORT=$ZT_PORT" - echo "API_PORT=$API_PORT" if [ -z "$IP_ADDR4" ]; then stableEndpoints="[\"$IP_ADDR6/${ZT_PORT}\"]"; fi if [ -z "$IP_ADDR6" ]; then stableEndpoints="[\"$IP_ADDR4/${ZT_PORT}\"]"; fi @@ -86,21 +74,31 @@ function check_zerotier() { fi } -function check_file_server(){ - if [ ! -f "/app/config/file_server.port" ]; then - echo "file_server.port is not exist, generate it" - echo "${FILE_SERVER_PORT}" >/app/config/file_server.port - echo "${FILE_SERVER_PORT}" +function check_ztncui() { + mkdir -p /app/ztncui + if [ "$(ls -A /app/ztncui)" ]; then + echo "${API_PORT}" >/app/config/ztncui.port + echo "/app/ztncui is not empty, start directly" else - echo "file_server.port is exist, read it" - FILE_SERVER_PORT=$(cat /app/config/file_server.port) - echo "${FILE_SERVER_PORT}" + echo "/app/ztncui is empty, init data" + cp -r /bak/ztncui/* /app/ztncui/ + + echo "config ztncui" + mkdir -p /app/config + echo "${API_PORT}" >/app/config/ztncui.port + cd /app/ztncui/src + echo "HTTP_PORT=${API_PORT}" >.env && + echo 'NODE_ENV=production' >>.env && + echo 'HTTP_ALL_INTERFACES=true' >>.env && + echo "ZT_ADDR=localhost:${ZT_PORT}" >>.env && echo "${ZT_PORT}" >/app/config/zerotier-one.port && + cp -v etc/default.passwd etc/passwd && TOKEN=$(cat /var/lib/zerotier-one/authtoken.secret) && + echo "ZT_TOKEN=$TOKEN" >>.env && + echo "make ztncui success!" fi } - check_file_server -check_ztncui check_zerotier +check_ztncui start \ No newline at end of file