Update start.sh

This commit is contained in:
wnlen
2026-01-14 22:18:04 +08:00
committed by GitHub
parent c9d8fb06d6
commit 3fd6d3326a

View File

@ -53,15 +53,25 @@ else
fi fi
fi fi
# 获取 CLASH_SECRET 值:优先 .env否则尝试读取旧 config否则生成随机 # 获取 CLASH_SECRET 值:优先 .env其次读取旧 config占位符视为无效;最后生成随机
Secret="${CLASH_SECRET:-}" Secret="${CLASH_SECRET:-}"
# 尝试从旧 config.yaml 读取(仅当 .env 未提供)
if [ -z "$Secret" ] && [ -f "$Conf_Dir/config.yaml" ]; then if [ -z "$Secret" ] && [ -f "$Conf_Dir/config.yaml" ]; then
Secret="$(awk -F': ' '/^secret:/{print $2; exit}' "$Conf_Dir/config.yaml" || true)" Secret="$(awk -F': *' '/^secret:/{gsub(/"/,"",$2); print $2; exit}' "$Conf_Dir/config.yaml" || true)"
fi fi
# 若读取到的是占位符(如 ${CLASH_SECRET}),视为无效
if [[ "$Secret" =~ ^\$\{.*\}$ ]]; then
Secret=""
fi
# 兜底生成随机 secret
if [ -z "$Secret" ]; then if [ -z "$Secret" ]; then
Secret="$(openssl rand -hex 32)" Secret="$(openssl rand -hex 32)"
fi fi
# 设置默认值 # 设置默认值
CLASH_HTTP_PORT="${CLASH_HTTP_PORT:-7890}" CLASH_HTTP_PORT="${CLASH_HTTP_PORT:-7890}"
CLASH_SOCKS_PORT="${CLASH_SOCKS_PORT:-7891}" CLASH_SOCKS_PORT="${CLASH_SOCKS_PORT:-7891}"