Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
93 lines (76 loc) · 3.04 KB
/
Copy pathinstall.ps1
File metadata and controls
93 lines (76 loc) · 3.04 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# WeChatBot Echo Bot — Windows install script
# Usage (PowerShell):
# irm https://raw.githubusercontent.com/corespeed-io/wechatbot/main/install.ps1 | iex
# install.ps1 -Version v0.1.0
# install.ps1 -Dir C:\tools
param(
[string]$Version = "",
[string]$Dir = "$env:LOCALAPPDATA\wechatbot\bin"
)
$ErrorActionPreference = "Stop"
$Repo = "corespeed-io/wechatbot"
$BinaryName = "wechatbot-echo-bot"
# ── Detect architecture ──────────────────────────────────────────────
function Get-Platform {
$arch = if ([Environment]::Is64BitOperatingSystem) {
if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64" -or
(Get-CimInstance Win32_Processor).Architecture -eq 12) {
"arm64"
} else {
"amd64"
}
} else {
Write-Error "32-bit systems are not supported"
exit 1
}
return "windows-$arch"
}
# ── Resolve latest version ──────────────────────────────────────────
function Get-LatestVersion {
if ($Version -ne "") { return $Version }
try {
$release = Invoke-RestMethod "https://api.github.com/repos/$Repo/releases/latest"
return $release.tag_name
} catch {
Write-Error "Could not determine latest version. Use -Version to specify."
exit 1
}
}
# ── Main ─────────────────────────────────────────────────────────────
$platform = Get-Platform
$ver = Get-LatestVersion
$url = "https://github.com/$Repo/releases/download/$ver/$BinaryName-$platform.exe"
Write-Host ""
Write-Host " WeChatBot Echo Bot Installer" -ForegroundColor Cyan
Write-Host ""
Write-Host " Version: $ver"
Write-Host " Platform: $platform"
Write-Host " URL: $url"
Write-Host ""
# Create install directory
if (!(Test-Path $Dir)) {
New-Item -ItemType Directory -Path $Dir -Force | Out-Null
}
$targetFile = Join-Path $Dir "$BinaryName.exe"
Write-Host " Downloading..." -ForegroundColor Yellow
Invoke-WebRequest -Uri $url -OutFile $targetFile -UseBasicParsing
Write-Host " Installed to: $targetFile" -ForegroundColor Green
Write-Host ""
# Add to PATH if not already there
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($currentPath -notlike "*$Dir*") {
$addToPath = Read-Host " Add $Dir to PATH? (Y/n)"
if ($addToPath -ne "n" -and $addToPath -ne "N") {
[Environment]::SetEnvironmentVariable("Path", "$currentPath;$Dir", "User")
$env:Path = "$env:Path;$Dir"
Write-Host " Added to PATH (restart terminal to take effect)" -ForegroundColor Green
} else {
Write-Host ""
Write-Host " To add manually, run:" -ForegroundColor Yellow
Write-Host " `$env:Path += `";$Dir`"" -ForegroundColor White
Write-Host ""
}
}
Write-Host ""
Write-Host " Run: $BinaryName" -ForegroundColor Cyan
Write-Host ""