+11
-5
@@ -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'] = {
|
||||
# 仅当 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:
|
||||
}
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user