-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
64 lines (54 loc) · 2.42 KB
/
Copy pathinstall.ps1
File metadata and controls
64 lines (54 loc) · 2.42 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
$ErrorActionPreference = "Stop"
$repo = "TRC-Loop/CColon"
$binaryName = "ccolon.exe"
$installDir = "$env:LOCALAPPDATA\CColon"
$arch = if ([Environment]::Is64BitOperatingSystem) { "amd64" } else {
Write-Error "CColon requires a 64-bit system."
exit 1
}
if ($args.Count -gt 0) {
$version = $args[0]
} else {
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/releases/latest" -Headers @{ "User-Agent" = "CColon-Installer" }
$version = $release.tag_name
}
$asset = "ccolon-windows-$arch.exe"
$url = "https://github.com/$repo/releases/download/$version/$asset"
$checksumsUrl = "https://github.com/$repo/releases/download/$version/checksums.txt"
Write-Host "Downloading CColon $version..."
if (-not (Test-Path $installDir)) {
New-Item -ItemType Directory -Path $installDir -Force | Out-Null
}
$outPath = Join-Path $installDir $binaryName
Invoke-WebRequest -Uri $url -OutFile $outPath -UseBasicParsing
# Verify SHA256 checksum
Write-Host "Verifying checksum..."
try {
$checksumsPath = Join-Path $env:TEMP "ccolon_checksums.txt"
Invoke-WebRequest -Uri $checksumsUrl -OutFile $checksumsPath -UseBasicParsing
$checksumContent = Get-Content $checksumsPath
$expectedLine = $checksumContent | Where-Object { $_ -match $asset }
if ($expectedLine) {
$expectedHash = ($expectedLine -split '\s+')[0]
$actualHash = (Get-FileHash -Path $outPath -Algorithm SHA256).Hash.ToLower()
if ($expectedHash -ne $actualHash) {
Write-Error "Checksum verification FAILED!`n Expected: $expectedHash`n Got: $actualHash"
Remove-Item $outPath -Force
Remove-Item $checksumsPath -Force -ErrorAction SilentlyContinue
exit 1
}
Write-Host "Checksum verified OK."
} else {
Write-Host "Warning: asset not found in checksums.txt, skipping verification."
}
Remove-Item $checksumsPath -Force -ErrorAction SilentlyContinue
} catch {
Write-Host "Warning: checksums.txt not available for this release, skipping verification."
}
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($currentPath -notlike "*$installDir*") {
[Environment]::SetEnvironmentVariable("Path", "$currentPath;$installDir", "User")
Write-Host "Added $installDir to your PATH. Restart your terminal for changes to take effect."
}
Write-Host "CColon $version installed to $outPath"
Write-Host "Run 'ccolon' to start the interactive shell."