-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
59 lines (48 loc) · 2.41 KB
/
Copy pathinstall.ps1
File metadata and controls
59 lines (48 loc) · 2.41 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
# PeekMify official installer bootstrapper.
# Usage: irm https://peekmify.github.io/install.ps1 | iex
[CmdletBinding()]
param()
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
if ([Net.ServicePointManager]::SecurityProtocol -band [Net.SecurityProtocolType]::Tls12) {
# TLS 1.2 is already available.
}
else {
[Net.ServicePointManager]::SecurityProtocol =
[Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
}
$manifestUri = 'https://peekmify.github.io/update/latest.json'
$manifest = Invoke-RestMethod -Uri $manifestUri -Headers @{ 'User-Agent' = 'PeekMify-Installer' }
if ([string]::IsNullOrWhiteSpace($manifest.installerUrl) -or
[string]::IsNullOrWhiteSpace($manifest.sha256)) {
throw 'The official update manifest is incomplete.'
}
$installerUri = [Uri]$manifest.installerUrl
if ($installerUri.Scheme -ne 'https' -or
$installerUri.Host -notin @('github.com', 'objects.githubusercontent.com')) {
throw "Installer URL is not an approved HTTPS GitHub address: $installerUri"
}
$expectedHash = ([string]$manifest.sha256).Replace('sha256:', '').Trim().ToUpperInvariant()
if ($expectedHash -notmatch '^[A-F0-9]{64}$') {
throw 'The official SHA-256 value is invalid.'
}
$tempRoot = Join-Path ([IO.Path]::GetTempPath()) ('PeekMify-' + [Guid]::NewGuid().ToString('N'))
$installerPath = Join-Path $tempRoot 'PeekMify-Setup-x64.exe'
New-Item -ItemType Directory -Path $tempRoot | Out-Null
try {
Write-Host "Downloading PeekMify $($manifest.version) from the official GitHub release..." -ForegroundColor Cyan
Invoke-WebRequest -Uri $installerUri -OutFile $installerPath -Headers @{ 'User-Agent' = 'PeekMify-Installer' }
$actualHash = (Get-FileHash -Algorithm SHA256 -LiteralPath $installerPath).Hash.ToUpperInvariant()
if ($actualHash -ne $expectedHash) {
throw "SHA-256 verification failed. Expected $expectedHash, received $actualHash."
}
Write-Host 'SHA-256 verified. Starting the installer...' -ForegroundColor Green
$process = Start-Process -FilePath $installerPath -ArgumentList '/install', '/passive', '/norestart' -Wait -PassThru
if ($process.ExitCode -notin @(0, 3010)) {
throw "PeekMify installer returned exit code $($process.ExitCode)."
}
Write-Host 'PeekMify installation completed.' -ForegroundColor Green
}
finally {
Remove-Item -LiteralPath $tempRoot -Recurse -Force -ErrorAction SilentlyContinue
}