From 2c1c1b6a2f7b818eac970512c183579e04e3d69f Mon Sep 17 00:00:00 2001 From: yuming Date: Sat, 25 Apr 2026 22:44:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B7=B2=E9=85=8D=E7=BD=AE=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E6=97=B6=E4=B8=8D=E8=A2=AB=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entrypoint.sh | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 2230031..60cbf6c 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -26,21 +26,27 @@ if [ -n "$WEB_PORT" ] && [ -f "$APPDATA/config.yaml" ]; then sed -i "s/^web_port:.*/web_port: ${WEB_PORT}/" "$APPDATA/config.yaml" fi -# 若设置了代理环境变量,写入 config.yaml +# 仅在首次启动(config.yaml 中尚未配置 proxy)时,使用环境变量初始化代理 +# 已经在 Web 界面保存过的代理配置不会被环境变量覆盖 if [ -n "$PROXY_HOSTNAME" ] && [ -f "$APPDATA/config.yaml" ]; then python3 -c " import yaml, os, sys path = '$APPDATA/config.yaml' with open(path) as f: cfg = yaml.safe_load(f) or {} -cfg['proxy'] = { - 'scheme': os.environ.get('PROXY_SCHEME', 'socks5'), - 'hostname': os.environ.get('PROXY_HOSTNAME'), - 'port': int(os.environ.get('PROXY_PORT', 7890)) -} -with open(path, 'w') as f: - yaml.dump(cfg, f, allow_unicode=True, default_flow_style=False) -print('[entrypoint] 代理配置已写入: ' + cfg['proxy']['scheme'] + '://' + cfg['proxy']['hostname'] + ':' + str(cfg['proxy']['port'])) +# 仅当 proxy 不存在或 hostname 为空时才用环境变量初始化 +existing = cfg.get('proxy') or {} +if not existing.get('hostname'): + cfg['proxy'] = { + 'scheme': os.environ.get('PROXY_SCHEME', 'socks5'), + 'hostname': os.environ.get('PROXY_HOSTNAME'), + 'port': int(os.environ.get('PROXY_PORT', 7890)) + } + with open(path, 'w') as f: + yaml.dump(cfg, f, allow_unicode=True, default_flow_style=False) + print('[entrypoint] 首次启动,代理配置已写入: ' + cfg['proxy']['scheme'] + '://' + cfg['proxy']['hostname'] + ':' + str(cfg['proxy']['port'])) +else: + print('[entrypoint] 检测到已有代理配置,跳过环境变量覆盖: ' + existing.get('scheme', '') + '://' + existing.get('hostname', '') + ':' + str(existing.get('port', ''))) " fi