|
| 1 | +export function handler(): Response { |
| 2 | + const installScript = `# Andromeda Installation Script for Windows |
| 3 | +# This script downloads and installs Andromeda on Windows systems |
| 4 | +
|
| 5 | +param( |
| 6 | + [string]$InstallDir = "$env:USERPROFILE\\.local\\bin", |
| 7 | + [switch]$Help |
| 8 | +) |
| 9 | +
|
| 10 | +# Configuration |
| 11 | +$Repo = "tryandromeda/andromeda" |
| 12 | +$Version = "0.1.0-draft" |
| 13 | +$AssetName = "andromeda-windows-amd64.exe" |
| 14 | +
|
| 15 | +# Colors for output |
| 16 | +$Colors = @{ |
| 17 | + Red = [System.ConsoleColor]::Red |
| 18 | + Green = [System.ConsoleColor]::Green |
| 19 | + Yellow = [System.ConsoleColor]::Yellow |
| 20 | + Blue = [System.ConsoleColor]::Blue |
| 21 | + White = [System.ConsoleColor]::White |
| 22 | +} |
| 23 | +
|
| 24 | +function Write-ColoredOutput { |
| 25 | + param( |
| 26 | + [string]$Message, |
| 27 | + [System.ConsoleColor]$Color = $Colors.White, |
| 28 | + [string]$Prefix = "" |
| 29 | + ) |
| 30 | + |
| 31 | + if ($Prefix) { |
| 32 | + Write-Host "[$Prefix] " -ForegroundColor $Color -NoNewline |
| 33 | + } |
| 34 | + Write-Host $Message -ForegroundColor $Color |
| 35 | +} |
| 36 | +
|
| 37 | +function Write-Status { |
| 38 | + param([string]$Message) |
| 39 | + Write-ColoredOutput -Message $Message -Color $Colors.Blue -Prefix "INFO" |
| 40 | +} |
| 41 | +
|
| 42 | +function Write-Success { |
| 43 | + param([string]$Message) |
| 44 | + Write-ColoredOutput -Message $Message -Color $Colors.Green -Prefix "SUCCESS" |
| 45 | +} |
| 46 | +
|
| 47 | +function Write-Error { |
| 48 | + param([string]$Message) |
| 49 | + Write-ColoredOutput -Message $Message -Color $Colors.Red -Prefix "ERROR" |
| 50 | +} |
| 51 | +
|
| 52 | +function Write-Warning { |
| 53 | + param([string]$Message) |
| 54 | + Write-ColoredOutput -Message $Message -Color $Colors.Yellow -Prefix "WARNING" |
| 55 | +} |
| 56 | +
|
| 57 | +function Show-Help { |
| 58 | + Write-Host "Andromeda Installation Script for Windows" -ForegroundColor $Colors.Blue |
| 59 | + Write-Host "" |
| 60 | + Write-Host "Usage: .\\install.ps1 [OPTIONS]" -ForegroundColor $Colors.White |
| 61 | + Write-Host "" |
| 62 | + Write-Host "Options:" -ForegroundColor $Colors.White |
| 63 | + Write-Host " -InstallDir <path> Installation directory (default: %USERPROFILE%\\.local\\bin)" -ForegroundColor $Colors.White |
| 64 | + Write-Host " -Help Show this help message" -ForegroundColor $Colors.White |
| 65 | + Write-Host "" |
| 66 | + Write-Host "Examples:" -ForegroundColor $Colors.White |
| 67 | + Write-Host " .\\install.ps1 # Install to default location" -ForegroundColor $Colors.White |
| 68 | + Write-Host " .\\install.ps1 -InstallDir 'C:\\tools' # Install to custom location" -ForegroundColor $Colors.White |
| 69 | + Write-Host "" |
| 70 | + Write-Host "This script will download the Andromeda binary from the GitHub release" -ForegroundColor $Colors.White |
| 71 | + Write-Host "and install it to the specified directory." -ForegroundColor $Colors.White |
| 72 | +} |
| 73 | +
|
| 74 | +function Test-Administrator { |
| 75 | + $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) |
| 76 | + return $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) |
| 77 | +} |
| 78 | +
|
| 79 | +function Install-Andromeda { |
| 80 | + Write-Status "Installing Andromeda $Version for Windows..." |
| 81 | + |
| 82 | + # Construct download URL |
| 83 | + $DownloadUrl = "https://github.com/$Repo/releases/download/$Version/$AssetName" |
| 84 | + Write-Status "Download URL: $DownloadUrl" |
| 85 | + |
| 86 | + try { |
| 87 | + # Create install directory if it doesn't exist |
| 88 | + if (-not (Test-Path $InstallDir)) { |
| 89 | + Write-Status "Creating install directory: $InstallDir" |
| 90 | + New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null |
| 91 | + } |
| 92 | + |
| 93 | + # Download the binary |
| 94 | + $TempFile = [System.IO.Path]::GetTempFileName() |
| 95 | + $BinaryPath = Join-Path $InstallDir "andromeda.exe" |
| 96 | + |
| 97 | + Write-Status "Downloading Andromeda binary..." |
| 98 | + |
| 99 | + # Use System.Net.WebClient for compatibility |
| 100 | + $WebClient = New-Object System.Net.WebClient |
| 101 | + $WebClient.DownloadFile($DownloadUrl, $TempFile) |
| 102 | + $WebClient.Dispose() |
| 103 | + |
| 104 | + # Move to install directory |
| 105 | + Move-Item -Path $TempFile -Destination $BinaryPath -Force |
| 106 | + |
| 107 | + Write-Success "Andromeda installed to: $BinaryPath" |
| 108 | + |
| 109 | + # Check if install directory is in PATH |
| 110 | + $CurrentPath = [Environment]::GetEnvironmentVariable("PATH", "User") |
| 111 | + if ($CurrentPath -notlike "*$InstallDir*") { |
| 112 | + Write-Warning "Install directory '$InstallDir' is not in your PATH." |
| 113 | + Write-Warning "Adding it to your user PATH environment variable..." |
| 114 | + |
| 115 | + try { |
| 116 | + $NewPath = if ($CurrentPath) { "$CurrentPath;$InstallDir" } else { $InstallDir } |
| 117 | + [Environment]::SetEnvironmentVariable("PATH", $NewPath, "User") |
| 118 | + Write-Success "Added '$InstallDir' to your PATH." |
| 119 | + Write-Warning "Please restart your PowerShell/Command Prompt for PATH changes to take effect." |
| 120 | + } |
| 121 | + catch { |
| 122 | + Write-Warning "Failed to update PATH automatically. Please add '$InstallDir' to your PATH manually:" |
| 123 | + Write-Host "1. Open System Properties > Environment Variables" -ForegroundColor $Colors.Yellow |
| 124 | + Write-Host "2. Add '$InstallDir' to your user PATH variable" -ForegroundColor $Colors.Yellow |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + # Verify installation |
| 129 | + Write-Status "Verifying installation..." |
| 130 | + try { |
| 131 | + $VersionOutput = & $BinaryPath --version 2>$null |
| 132 | + if ($LASTEXITCODE -eq 0) { |
| 133 | + Write-Success "Installation verified successfully!" |
| 134 | + Write-Status "Version: $VersionOutput" |
| 135 | + } else { |
| 136 | + Write-Warning "Installation completed but version check failed." |
| 137 | + } |
| 138 | + } |
| 139 | + catch { |
| 140 | + Write-Warning "Installation completed but verification failed." |
| 141 | + } |
| 142 | + |
| 143 | + Write-Host "" |
| 144 | + Write-Success "Andromeda has been installed successfully!" |
| 145 | + Write-Status "Try running: andromeda --help" |
| 146 | + Write-Status "Note: You may need to restart your terminal for PATH changes to take effect." |
| 147 | + |
| 148 | + } |
| 149 | + catch { |
| 150 | + Write-Error "Installation failed: $($_.Exception.Message)" |
| 151 | + |
| 152 | + # Clean up temporary file if it exists |
| 153 | + if (Test-Path $TempFile) { |
| 154 | + Remove-Item $TempFile -Force -ErrorAction SilentlyContinue |
| 155 | + } |
| 156 | + |
| 157 | + exit 1 |
| 158 | + } |
| 159 | +} |
| 160 | +
|
| 161 | +# Show help if requested |
| 162 | +if ($Help) { |
| 163 | + Show-Help |
| 164 | + exit 0 |
| 165 | +} |
| 166 | +
|
| 167 | +# Check PowerShell execution policy |
| 168 | +$ExecutionPolicy = Get-ExecutionPolicy |
| 169 | +if ($ExecutionPolicy -eq "Restricted") { |
| 170 | + Write-Warning "PowerShell execution policy is set to 'Restricted'." |
| 171 | + Write-Warning "You may need to run: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser" |
| 172 | + Write-Warning "Or run this script with: powershell -ExecutionPolicy Bypass -File install.ps1" |
| 173 | +} |
| 174 | +
|
| 175 | +# Run installation |
| 176 | +Install-Andromeda |
| 177 | +`; |
| 178 | + |
| 179 | + return new Response(installScript, { |
| 180 | + headers: { |
| 181 | + "Content-Type": "text/plain; charset=utf-8", |
| 182 | + "Content-Disposition": "attachment; filename=install.ps1", |
| 183 | + "Cache-Control": "public, max-age=3600", // Cache for 1 hour |
| 184 | + }, |
| 185 | + }); |
| 186 | +} |
0 commit comments