修复bug

This commit is contained in:
dekun
2026-05-24 07:43:05 +08:00
parent a3218f4fbd
commit 4b5fae2946
6 changed files with 26 additions and 11 deletions
+2
View File
@@ -1,3 +1,5 @@
# Shell 脚本在仓库内统一 LF,避免 Linux 上 bash: pipefail: invalid option nameCRLF # Shell 脚本在仓库内统一 LF,避免 Linux 上 bash: pipefail: invalid option nameCRLF
*.sh text eol=lf *.sh text eol=lf
deploy/** text eol=lf deploy/** text eol=lf
# .env 模板统一 LF,避免 Linux PM2 source 报 $'\r': command not found
**/.env.example text eol=lf
+12 -4
View File
@@ -62,6 +62,14 @@ function Should-Include([string]$Key, [string[]]$Selected) {
return $Selected -contains $Key return $Selected -contains $Key
} }
# 复制 .env 时统一为 LF,避免上传到 Linux 后 PM2 source 报 $'\r': command not found
function Copy-EnvFileLf([string]$Src, [string]$Dst) {
$raw = [System.IO.File]::ReadAllText($Src)
$lf = ($raw -replace "`r`n", "`n") -replace "`r", "`n"
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
[System.IO.File]::WriteAllText($Dst, $lf, $utf8NoBom)
}
function Setup-MonitorProject([hashtable]$Proj) { function Setup-MonitorProject([hashtable]$Proj) {
$projPath = Join-Path $RepoRoot $Proj.Dir $projPath = Join-Path $RepoRoot $Proj.Dir
if (-not (Test-Path $projPath)) { if (-not (Test-Path $projPath)) {
@@ -94,8 +102,8 @@ function Setup-MonitorProject([hashtable]$Proj) {
$envExample = Join-Path $projPath ".env.example" $envExample = Join-Path $projPath ".env.example"
$envFile = Join-Path $projPath ".env" $envFile = Join-Path $projPath ".env"
if ((Test-Path $envExample) -and -not (Test-Path $envFile)) { if ((Test-Path $envExample) -and -not (Test-Path $envFile)) {
Copy-Item $envExample $envFile Copy-EnvFileLf $envExample $envFile
Write-Host " 已复制 .env.example -> .env" -ForegroundColor Green Write-Host " 已复制 .env.example -> .env (LF)" -ForegroundColor Green
} elseif (Test-Path $envFile) { } elseif (Test-Path $envFile) {
Write-Host " 保留已有 .env" -ForegroundColor DarkGray Write-Host " 保留已有 .env" -ForegroundColor DarkGray
} else { } else {
@@ -147,8 +155,8 @@ function Setup-HubProject() {
$envExample = Join-Path $projPath ".env.example" $envExample = Join-Path $projPath ".env.example"
$envFile = Join-Path $projPath ".env" $envFile = Join-Path $projPath ".env"
if ((Test-Path $envExample) -and -not (Test-Path $envFile)) { if ((Test-Path $envExample) -and -not (Test-Path $envFile)) {
Copy-Item $envExample $envFile Copy-EnvFileLf $envExample $envFile
Write-Host " 已复制 .env.example -> .env" -ForegroundColor Green Write-Host " 已复制 .env.example -> .env (LF)" -ForegroundColor Green
} }
} }
Write-Host " 完成: $venvPy" -ForegroundColor Green Write-Host " 完成: $venvPy" -ForegroundColor Green
+3 -1
View File
@@ -29,4 +29,6 @@ for d in "${dirs[@]}"; do
fi fi
done done
echo "完成,共修复 ${fixed} 个 .env。请执行: pm2 restart ecosystem.config.cjs" echo "完成,共修复 ${fixed} 个 .env。"
echo "请重启子代理: cd ${REPO}/manual_trading_hub && pm2 restart manual-agent-gate manual-agent-gate-bot manual-agent-binance manual-agent-okx"
echo "或: bash scripts/pm2_hub.sh restart"
+3
View File
@@ -20,6 +20,9 @@ if [[ ! -x "${VENV_PY}" ]]; then
fi fi
if [[ -f .env ]]; then if [[ -f .env ]]; then
if grep -q $'\r' .env 2>/dev/null; then
echo "警告: $(pwd)/.env 含 Windows 换行(CRLF),请在仓库根执行: bash manual_trading_hub/scripts/fix_env_crlf.sh" >&2
fi
if ! load_dotenv_file ".env"; then if ! load_dotenv_file ".env"; then
echo "错误: $(pwd)/.env 加载失败" >&2 echo "错误: $(pwd)/.env 加载失败" >&2
exit 1 exit 1
@@ -53,11 +53,11 @@ start_one() {
fi fi
screen -dmS "${name}" bash -c " screen -dmS "${name}" bash -c "
cd '${work}' || { echo 'cd failed' >>'${logf}'; exit 1; } cd '${work}' || { echo 'cd failed' >>'${logf}'; exit 1; }
set -a # shellcheck source=lib_load_dotenv.sh
source '${HUB_DIR}/scripts/lib_load_dotenv.sh'
if [[ -f .env ]]; then if [[ -f .env ]]; then
. ./.env load_dotenv_file .env >>'${logf}' 2>&1 || echo 'load .env failed' >>'${logf}'
fi fi
set +a
export EXCHANGE='${exchange}' PORT='${port}' HOST=127.0.0.1 export EXCHANGE='${exchange}' PORT='${port}' HOST=127.0.0.1
exec '${VENV_PY}' '${AGENT_PY}' >>'${logf}' 2>&1 exec '${VENV_PY}' '${AGENT_PY}' >>'${logf}' 2>&1
" "
@@ -49,11 +49,11 @@ fi
screen -dmS mt-hub bash -c " screen -dmS mt-hub bash -c "
set -e set -e
cd '${HUB_DIR}' cd '${HUB_DIR}'
set -a # shellcheck source=lib_load_dotenv.sh
source '${HUB_DIR}/scripts/lib_load_dotenv.sh'
if [[ -f .env ]]; then if [[ -f .env ]]; then
. ./.env load_dotenv_file .env
fi fi
set +a
export HUB_AGENTS='${HUB_AGENTS}' export HUB_AGENTS='${HUB_AGENTS}'
${EXTRA_NAMES} ${EXTRA_NAMES}
export HUB_HOST='${HUB_HOST}' export HUB_HOST='${HUB_HOST}'