-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
147 lines (118 loc) · 4.44 KB
/
install.ps1
File metadata and controls
147 lines (118 loc) · 4.44 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#Requires -Version 5.1
<#
.SYNOPSIS
Install mdproof on Windows
.DESCRIPTION
Downloads and installs the latest mdproof release from GitHub
.EXAMPLE
irm https://raw.githubusercontent.com/runkids/mdproof/main/install.ps1 | iex
#>
$ErrorActionPreference = "Stop"
# PowerShell 5.1 defaults to TLS 1.0/1.1; GitHub requires TLS 1.2+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$Repo = "runkids/mdproof"
$BinaryName = "mdproof"
function Write-Info { param($Message) Write-Host $Message -ForegroundColor Green }
function Write-Warn { param($Message) Write-Host $Message -ForegroundColor Yellow }
function Write-Err { param($Message) Write-Host $Message -ForegroundColor Red; exit 1 }
# Detect architecture
function Get-Arch {
$arch = $env:PROCESSOR_ARCHITECTURE
switch ($arch) {
"AMD64" { return "amd64" }
"ARM64" { return "arm64" }
default { Write-Err "Unsupported architecture: $arch" }
}
}
# Get latest version using redirect (avoids API rate limit)
function Get-LatestVersion {
try {
$response = Invoke-WebRequest -Uri "https://github.com/$Repo/releases/latest" `
-MaximumRedirection 0 -UseBasicParsing -ErrorAction SilentlyContinue
} catch {
# PowerShell 5.1 throws on 3xx redirects; extract from the exception
$response = $_.Exception.Response
}
$location = ""
if ($response -and $response.Headers -and $response.Headers["Location"]) {
$location = $response.Headers["Location"]
}
if ($location -match "/tag/([^/\s]+)") {
return $Matches[1]
}
# Fallback to API if redirect fails
try {
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
return $release.tag_name
} catch {
Write-Err "Failed to get latest version. Please check your internet connection."
}
}
# Get install directory
function Get-InstallDir {
$dir = "$env:LOCALAPPDATA\Programs\mdproof"
if (-not (Test-Path $dir)) {
New-Item -ItemType Directory -Path $dir -Force | Out-Null
}
return $dir
}
# Add to PATH if not already present
function Add-ToPath {
param($Dir)
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($currentPath -notlike "*$Dir*") {
Write-Info "Adding $Dir to PATH..."
[Environment]::SetEnvironmentVariable("Path", "$currentPath;$Dir", "User")
$env:Path = "$env:Path;$Dir"
return $true
}
return $false
}
function Install-Mdproof {
Write-Info "Installing mdproof..."
Write-Host ""
$arch = Get-Arch
$version = Get-LatestVersion
$installDir = Get-InstallDir
# Release artifact: mdproof-v1.2.3-windows-amd64.zip
$url = "https://github.com/$Repo/releases/download/$version/${BinaryName}-${version}-windows-${arch}.zip"
Write-Info "Downloading mdproof $version for windows/$arch..."
# Create temp directory
$tempDir = Join-Path $env:TEMP "mdproof-install-$(Get-Random)"
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
try {
$zipPath = Join-Path $tempDir "mdproof.zip"
# Download
Invoke-WebRequest -Uri $url -OutFile $zipPath -UseBasicParsing
# Extract
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
# Find the binary (named mdproof-vX.Y.Z-windows-amd64.exe)
$exePath = Get-ChildItem -Path $tempDir -Filter "$BinaryName-*.exe" | Select-Object -First 1
if (-not $exePath) {
Write-Err "Binary not found in archive"
}
$destPath = Join-Path $installDir "$BinaryName.exe"
Move-Item -Path $exePath.FullName -Destination $destPath -Force
# Add to PATH
$pathAdded = Add-ToPath -Dir $installDir
Write-Host ""
Write-Info "Successfully installed mdproof to $destPath"
Write-Host ""
# Show version
& $destPath --version
Write-Host ""
if ($pathAdded) {
Write-Warn "PATH updated. Restart your terminal for changes to take effect."
Write-Host ""
}
Write-Info "Get started:"
Write-Info " mdproof --help"
Write-Host ""
Write-Warn "Note: Sandbox mode and jq assertions require WSL2 or Docker Desktop."
Write-Warn " https://learn.microsoft.com/en-us/windows/wsl/install"
} finally {
# Cleanup
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
}
}
Install-Mdproof