-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
141 lines (114 loc) · 4.49 KB
/
install.ps1
File metadata and controls
141 lines (114 loc) · 4.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
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
# odd-dashboard installation script for Windows
# Downloads the appropriate binary from GitHub Releases
# Verifies checksum before installation
#Requires -Version 5.1
param(
[string]$Version = "latest",
[string]$InstallDir = "$env:LOCALAPPDATA\OddDashboard"
)
$ErrorActionPreference = "Stop"
# Configuration
$Repo = "oddessentials/odd-demonstration"
$Artifact = "odd-dashboard-windows-x64.exe"
function Write-Status {
param([string]$Message, [string]$Color = "White")
Write-Host $Message -ForegroundColor $Color
}
function Resolve-Version {
if ($Version -eq "latest") {
Write-Status "Fetching latest version..."
try {
$release = Invoke-RestMethod "https://api.github.com/repos/$Repo/releases/latest"
$script:Version = $release.tag_name -replace '^v', ''
}
catch {
Write-Status "Failed to determine latest version: $_" -Color Red
exit 1
}
}
Write-Status "Version: v$Version"
$script:BaseUrl = "https://github.com/$Repo/releases/download/v$Version"
}
function Download-AndVerify {
$tempDir = New-Item -ItemType Directory -Path ([System.IO.Path]::GetTempPath()) -Name "odd-dashboard-install-$(Get-Random)"
try {
# Download binary
Write-Status "Downloading $Artifact..."
$binaryPath = Join-Path $tempDir $Artifact
Invoke-WebRequest -Uri "$BaseUrl/$Artifact" -OutFile $binaryPath -UseBasicParsing
# Download checksums
Write-Status "Downloading checksums..."
$checksumPath = Join-Path $tempDir "SHA256SUMS"
Invoke-WebRequest -Uri "$BaseUrl/SHA256SUMS" -OutFile $checksumPath -UseBasicParsing
# Verify checksum
Write-Status "Verifying checksum..."
# Parse checksum file - exact match on filename
$checksumContent = Get-Content $checksumPath
$artifactLine = $checksumContent | Where-Object {
$_ -match "^([a-fA-F0-9]{64})\s+$([regex]::Escape($Artifact))$"
}
if (-not $artifactLine) {
Write-Status "Artifact '$Artifact' not found in SHA256SUMS" -Color Red
exit 1
}
$expected = ($artifactLine -split '\s+')[0].ToLower()
$actual = (Get-FileHash -Algorithm SHA256 $binaryPath).Hash.ToLower()
if ($expected -ne $actual) {
Write-Status "Checksum mismatch!" -Color Red
Write-Status " Expected: $expected"
Write-Status " Actual: $actual"
exit 1
}
Write-Status "Checksum verified" -Color Green
# Install
Write-Status "Installing to $InstallDir..."
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
$destPath = Join-Path $InstallDir "odd-dashboard.exe"
Move-Item $binaryPath $destPath -Force
}
finally {
# Cleanup temp directory
if (Test-Path $tempDir) {
Remove-Item $tempDir -Recurse -Force -ErrorAction SilentlyContinue
}
}
}
function Verify-Installation {
$exePath = Join-Path $InstallDir "odd-dashboard.exe"
if (Test-Path $exePath) {
Write-Status ""
Write-Status "Successfully installed odd-dashboard!" -Color Green
Write-Status ""
& $exePath --version
Write-Status ""
# Check if install dir is in PATH
$envPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($envPath -notlike "*$InstallDir*") {
Write-Status "Note: $InstallDir is not in your PATH" -Color Yellow
Write-Status ""
Write-Status "To add it, run:"
Write-Status ""
Write-Status " `$env:Path += `";$InstallDir`""
Write-Status " [Environment]::SetEnvironmentVariable('Path', `$env:Path + ';$InstallDir', 'User')"
Write-Status ""
}
Write-Status "Run 'odd-dashboard doctor' to check prerequisites."
}
else {
Write-Status "Installation failed" -Color Red
exit 1
}
}
# Main
function Main {
Write-Status "odd-dashboard installer"
Write-Status "======================="
Write-Status ""
Write-Status "Platform: windows-x64"
Resolve-Version
Download-AndVerify
Verify-Installation
}
Main