refactor: remove all Docker checks, warnings, compose operations from install script
This commit is contained in:
+11
-171
@@ -78,11 +78,9 @@ $STATUS_CLI_VERSION = ""
|
||||
$STATUS_CLI_SOURCE = ""
|
||||
$STATUS_CLI_PATH = ""
|
||||
$STATUS_REMOTE_VERSION = ""
|
||||
$STATUS_HUB_RUNNING = $false
|
||||
$STATUS_HUB_CONFIGURED = $false
|
||||
$STATUS_AUTOSTART_HUB = $null
|
||||
$STATUS_AUTOSTART_RUNNER = $null
|
||||
$HAS_DOCKER = $false
|
||||
|
||||
# ─────────────────────────────────────────
|
||||
# 输出函数
|
||||
@@ -494,31 +492,10 @@ function Install-NodeJS {
|
||||
Write-Ok "Node.js $(node -v) 安装成功"
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────
|
||||
# 检查 Docker
|
||||
# ─────────────────────────────────────────
|
||||
function Check-Docker {
|
||||
$docker = Get-Command "docker" -ErrorAction SilentlyContinue
|
||||
if ($docker) {
|
||||
try {
|
||||
$null = & docker info 2>$null
|
||||
$script:HAS_DOCKER = $true
|
||||
return
|
||||
} catch {}
|
||||
}
|
||||
$script:HAS_DOCKER = $false
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────
|
||||
# 配置 HAPI Hub
|
||||
# ─────────────────────────────────────────
|
||||
function Setup-Hub {
|
||||
if (-not $script:HAS_DOCKER) {
|
||||
Write-Err "Docker 不可用,无法配置 Hub"
|
||||
Write-Warn "请安装 Docker Desktop: https://docs.docker.com/desktop/install/windows-install/"
|
||||
return
|
||||
}
|
||||
|
||||
Write-Step "配置 HAPI Hub"
|
||||
New-Item -ItemType Directory -Force -Path $script:INSTALL_DIR | Out-Null
|
||||
New-Item -ItemType Directory -Force -Path $script:HAPI_DATA | Out-Null
|
||||
@@ -555,78 +532,7 @@ TZ=Asia/Shanghai
|
||||
Write-Ok "已生成配置文件"
|
||||
}
|
||||
|
||||
$composePath = Join-Path $script:INSTALL_DIR "docker-compose.yml"
|
||||
$composeContent = @"
|
||||
services:
|
||||
hapi-hub:
|
||||
image: ghcr.io/arkylin/hapi-docker:latest
|
||||
container_name: hapi-hub
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- `"3006:3006`"
|
||||
volumes:
|
||||
- ./hapi-data:/root/.hapi
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
- HAPI_LISTEN_HOST=0.0.0.0
|
||||
- HAPI_LISTEN_PORT=3006
|
||||
"@
|
||||
$composeContent | Set-Content $composePath -Encoding UTF8
|
||||
|
||||
Push-Location $script:INSTALL_DIR
|
||||
docker compose pull | Out-File $LOG_FILE -Append
|
||||
docker compose up -d | Out-File $LOG_FILE -Append
|
||||
Pop-Location
|
||||
|
||||
Write-Info "等待 Hub 启动..."
|
||||
for ($i = 0; $i -lt 30; $i++) {
|
||||
try {
|
||||
$resp = Invoke-WebRequest -Uri "http://localhost:3006" -TimeoutSec 2 -UseBasicParsing -ErrorAction SilentlyContinue
|
||||
if ($resp.StatusCode -eq 200) { break }
|
||||
} catch { }
|
||||
Start-Sleep -Seconds 1
|
||||
}
|
||||
Write-Ok "HAPI Hub 已启动"
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────
|
||||
# 停止 HAPI Hub
|
||||
# ─────────────────────────────────────────
|
||||
function Stop-Hub {
|
||||
$composePath = Join-Path $script:INSTALL_DIR "docker-compose.yml"
|
||||
if (-not (Test-Path $composePath)) {
|
||||
Write-Warn "未找到 Hub 配置,无需停止"
|
||||
return
|
||||
}
|
||||
if (-not $script:HAS_DOCKER) {
|
||||
Write-Err "Docker 不可用"
|
||||
return
|
||||
}
|
||||
Write-Step "停止 HAPI Hub"
|
||||
Push-Location $script:INSTALL_DIR
|
||||
docker compose down | Out-File $LOG_FILE -Append
|
||||
Pop-Location
|
||||
Write-Ok "HAPI Hub 已停止"
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────
|
||||
# 启动 HAPI Hub
|
||||
# ─────────────────────────────────────────
|
||||
function Start-HubOnly {
|
||||
if (-not $script:HAS_DOCKER) {
|
||||
Write-Err "Docker 不可用"
|
||||
return
|
||||
}
|
||||
$composePath = Join-Path $script:INSTALL_DIR "docker-compose.yml"
|
||||
if (-not (Test-Path $composePath)) {
|
||||
Write-Warn "未找到 Hub 配置"
|
||||
return
|
||||
}
|
||||
Push-Location $script:INSTALL_DIR
|
||||
docker compose up -d | Out-File $LOG_FILE -Append
|
||||
Pop-Location
|
||||
Write-Ok "HAPI Hub 已启动"
|
||||
Write-Ok "HAPI Hub 配置完成,请手动启动 Hub"
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────
|
||||
@@ -637,8 +543,9 @@ function Setup-AutoStart {
|
||||
|
||||
$hubScriptPath = Join-Path $script:INSTALL_DIR "start-hub.ps1"
|
||||
$hubScript = @"
|
||||
Set-Location "$($script:INSTALL_DIR)"
|
||||
docker compose up -d
|
||||
# HAPI Hub 启动脚本
|
||||
# 请根据实际部署方式启动 Hub
|
||||
# 配置文件: $($script:INSTALL_DIR)\.env
|
||||
"@
|
||||
$hubScript | Set-Content $hubScriptPath -Encoding UTF8
|
||||
|
||||
@@ -779,7 +686,6 @@ function Collect-Status {
|
||||
$script:STATUS_CLI_SOURCE = ""
|
||||
$script:STATUS_CLI_PATH = ""
|
||||
$script:STATUS_REMOTE_VERSION = ""
|
||||
$script:STATUS_HUB_RUNNING = $false
|
||||
$script:STATUS_HUB_CONFIGURED = $false
|
||||
$script:STATUS_AUTOSTART_HUB = $null
|
||||
$script:STATUS_AUTOSTART_RUNNER = $null
|
||||
@@ -793,13 +699,9 @@ function Collect-Status {
|
||||
if (-not $script:STATUS_CLI_PATH) { $script:STATUS_CLI_PATH = "" }
|
||||
}
|
||||
|
||||
$composePath = Join-Path $script:INSTALL_DIR "docker-compose.yml"
|
||||
if (Test-Path $composePath) {
|
||||
$envPath = Join-Path $script:INSTALL_DIR ".env"
|
||||
if (Test-Path $envPath) {
|
||||
$script:STATUS_HUB_CONFIGURED = $true
|
||||
if ($script:HAS_DOCKER) {
|
||||
$containers = (& docker ps --format '{{.Names}}' 2>$null) | Where-Object { $_ -eq "hapi-hub" }
|
||||
if ($containers) { $script:STATUS_HUB_RUNNING = $true }
|
||||
}
|
||||
}
|
||||
|
||||
$hubTask = Get-ScheduledTask -TaskName "HAPI Hub" -ErrorAction SilentlyContinue
|
||||
@@ -828,18 +730,6 @@ function Print-Status {
|
||||
$cliColor = "Green"
|
||||
}
|
||||
|
||||
$hubStatus = "未配置"
|
||||
$hubColor = "Red"
|
||||
if ($script:STATUS_HUB_CONFIGURED) {
|
||||
if ($script:STATUS_HUB_RUNNING) {
|
||||
$hubStatus = "运行中"
|
||||
$hubColor = "Green"
|
||||
} else {
|
||||
$hubStatus = "已配置 (未运行)"
|
||||
$hubColor = "Yellow"
|
||||
}
|
||||
}
|
||||
|
||||
$autoHub = "未设置"
|
||||
$autoRunner = "未设置"
|
||||
if ($script:STATUS_AUTOSTART_HUB) {
|
||||
@@ -868,16 +758,6 @@ function Print-Status {
|
||||
Write-Host $pathLine -ForegroundColor White
|
||||
}
|
||||
Write-Host "║ ║" -ForegroundColor White
|
||||
Write-Host "║ HAPI Hub ║" -ForegroundColor White
|
||||
$hubLine = "║ 状态: $hubStatus"
|
||||
$hubLine = $hubLine.PadRight(67) + "║"
|
||||
Write-Host $hubLine -ForegroundColor White
|
||||
if ($script:STATUS_HUB_CONFIGURED) {
|
||||
$cfgLine = "║ 配置: $($script:INSTALL_DIR)"
|
||||
$cfgLine = $cfgLine.PadRight(67) + "║"
|
||||
Write-Host $cfgLine -ForegroundColor White
|
||||
}
|
||||
Write-Host "║ ║" -ForegroundColor White
|
||||
Write-Host "║ 开机自启 ║" -ForegroundColor White
|
||||
$ahLine = "║ Hub: $autoHub"
|
||||
$ahLine = $ahLine.PadRight(67) + "║"
|
||||
@@ -921,26 +801,9 @@ function Main-Menu {
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
|
||||
if ($script:HAS_DOCKER) {
|
||||
if (-not $script:STATUS_HUB_CONFIGURED) {
|
||||
Write-Host " $i) 配置并启动 HAPI Hub"
|
||||
$options += "hub"
|
||||
$i++
|
||||
} else {
|
||||
if ($script:STATUS_HUB_RUNNING) {
|
||||
Write-Host " $i) 停止 HAPI Hub"
|
||||
$options += "stop_hub"
|
||||
} else {
|
||||
Write-Host " $i) 启动 HAPI Hub"
|
||||
$options += "start_hub"
|
||||
}
|
||||
$i++
|
||||
}
|
||||
} else {
|
||||
Write-Host " Hub 管理 (Docker 不可用)" -ForegroundColor DarkGray
|
||||
}
|
||||
|
||||
Write-Host " $i) 配置 HAPI Hub" -ForegroundColor Yellow
|
||||
$options += "hub"
|
||||
$i++
|
||||
Write-Host ""
|
||||
|
||||
if ($script:STATUS_AUTOSTART_HUB -or $script:STATUS_AUTOSTART_RUNNER) {
|
||||
@@ -992,8 +855,6 @@ function Main-Menu {
|
||||
"upgrade" { Execute-Upgrade }
|
||||
"uninstall" { Execute-Uninstall }
|
||||
"hub" { Execute-HubSetup }
|
||||
"start_hub" { Execute-StartHub }
|
||||
"stop_hub" { Execute-StopHub }
|
||||
"setup_autostart" { Execute-SetupAutoStart }
|
||||
"disable_autostart" { Execute-DisableAutoStart }
|
||||
"refresh" {
|
||||
@@ -1123,24 +984,12 @@ function Execute-HubSetup {
|
||||
Read-Host "按 Enter 继续..."
|
||||
}
|
||||
|
||||
function Execute-StartHub {
|
||||
Start-HubOnly
|
||||
Collect-Status
|
||||
Read-Host "按 Enter 继续..."
|
||||
}
|
||||
|
||||
function Execute-StopHub {
|
||||
Stop-Hub
|
||||
Collect-Status
|
||||
Read-Host "按 Enter 继续..."
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────
|
||||
# 菜单操作:开机自启
|
||||
# ─────────────────────────────────────────
|
||||
function Execute-SetupAutoStart {
|
||||
if (-not $script:STATUS_HUB_CONFIGURED) {
|
||||
Write-Warn "Hub 未配置,先执行配置并启动 HAPI Hub"
|
||||
Write-Warn "Hub 未配置,先执行配置"
|
||||
Setup-Hub
|
||||
}
|
||||
Setup-AutoStart
|
||||
@@ -1168,15 +1017,6 @@ function Check-Prerequisites {
|
||||
}
|
||||
}
|
||||
Write-Ok "基础工具检查通过"
|
||||
|
||||
Check-Docker
|
||||
if ($script:HAS_DOCKER) {
|
||||
Write-Ok "Docker 可用"
|
||||
} else {
|
||||
Write-Warn "Docker 不可用"
|
||||
Write-Warn "Hub 管理功能将不可用"
|
||||
Write-Warn "请安装 Docker Desktop: https://docs.docker.com/desktop/install/windows-install/"
|
||||
}
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────
|
||||
@@ -1314,7 +1154,7 @@ function Run-QuickMode {
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ($script:HAS_DOCKER -and -not $SkipHub) {
|
||||
if (-not $SkipHub) {
|
||||
Setup-Hub
|
||||
Setup-AutoStart
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user