# GoatCMS installer for Windows # Auto-detects CPU architecture, downloads the matching binary, installs it, # and adds the install directory to the system PATH. # # Usage (one-liner): # iwr -useb https://goatcms.com/dist/install.ps1 | iex # # Usage (with parameters): # .\install.ps1 -Version 0.0.1 -InstallDir "C:\Tools\GoatCMS" [CmdletBinding()] param( [string]$Version = "latest", [string]$InstallDir = "$env:ProgramFiles\GoatCMS" ) $ErrorActionPreference = "Stop" # --- Detect architecture ------------------------------------------------ $archRaw = $env:PROCESSOR_ARCHITECTURE if ($env:PROCESSOR_ARCHITEW6432) { $archRaw = $env:PROCESSOR_ARCHITEW6432 } switch ($archRaw.ToUpper()) { "AMD64" { $arch = "amd64" } "ARM64" { $arch = "arm64" } default { throw "Unsupported architecture: $archRaw" } } # --- Resolve base URL --------------------------------------------------- if ($Version -eq "latest") { $base = "https://goatcms.com/dist/latest" } else { $base = "https://goatcms.com/dist/$Version" } Write-Host "Detected: OS=windows ARCH=$arch" Write-Host "Installing from $base -> $InstallDir" # --- Download ----------------------------------------------------------- $tmp = Join-Path $env:TEMP "goat-install" New-Item -ItemType Directory -Force -Path $tmp | Out-Null if ($Version -eq "latest") { $url = "$base/bin/goat_windows_${arch}.exe" $bin = Join-Path $tmp "goat.exe" Invoke-WebRequest -Uri $url -OutFile $bin } else { $url = "$base/archives/goat_${Version}_windows_${arch}.zip" $zip = Join-Path $tmp "goat.zip" Invoke-WebRequest -Uri $url -OutFile $zip Expand-Archive -Path $zip -DestinationPath $tmp -Force $found = Get-ChildItem -Path $tmp -Recurse -Filter "goat.exe" | Select-Object -First 1 if (-not $found) { throw "goat.exe not found in archive" } $bin = $found.FullName } # --- Install ------------------------------------------------------------ New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null $dest = Join-Path $InstallDir "goat.exe" Copy-Item -Path $bin -Destination $dest -Force # --- Add to system PATH ------------------------------------------------- $machinePath = [Environment]::GetEnvironmentVariable("Path", "Machine") if ($machinePath -notlike "*$InstallDir*") { [Environment]::SetEnvironmentVariable("Path", "$machinePath;$InstallDir", "Machine") Write-Host "Added $InstallDir to system PATH" } $env:Path += ";$InstallDir" # --- Verify ------------------------------------------------------------- Write-Host "Done. Verifying:" & $dest version Write-Host "" Write-Host "Open a new terminal to use 'goat' from anywhere."