From 6776868483d86c85a414a25e967fb192d8c83450 Mon Sep 17 00:00:00 2001
From: root <evlicn.ok@gmail.com>
Date: Fri, 21 Mar 2025 04:31:57 +0000
Subject: [PATCH] update

---
 .gitignore          |  1 +
 docker-compose.yaml |  2 +-
 env.sh              |  0
 env_model           |  6 +++---
 run-re.sh           |  4 +---
 run.sh              |  7 -------
 update-env.sh       | 39 +++++++++++++++++++++++++++++++++++++++
 7 files changed, 45 insertions(+), 14 deletions(-)
 delete mode 100755 env.sh
 create mode 100755 update-env.sh

diff --git a/.gitignore b/.gitignore
index 33c9010..0b4c236 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 nginx/
 !nginx/etc/mime.types
+.env
diff --git a/docker-compose.yaml b/docker-compose.yaml
index 6c6e0ff..6a9d690 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -21,7 +21,7 @@ services:
       - H2_REALITY=true
       - GRPC_REALITY=true
       - UUID=${UUID}
-      - NODE_NAME=${NAME}
+      - NODE_NAME=${HOST}
       - CDN=www.csgo.com
       - ARGO_DOMAIN=${IP}
       - ARGO_AUTH=''
diff --git a/env.sh b/env.sh
deleted file mode 100755
index e69de29..0000000
diff --git a/env_model b/env_model
index c43336e..2758412 100644
--- a/env_model
+++ b/env_model
@@ -5,9 +5,9 @@ TZ=Asia/Shanghai
 TERM=xterm-256color
 
 DIR=.
-ROOT_DIR=/root/.u22
 
 UUID=
 IP=
-NAME=
-PORT= 
+HOST=
+PORT=
+ROOT_DIR=/root/.sing
\ No newline at end of file
diff --git a/run-re.sh b/run-re.sh
index a5e3dc9..d906e4d 100755
--- a/run-re.sh
+++ b/run-re.sh
@@ -1,5 +1,3 @@
-ip_addr=`wget -qO- ipinfo.io/ip`
-
-IP_ADDR="$ip_addr" docker compose up -d --force-recreate
+docker compose up -d --force-recreate
 
 docker logs -f sing
diff --git a/run.sh b/run.sh
index 6aec9e7..3be093f 100755
--- a/run.sh
+++ b/run.sh
@@ -1,10 +1,3 @@
-ip_addr=`wget -qO- ipinfo.io/ip`
-
-NAME=`hostnamectl`
-IP="$ip_addr" 
-PORT=40900
-
-
 docker compose up -d --build
 
 docker logs -f sing
diff --git a/update-env.sh b/update-env.sh
new file mode 100755
index 0000000..0ddff21
--- /dev/null
+++ b/update-env.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+set -x
+
+# 如果 .env 文件不存在,则从 env_model 复制
+if [ ! -f .env ]; then
+    cp env_model .env
+fi
+
+# 读取 .env 文件中的 PORT,如果不存在则使用默认值 40900
+DEF_PORT="40900"
+PORT=$(grep -E '^PORT=' .env | cut -d '=' -f2)
+PORT=${PORT:-$DEF_PORT}
+
+# 读取 .env 文件中的 UUID,如果不存在则生成一个新的
+DEF_UUID="20f7fca4-86e5-4ddf-9eed-24142073d197"
+UUID=$(grep -E '^UUID=' .env | cut -d '=' -f2)
+UUID=${UUID:-$DEF_UUID}
+
+# 读取默认 HOST
+HOST=$(grep -E '^HOST=' .env | cut -d '=' -f2)
+NOW_HOST=`hostname`
+HOST=${HOST:-$NOW_HOST}
+
+# 生成新的 IP 地址(这里用示例 IP,你可以根据需要动态生成)
+NOW_IP=`wget -qO- ipinfo.io/ip`
+
+# 更新 IP 地址
+sed -i "s/^IP=.*/IP=$NOW_IP/" .env
+
+# 更新 UUID
+sed -i "s/^UUID=.*/UUID=$UUID/" .env
+
+# 更新 HOST,如果没有值
+sed -i "/^HOST=/s/HOST=$/HOST=$HOST/" .env
+
+# 更新 PORT,如果没有值
+sed -i "/^PORT=/s/PORT=$/PORT=$PORT/" .env
+
+cat .env