Skip to content

Commit

Permalink
fix-authtoken (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
xubiaolin authored Jan 6, 2024
1 parent b4c4bc6 commit ddfce29
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
/data
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

docker build -t xubiaolin/zerotier-planet:latest .
4 changes: 2 additions & 2 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
60 changes: 29 additions & 31 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit ddfce29

Please sign in to comment.