# Installs or updates GOAT on Windows: # irm https://qoleton.dev/chat/install.ps1 | iex & { $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' # Invoke-WebRequest is far slower with the progress bar [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $Updates = 'https://goat.joshuabissett.com/updates' $Exe = Join-Path $env:LOCALAPPDATA 'Programs\goat-desktop\GOAT.exe' function Open-Goat { if (Get-Process GOAT -ErrorAction SilentlyContinue) { Write-Host ' GOAT is already open.' } else { Start-Process $Exe } } Write-Host '' Write-Host ' Setting up GOAT' -ForegroundColor Cyan Write-Host '' $latest = (Invoke-WebRequest "$Updates/latest.yml" -UseBasicParsing).Content if ($latest -is [byte[]]) { $latest = [Text.Encoding]::UTF8.GetString($latest) } $version = [regex]::Match($latest, '(?m)^version:\s*(\S+)').Groups[1].Value $file = [regex]::Match($latest, '(?m)^path:\s*(\S+)').Groups[1].Value $sha512 = [regex]::Match($latest, '(?m)^sha512:\s*(\S+)').Groups[1].Value if (-not $version -or -not $file -or -not $sha512) { throw "Couldn't read the latest GOAT version." } # Windows reports four-part versions (0.2.38.0), and the installed copy may be newer than latest.yml. if ((Test-Path $Exe) -and [version](Get-Item $Exe).VersionInfo.ProductVersion -ge [version]$version) { Write-Host " GOAT is already up to date." Open-Goat Write-Host '' return } $setup = Join-Path $env:TEMP $file try { Write-Host " Downloading GOAT $version (about 140 MB)..." Invoke-WebRequest "$Updates/$file" -OutFile $setup -UseBasicParsing $stream = [IO.File]::OpenRead($setup) try { $hasher = [Security.Cryptography.SHA512]::Create() $actual = [Convert]::ToBase64String($hasher.ComputeHash($stream)) } finally { $stream.Dispose() } if ($actual -ne $sha512) { throw 'The download was damaged, so nothing was installed. Run this again to retry.' } if (Get-Process GOAT -ErrorAction SilentlyContinue) { Write-Host ' Closing GOAT so it can update...' Stop-Process -Name GOAT -Force Start-Sleep 2 } Write-Host ' Installing...' $process = Start-Process $setup -ArgumentList '/S' -PassThru -Wait if ($process.ExitCode -ne 0) { throw "The installer stopped with error $($process.ExitCode)." } } finally { Remove-Item $setup -ErrorAction SilentlyContinue } if (-not (Test-Path $Exe)) { throw "GOAT didn't finish installing (no $Exe)." } Write-Host '' Write-Host ' Done! GOAT is in your Start menu and updates itself from now on.' -ForegroundColor Green Write-Host '' Open-Goat }