# Installs or updates every SWAT+ tool on https://install.swat.tamu.edu for Windows: # SWAT+ Editor, SWAT+ Toolbox, QSWATPlus. # All or nothing: every installer is downloaded and the requirements are checked # before anything is installed, and the first installer that fails stops the rest. # # irm https://install.swat.tamu.edu/all.ps1 | iex & { $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $done = New-Object System.Collections.Generic.List[string] $sb = @{} function Say([string]$m) { Write-Host ''; Write-Host "### $m" -ForegroundColor Magenta } # Errors are thrown, never `exit`, which would close the window the command was pasted into. function Stop-All([string]$m) { Write-Host '' Write-Host "xx $m" -ForegroundColor Red if ($done.Count) { Write-Host 'Installed or updated before it stopped:'; $done | ForEach-Object { Write-Host " $_" } } else { Write-Host 'Nothing was installed.' } throw 'The SWAT+ install stopped.' } function Get-Installer([string]$key, [string]$url) { try { $sb[$key] = [scriptblock]::Create((Invoke-RestMethod -UseBasicParsing -Uri $url)) } catch { Stop-All "Could not download $url" } } function Install-One([string]$name, [string]$key, [hashtable]$opts) { Say $name try { & $sb[$key] @opts } catch { Stop-All "${name}: $($_.Exception.Message)" } $done.Add($name) } Get-Installer 'editor' 'https://install.swat.tamu.edu/spe.ps1' Get-Installer 'toolbox' 'https://install.swat.tamu.edu/spt.ps1' Get-Installer 'qswatplus' 'https://install.swat.tamu.edu/qsp.ps1' Say 'Checking the SWAT+ Toolbox requirements' try { & $sb['toolbox'] -Check } catch { Stop-All ('SWAT+ Toolbox cannot be installed here: ' + $_.Exception.Message) } Say 'Checking the QSWATPlus requirements' try { & $sb['qswatplus'] -Check } catch { Stop-All ('QSWATPlus cannot be installed here: ' + $_.Exception.Message) } Install-One 'SWAT+ Editor' 'editor' @{} Install-One 'SWAT+ Toolbox' 'toolbox' @{} Install-One 'QSWATPlus' 'qswatplus' @{} Say 'Summary' Write-Host 'Installed or up to date:' $done | ForEach-Object { Write-Host " $_" } }