# Athas install script for Windows # Usage: powershell -ExecutionPolicy ByPass -c "irm https://athas.dev/install.ps1 | iex" # # Environment variables: # ATHAS_VERSION - Install a specific version (e.g., "0.4.4") $ErrorActionPreference = "Stop" $Repo = "athasdev/athas" $GitHub = "https://github.com" function Write-Info { param([string]$Message) Write-Host " > " -ForegroundColor Blue -NoNewline Write-Host $Message } function Write-Success { param([string]$Message) Write-Host " > " -ForegroundColor Green -NoNewline Write-Host $Message } function Write-Warn { param([string]$Message) Write-Host " warn: " -ForegroundColor Yellow -NoNewline Write-Host $Message } function Exit-Error { param([string]$Message) Write-Host " error: " -ForegroundColor Red -NoNewline Write-Host $Message exit 1 } # --- Detect architecture --- function Get-Arch { $arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture switch ($arch) { "X64" { return "x64" } "Arm64" { return "arm64" } default { Exit-Error "Unsupported architecture: $arch" } } } # --- Get latest version --- function Get-LatestVersion { $envVersion = $env:ATHAS_VERSION if ($envVersion) { Write-Info "Using specified version: $envVersion" return $envVersion } Write-Info "Fetching latest version..." try { # Use the redirect from /releases/latest to extract the tag $response = Invoke-WebRequest -Uri "$GitHub/$Repo/releases/latest" ` -MaximumRedirection 0 -ErrorAction SilentlyContinue -UseBasicParsing 2>$null } catch { $response = $_.Exception.Response } $redirectUrl = "" if ($response -and $response.Headers -and $response.Headers["Location"]) { $redirectUrl = $response.Headers["Location"] } elseif ($response -and $response.StatusCode -ge 300 -and $response.StatusCode -lt 400) { $redirectUrl = $response.Headers["Location"] } # Fallback: follow the redirect normally if (-not $redirectUrl) { try { $response = Invoke-WebRequest -Uri "$GitHub/$Repo/releases/latest" -UseBasicParsing $redirectUrl = $response.BaseResponse.ResponseUri.ToString() if (-not $redirectUrl) { $redirectUrl = $response.BaseResponse.RequestMessage.RequestUri.ToString() } } catch { Exit-Error "Failed to determine latest version. Set ATHAS_VERSION and try again." } } if ($redirectUrl -match "/tag/v(.+)$") { $version = $Matches[1] Write-Info "Latest version: $version" return $version } Exit-Error "Failed to parse version from: $redirectUrl. Set ATHAS_VERSION and try again." } # --- Verify checksum --- function Test-Checksum { param( [string]$FilePath, [string]$ChecksumsPath ) if (-not (Test-Path $ChecksumsPath)) { Write-Warn "Checksums file not available, skipping verification" return } $fileName = Split-Path $FilePath -Leaf $checksumLine = Get-Content $ChecksumsPath | Where-Object { $_ -match $fileName } if (-not $checksumLine) { Write-Warn "No checksum found for $fileName, skipping verification" return } $expected = ($checksumLine -split '\s+')[0] $actual = (Get-FileHash -Path $FilePath -Algorithm SHA256).Hash.ToLower() if ($expected -ne $actual) { Exit-Error "Checksum verification failed for $fileName`n Expected: $expected`n Actual: $actual" } Write-Success "Checksum verified" } # --- Main --- function Install-Athas { Write-Host "" Write-Host " Athas Installer" -ForegroundColor White Write-Host "" $arch = Get-Arch $version = Get-LatestVersion # Determine artifact $artifact = "Athas_${version}_${arch}-setup.exe" $downloadUrl = "$GitHub/$Repo/releases/download/v${version}/$artifact" $checksumsUrl = "$GitHub/$Repo/releases/download/v${version}/SHA256SUMS.txt" # Create temp directory $tmpDir = Join-Path ([System.IO.Path]::GetTempPath()) "athas-install-$([System.Guid]::NewGuid().ToString('N').Substring(0,8))" New-Item -ItemType Directory -Path $tmpDir -Force | Out-Null try { $artifactPath = Join-Path $tmpDir $artifact $checksumsPath = Join-Path $tmpDir "SHA256SUMS.txt" Write-Info "Downloading Athas $version for windows ($arch)..." Invoke-WebRequest -Uri $downloadUrl -OutFile $artifactPath -UseBasicParsing # Try to download checksums try { Invoke-WebRequest -Uri $checksumsUrl -OutFile $checksumsPath -UseBasicParsing } catch { # Checksums may not exist for older releases } Test-Checksum -FilePath $artifactPath -ChecksumsPath $checksumsPath Write-Info "Running installer..." Start-Process -FilePath $artifactPath -Wait Write-Success "Athas $version installed" Write-Info "Launch from the Start Menu or desktop shortcut" } finally { # Cleanup if (Test-Path $tmpDir) { Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue } } Write-Host "" } Install-Athas