修复bug
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
# Shell 脚本在仓库内统一 LF,避免 Linux 上 bash: pipefail: invalid option name(CRLF)
|
||||
*.sh text eol=lf
|
||||
deploy/** text eol=lf
|
||||
# .env 模板统一 LF,避免 Linux PM2 source 报 $'\r': command not found
|
||||
**/.env.example text eol=lf
|
||||
|
||||
+12
-4
@@ -62,6 +62,14 @@ function Should-Include([string]$Key, [string[]]$Selected) {
|
||||
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) {
|
||||
$projPath = Join-Path $RepoRoot $Proj.Dir
|
||||
if (-not (Test-Path $projPath)) {
|
||||
@@ -94,8 +102,8 @@ function Setup-MonitorProject([hashtable]$Proj) {
|
||||
$envExample = Join-Path $projPath ".env.example"
|
||||
$envFile = Join-Path $projPath ".env"
|
||||
if ((Test-Path $envExample) -and -not (Test-Path $envFile)) {
|
||||
Copy-Item $envExample $envFile
|
||||
Write-Host " 已复制 .env.example -> .env" -ForegroundColor Green
|
||||
Copy-EnvFileLf $envExample $envFile
|
||||
Write-Host " 已复制 .env.example -> .env (LF)" -ForegroundColor Green
|
||||
} elseif (Test-Path $envFile) {
|
||||
Write-Host " 保留已有 .env" -ForegroundColor DarkGray
|
||||
} else {
|
||||
@@ -147,8 +155,8 @@ function Setup-HubProject() {
|
||||
$envExample = Join-Path $projPath ".env.example"
|
||||
$envFile = Join-Path $projPath ".env"
|
||||
if ((Test-Path $envExample) -and -not (Test-Path $envFile)) {
|
||||
Copy-Item $envExample $envFile
|
||||
Write-Host " 已复制 .env.example -> .env" -ForegroundColor Green
|
||||
Copy-EnvFileLf $envExample $envFile
|
||||
Write-Host " 已复制 .env.example -> .env (LF)" -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
Write-Host " 完成: $venvPy" -ForegroundColor Green
|
||||
|
||||
@@ -29,4 +29,6 @@ for d in "${dirs[@]}"; do
|
||||
fi
|
||||
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"
|
||||
|
||||
@@ -20,6 +20,9 @@ if [[ ! -x "${VENV_PY}" ]]; then
|
||||
fi
|
||||
|
||||
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
|
||||
echo "错误: $(pwd)/.env 加载失败" >&2
|
||||
exit 1
|
||||
|
||||
@@ -53,11 +53,11 @@ start_one() {
|
||||
fi
|
||||
screen -dmS "${name}" bash -c "
|
||||
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
|
||||
. ./.env
|
||||
load_dotenv_file .env >>'${logf}' 2>&1 || echo 'load .env failed' >>'${logf}'
|
||||
fi
|
||||
set +a
|
||||
export EXCHANGE='${exchange}' PORT='${port}' HOST=127.0.0.1
|
||||
exec '${VENV_PY}' '${AGENT_PY}' >>'${logf}' 2>&1
|
||||
"
|
||||
|
||||
@@ -49,11 +49,11 @@ fi
|
||||
screen -dmS mt-hub bash -c "
|
||||
set -e
|
||||
cd '${HUB_DIR}'
|
||||
set -a
|
||||
# shellcheck source=lib_load_dotenv.sh
|
||||
source '${HUB_DIR}/scripts/lib_load_dotenv.sh'
|
||||
if [[ -f .env ]]; then
|
||||
. ./.env
|
||||
load_dotenv_file .env
|
||||
fi
|
||||
set +a
|
||||
export HUB_AGENTS='${HUB_AGENTS}'
|
||||
${EXTRA_NAMES}
|
||||
export HUB_HOST='${HUB_HOST}'
|
||||
|
||||
Reference in New Issue
Block a user