-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.ps1
More file actions
35 lines (26 loc) · 1.36 KB
/
install.ps1
File metadata and controls
35 lines (26 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
$ErrorActionPreference = "Stop"
$REPO = "afumu/openlink"
$BIN = "openlink"
$INSTALL_DIR = "$env:USERPROFILE\.openlink"
$ARCH = if ([Environment]::Is64BitOperatingSystem) { "amd64" } else { "386" }
$response = Invoke-WebRequest -Uri "https://github.com/$REPO/releases/latest" -MaximumRedirection 0 -ErrorAction SilentlyContinue
$VERSION = $response.Headers.Location -replace ".*/tag/", ""
if (-not $VERSION) { Write-Error "获取版本失败"; exit 1 }
$FILE = "${BIN}_windows_${ARCH}.zip"
$URL = "https://github.com/$REPO/releases/download/$VERSION/$FILE"
Write-Host "正在安装 openlink $VERSION (windows/$ARCH)..."
New-Item -ItemType Directory -Force -Path $INSTALL_DIR | Out-Null
$TMP = Join-Path $env:TEMP "openlink_install"
New-Item -ItemType Directory -Force -Path $TMP | Out-Null
Invoke-WebRequest -Uri $URL -OutFile "$TMP\openlink.zip"
Expand-Archive -Path "$TMP\openlink.zip" -DestinationPath $TMP -Force
Move-Item -Force "$TMP\$BIN.exe" "$INSTALL_DIR\$BIN.exe"
Remove-Item -Recurse -Force $TMP
# 添加到用户 PATH
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($path -notlike "*$INSTALL_DIR*") {
[Environment]::SetEnvironmentVariable("PATH", "$path;$INSTALL_DIR", "User")
Write-Host "已添加 $INSTALL_DIR 到 PATH(重新打开终端生效)"
}
Write-Host "安装完成: $INSTALL_DIR\$BIN.exe"
Write-Host "运行 'openlink' 启动服务"