File size: 3,571 Bytes
19b2935
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Arx installer for Windows 10/11 (64-bit). In PowerShell:
#     irm https://devseis-arx.static.hf.space/install.ps1 | iex
# Downloads the current Arx release from Hugging Face (Devseis/endpoint-auditor-releases), checks its SHA-256 against the
# published SHA256SUMS, installs it for this user (no administrator rights needed) and opens it. A file downloaded by
# PowerShell is not marked as coming from the internet, so SmartScreen does not stop it.
# Uninstall: Settings > Apps > Installed apps > Arx > Uninstall.
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'   # much faster downloads in Windows PowerShell 5.1
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
$Releases = 'https://huggingface.co/datasets/Devseis/endpoint-auditor-releases/resolve/main'

function Step($Text) { Write-Host '> ' -ForegroundColor Red -NoNewline; Write-Host $Text }
function Fail($Text) { Write-Host "Arx install stopped: $Text" -ForegroundColor Red; throw "Arx install stopped" }

try {
    if (-not [Environment]::Is64BitOperatingSystem) { Fail 'Arx needs 64-bit Windows 10 or 11.' }
    Write-Host 'Installing Arx - free security audit for your computer' -ForegroundColor White
    Step 'finding the current version'
    $sums = (Invoke-WebRequest -UseBasicParsing "$Releases/SHA256SUMS").Content
    if ($sums -is [byte[]]) { $sums = [Text.Encoding]::UTF8.GetString($sums) }
    $version = (Invoke-RestMethod -UseBasicParsing "$Releases/latest.json").version
    if (-not $version) { Fail 'could not read the current version.' }
    $file = "Arx-$version-windows-x64-setup.exe"
    $want = ($sums -split "`n" | Where-Object { ($_ -split '\s+')[1] -eq $file } | ForEach-Object { ($_ -split '\s+')[0] }) | Select-Object -First 1
    if (-not $want) { Fail "$file is not in SHA256SUMS." }

    $tmp = Join-Path $env:TEMP "arx-install-$([guid]::NewGuid().ToString('N'))"
    New-Item -ItemType Directory -Path $tmp | Out-Null
    $exe = Join-Path $tmp $file
    Step "downloading $file"
    Invoke-WebRequest -UseBasicParsing "$Releases/$file" -OutFile $exe
    $got = (Get-FileHash -Algorithm SHA256 $exe).Hash.ToLower()
    if ($got -ne $want.ToLower()) { Fail "the download does not match the published checksum (expected $want, got $got). Nothing was installed." }
    Step "checksum OK ($want)"
    try { Unblock-File $exe } catch { }   # not needed for a PowerShell download; harmless where it applies

    Get-Process -Name 'Arx' -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
    Step 'installing for this user (no administrator rights needed)'
    $p = Start-Process -FilePath $exe -ArgumentList '/S' -Wait -PassThru
    if ($p.ExitCode -ne 0) { Fail "the installer ended with code $($p.ExitCode)." }
    Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue

    $app = Join-Path $env:LOCALAPPDATA 'Programs\Arx\Arx.exe'
    if (-not (Test-Path $app)) { $app = (Get-ChildItem "$env:LOCALAPPDATA\Programs" -Recurse -Filter 'Arx.exe' -ErrorAction SilentlyContinue | Select-Object -First 1).FullName }
    Step "installed Arx $version"
    if ($app) { Start-Process $app; Write-Host 'Done. Arx is open. Next time, open Arx from the Start menu or the desktop shortcut.' -ForegroundColor White }
    else { Write-Host 'Done. Open Arx from the Start menu.' -ForegroundColor White }
} catch {
    if ($_.Exception.Message -ne 'Arx install stopped') { Write-Host "Arx install stopped: $($_.Exception.Message)" -ForegroundColor Red }
}