-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
79 lines (64 loc) · 3.16 KB
/
Copy pathinstall.ps1
File metadata and controls
79 lines (64 loc) · 3.16 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
# Installs the latest ritobin-tools release for Windows (user scope)
param(
[string]$Owner = "LeagueToolkit",
[string]$Repo = "ritobin-tools",
[string]$Channel = "windows-x64",
[string]$InstallDir = "$env:LOCALAPPDATA\LeagueToolkit\ritobin-tools"
)
$ErrorActionPreference = 'Stop'
Write-Host "Installing ritobin-tools..." -ForegroundColor Cyan
if (!(Test-Path -LiteralPath $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
# Get latest release metadata
$releaseApi = "https://api.github.com/repos/$Owner/$Repo/releases/latest"
try {
$release = Invoke-RestMethod -Uri $releaseApi -Headers @{ 'User-Agent' = 'ritobin-tools-installer' }
} catch {
throw "Failed to query GitHub releases: $($_.Exception.Message)"
}
$tag = $release.tag_name
# Extract the first semantic version (handles tags like "v0.1.1" or "ritobin-tools-v0.1.1")
$match = [regex]::Match($tag, '\d+\.\d+\.\d+([\-\+][A-Za-z0-9\.-]+)?')
$version = if ($match.Success) { $match.Value } else { $tag.TrimStart('v') }
$assetName = "ritobin-tools-$version-$Channel.zip"
$asset = $release.assets | Where-Object { $_.name -eq $assetName } | Select-Object -First 1
if (-not $asset) {
# Fallback: find any ritobin-tools asset matching the channel
$pattern = "^ritobin-tools-.*-" + [regex]::Escape($Channel) + "\.zip$"
$asset = $release.assets | Where-Object { $_.name -match $pattern } | Select-Object -First 1
}
if (-not $asset) {
throw "Could not find asset matching '$assetName' (channel $Channel) in the latest release."
}
if ($asset.name -ne $assetName) { $assetName = $asset.name }
$zipPath = Join-Path $env:TEMP $assetName
Write-Host "Downloading $assetName ($version)..." -ForegroundColor Yellow
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $zipPath -UseBasicParsing
Write-Host "Extracting to $InstallDir" -ForegroundColor Yellow
Expand-Archive -Path $zipPath -DestinationPath $InstallDir -Force
# Create a shim directory so PATH is simple and stable
$binDir = Join-Path $InstallDir 'bin'
if (!(Test-Path -LiteralPath $binDir)) { New-Item -ItemType Directory -Path $binDir | Out-Null }
# Ensure the executable exists
$exePath = Join-Path $InstallDir 'ritobin-tools.exe'
if (!(Test-Path -LiteralPath $exePath)) {
throw "ritobin-tools.exe not found after extraction: $exePath"
}
# Place a thin cmd shim in bin to avoid spaces in paths and simplify PATH updates
$shimCmd = @"
@echo off
"$exePath" %*
"@
Set-Content -LiteralPath (Join-Path $binDir 'ritobin-tools.cmd') -Value $shimCmd -Encoding Ascii -Force
# Add to user PATH if missing
$currentPath = [Environment]::GetEnvironmentVariable('Path', 'User')
if (-not ($currentPath -split ';' | Where-Object { $_ -eq $binDir })) {
$newPath = if ([string]::IsNullOrEmpty($currentPath)) { $binDir } else { "$currentPath;$binDir" }
[Environment]::SetEnvironmentVariable('Path', $newPath, 'User')
Write-Host "Added to PATH (User): $binDir" -ForegroundColor Green
} else {
Write-Host "PATH already contains: $binDir" -ForegroundColor Green
}
Write-Host "Installed ritobin-tools $version to $InstallDir" -ForegroundColor Green
Write-Host "Open a new terminal and run: ritobin-tools --help" -ForegroundColor Cyan