fix-authtoken (#119)

This commit is contained in:
Markxu 2024-01-06 21:07:05 +08:00 committed by GitHub
parent b4c4bc636a
commit ddfce29c28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 34 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.idea
/data

View File

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

3
build.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
docker build -t xubiaolin/zerotier-planet:latest .

View File

@ -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() {

View File

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