# nui-devtools installer, served by deploy/serve.ts. Run: irm https://nui.cykel-holdet.dk | iex # Downloads %LOCALAPPDATA%\nui-devtools\nui-devtools.exe when it's missing or its hash differs from the server's # /version, then starts it. Re-running the one-liner is how you update + launch. # Wrapped in a script block so `return` never closes the caller's shell (this runs via iex). & { $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' # the Windows PowerShell 5.1 progress bar makes downloads crawl # Old .NET defaults lack TLS 1.2: add it, but leave SystemDefault (0) alone — OR-ing into 0 would pin TLS 1.2 only. if ([Net.ServicePointManager]::SecurityProtocol -ne 'SystemDefault') { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 } $base = 'https://nui.cykel-holdet.dk' $dir = Join-Path $env:LOCALAPPDATA 'nui-devtools' $exe = Join-Path $dir 'nui-devtools.exe' New-Item -ItemType Directory -Force $dir | Out-Null Remove-Item "$exe.old" -ErrorAction SilentlyContinue # left by the last update; still locked if that one is running $remote = "$(Invoke-RestMethod "$base/version")".Trim() if (-not (Test-Path $exe) -or (Get-FileHash $exe -Algorithm SHA256).Hash.ToLower() -ne $remote) { Write-Host ' Downloading nui-devtools...' $tmp = "$exe.download" # Cache-bust by version hash: a new build = a new URL = a guaranteed-fresh fetch through any CDN # (Cloudflare edge-caches .exe by default; the bare URL can serve a stale binary after a deploy). Invoke-WebRequest "$base/nui-devtools.exe?v=$remote" -OutFile $tmp -UseBasicParsing if ((Get-FileHash $tmp -Algorithm SHA256).Hash.ToLower() -ne $remote) { Remove-Item $tmp Write-Host ' Download was corrupted (hash mismatch) - run the installer again.' -ForegroundColor Red return } # A running exe can't be overwritten but can be renamed: move it aside, then swap the new one in. try { if (Test-Path $exe) { Move-Item -Force $exe "$exe.old" } Move-Item $tmp $exe } catch { Remove-Item $tmp -ErrorAction SilentlyContinue Write-Host " Couldn't replace nui-devtools.exe: $_" -ForegroundColor Red return } } & $exe }