-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
77 lines (60 loc) · 2.49 KB
/
Copy pathinstall.ps1
File metadata and controls
77 lines (60 loc) · 2.49 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
param(
[string]$Repo = "syn7xx/scoria",
[string]$InstallDir = "$env:USERPROFILE\Tools\scoria"
)
$ErrorActionPreference = "Stop"
function Get-LatestTag {
param([string]$Repository)
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repository/releases/latest"
if (-not $release.tag_name) {
throw "Could not fetch latest release tag."
}
return [string]$release.tag_name
}
function Add-ToUserPath {
param([string]$Dir)
$fullDir = [System.IO.Path]::GetFullPath($Dir)
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
$parts = @($userPath -split ';' | Where-Object { $_ -and $_.Trim() -ne "" })
if ($parts -contains $fullDir) {
Write-Host "Already in user PATH: $fullDir"
return
}
$newPath = if ($parts.Count -gt 0) {
($parts + $fullDir) -join ';'
} else {
$fullDir
}
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
Write-Host "Added to user PATH: $fullDir"
}
$tag = Get-LatestTag -Repository $Repo
$asset = "scoria-windows-x86_64.zip"
$checksumAsset = "scoria-windows-x86_64.sha256"
$url = "https://github.com/$Repo/releases/download/$tag/$asset"
$checksumUrl = "https://github.com/$Repo/releases/download/$tag/$checksumAsset"
Write-Host "Installing scoria $tag (windows/x86_64)..."
Write-Host " from: $url"
Write-Host " to: $InstallDir\scoria.exe"
$msiInstallDir = Join-Path ${env:ProgramFiles} "Scoria"
if (Test-Path $msiInstallDir) {
Write-Warning "Detected MSI-style install directory at '$msiInstallDir'. Portable install in '$InstallDir' may create PATH/version ambiguity."
}
$zipPath = Join-Path $env:TEMP "scoria-windows-x86_64.zip"
$shaPath = Join-Path $env:TEMP "scoria-windows-x86_64.zip.sha256"
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
Invoke-WebRequest -Uri $url -OutFile $zipPath
Invoke-WebRequest -Uri $checksumUrl -OutFile $shaPath
$expectedSha = (Get-Content -Path $shaPath -Raw).Trim().Split(" ")[0].ToLowerInvariant()
$actualSha = (Get-FileHash -Path $zipPath -Algorithm SHA256).Hash.ToLowerInvariant()
if ($expectedSha -ne $actualSha) {
throw "Checksum mismatch for downloaded archive."
}
Expand-Archive -Path $zipPath -DestinationPath $InstallDir -Force
if (-not (Test-Path (Join-Path $InstallDir "scoria.exe"))) {
throw "Installation failed: scoria.exe was not found after extraction."
}
Add-ToUserPath -Dir $InstallDir
Write-Host ""
Write-Host "Done. Restart your terminal and run:"
Write-Host " scoria --version"