fix: 已配置代理时不被环境变量覆盖
部署到群晖 / deploy (push) Successful in 41s

This commit is contained in:
yuming
2026-04-25 22:44:24 +08:00
parent 144fad29c2
commit 2c1c1b6a2f
+8 -2
View File
@@ -26,13 +26,17 @@ 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 {}
# 仅当 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'),
@@ -40,7 +44,9 @@ cfg['proxy'] = {
}
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']))
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