Files
ssh-e2e/install.ps1
T
leefer 97d8b7ae89 跨平台支持:CLI 模式 + 三平台一键安装命令
- cli.py:无界面命令行(host/tunnel/list/test/start/remove),复用隧道引擎
- storage.py:配置目录跨平台(Win %APPDATA%,Linux ~/ssh-e2e/.config,macOS ~/ssh-e2e/Library),
  非 Windows 经 keyring+AES-GCM 加密机密,无后端时明文并提示
- install.sh / install.ps1:经 gitea.xbay.cc 一键拉取安装
- 修复:Store 未创建配置目录的崩溃(CLI 路径)
2026-09-27 19:59:25 +08:00

71 lines
3.4 KiB
PowerShell

# SSH 隧道管理器 一键安装(Windows)
# 用法: powershell -c "irm https://gitea.xbay.cc/leefer/ssh-e2e/raw/branch/main/install.ps1 | iex"
$ErrorActionPreference = "Stop"
$BaseUrl = "https://gitea.xbay.cc/leefer/ssh-e2e"
$AppDir = Join-Path $env:USERPROFILE "ssh-e2e"
function Say($m) { Write-Host "===> $m" -ForegroundColor Green }
function Die($m) { Write-Host "错误: $m" -ForegroundColor Red; Read-Host "按回车退出"; exit 1 }
# ---------- 下载源码 ----------
Say "下载最新代码到 $AppDir ..."
New-Item -ItemType Directory -Force -Path $AppDir | Out-Null
$gotCode = $false
if (Get-Command git -ErrorAction SilentlyContinue) {
if (Test-Path (Join-Path $AppDir ".git")) {
git -C $AppDir fetch --all --quiet 2>$null
git -C $AppDir reset --hard origin/main --quiet 2>$null
$gotCode = $?
} else {
git clone --depth 1 "$BaseUrl.git" $AppDir 2>$null
if ($?) { $gotCode = $true }
}
if (-not $gotCode -and (Test-Path (Join-Path $AppDir "cli.py"))) { $gotCode = $true }
}
if (-not $gotCode) {
# git 不可用或失败:下载 zip 归档
$zip = Join-Path $env:TEMP "ssh-e2e-main.zip"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest "$BaseUrl/archive/main.zip" -OutFile $zip -UseBasicParsing
$tmp = Join-Path $env:TEMP "ssh-e2e-extract"
if (Test-Path $tmp) { Remove-Item $tmp -Recurse -Force }
Expand-Archive $zip -DestinationPath $tmp
$inner = Get-ChildItem $tmp | Where-Object PSIsContainer | Select-Object -First 1
Get-ChildItem $inner.FullName | Move-Item -Destination $AppDir -Force
Remove-Item $tmp, $zip -Recurse -Force -ErrorAction SilentlyContinue
}
if (-not (Test-Path (Join-Path $AppDir "main.py"))) { Die "代码下载失败,请检查网络" }
# ---------- Python 检查 ----------
$py = Get-Command python -ErrorAction SilentlyContinue
if (-not $py) { Die "未找到 python,请先安装 Python 3.10+(https://www.python.org/downloads/)" }
# ---------- 虚拟环境 ----------
if (-not (Test-Path (Join-Path $AppDir ".venv\Scripts\pythonw.exe"))) {
Say "创建虚拟环境并安装依赖(首次约 1-2 分钟)..."
python -m venv (Join-Path $AppDir ".venv")
if ($LASTEXITCODE -ne 0) { Die "创建虚拟环境失败" }
& (Join-Path $AppDir ".venv\Scripts\python.exe") -m pip install --quiet --disable-pip-version-check -r (Join-Path $AppDir "requirements.txt")
if ($LASTEXITCODE -ne 0) { Die "依赖安装失败,请检查网络" }
} elseif (-not (Test-Path (Join-Path $AppDir ".venv\Lib\site-packages\pystray"))) {
& (Join-Path $AppDir ".venv\Scripts\python.exe") -m pip install --quiet --disable-pip-version-check -r (Join-Path $AppDir "requirements.txt")
}
# ---------- 桌面快捷方式 ----------
try {
$ws = New-Object -ComObject WScript.Shell
$lnk = $ws.CreateShortcut([IO.Path]::Combine([Environment]::GetFolderPath("Desktop"), "SSH 隧道管理器.lnk"))
$lnk.TargetPath = Join-Path $AppDir ".venv\Scripts\pythonw.exe"
$lnk.Arguments = '"' + (Join-Path $AppDir "main.py") + '"'
$lnk.WorkingDirectory = $AppDir
$lnk.IconLocation = Join-Path $AppDir "ui\app.ico"
$lnk.Save()
Say "已创建桌面快捷方式"
} catch { }
# ---------- 启动 ----------
Say "启动 SSH 隧道管理器 ..."
Start-Process -FilePath (Join-Path $AppDir ".venv\Scripts\pythonw.exe") `
-ArgumentList ('"' + (Join-Path $AppDir "main.py") + '"') -WorkingDirectory $AppDir
Say "完成!窗口即将弹出;点最小化/关闭会驻留系统托盘。"