Skip to content

Commit 2b31fdc

Browse files
committed
feat: install scripts
1 parent ccede40 commit 2b31fdc

File tree

5 files changed

+571
-4
lines changed

5 files changed

+571
-4
lines changed

routes/index.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,35 @@ export default function Home() {
3636
<pre class="bg-black text-green-400 p-4 rounded-lg text-left overflow-x-auto border border-surface1">
3737
<code>cargo install --git https://github.com/tryandromeda/andromeda</code>
3838
</pre>
39+
{/* Quick Install Options */}
40+
<div class="mt-4 text-center">
41+
<p class="text-subtext1 text-sm mb-2">Or use our installation scripts:</p>
42+
<div class="flex justify-center gap-2 text-xs">
43+
<a
44+
href="/install.sh"
45+
class="text-blue hover:text-blue/80 transition-colors"
46+
download
47+
>
48+
Bash
49+
</a>
50+
<span class="text-subtext1"></span>
51+
<a
52+
href="/install.ps1"
53+
class="text-blue hover:text-blue/80 transition-colors"
54+
download
55+
>
56+
PowerShell
57+
</a>
58+
<span class="text-subtext1"></span>
59+
<a
60+
href="/install.bat"
61+
class="text-blue hover:text-blue/80 transition-colors"
62+
download
63+
>
64+
Batch
65+
</a>
66+
</div>
67+
</div>
3968
</div>{" "}
4069
<div class="mt-8 flex flex-col sm:flex-row gap-4 justify-center">
4170
<a

routes/install.bat.ts

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
export function handler(): Response {
2+
const installScript = `@echo off
3+
setlocal enabledelayedexpansion
4+
5+
REM Andromeda Installation Script for Windows (Batch)
6+
REM This script downloads and installs Andromeda on Windows systems
7+
8+
REM Configuration
9+
set "REPO=tryandromeda/andromeda"
10+
set "VERSION=0.1.0-draft"
11+
set "ASSET_NAME=andromeda-windows-amd64.exe"
12+
set "INSTALL_DIR=%USERPROFILE%\\.local\\bin"
13+
14+
REM Colors (limited in batch)
15+
set "INFO_PREFIX=[INFO]"
16+
set "SUCCESS_PREFIX=[SUCCESS]"
17+
set "ERROR_PREFIX=[ERROR]"
18+
set "WARNING_PREFIX=[WARNING]"
19+
20+
REM Check for help
21+
if "%1"=="--help" goto :show_help
22+
if "%1"=="-h" goto :show_help
23+
if "%1"=="/?" goto :show_help
24+
25+
echo %INFO_PREFIX% Installing Andromeda %VERSION% for Windows...
26+
27+
REM Construct download URL
28+
set "DOWNLOAD_URL=https://github.com/%REPO%/releases/download/%VERSION%/%ASSET_NAME%"
29+
echo %INFO_PREFIX% Download URL: !DOWNLOAD_URL!
30+
31+
REM Create install directory if it doesn't exist
32+
if not exist "%INSTALL_DIR%" (
33+
echo %INFO_PREFIX% Creating install directory: %INSTALL_DIR%
34+
mkdir "%INSTALL_DIR%" 2>nul
35+
if errorlevel 1 (
36+
echo %ERROR_PREFIX% Failed to create install directory
37+
goto :error_exit
38+
)
39+
)
40+
41+
REM Download the binary using PowerShell (available on Windows 7+)
42+
set "BINARY_PATH=%INSTALL_DIR%\\andromeda.exe"
43+
set "TEMP_FILE=%TEMP%\\andromeda_download.exe"
44+
45+
echo %INFO_PREFIX% Downloading Andromeda binary...
46+
47+
powershell -Command "& {[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%TEMP_FILE%')}" 2>nul
48+
49+
if not exist "%TEMP_FILE%" (
50+
echo %ERROR_PREFIX% Failed to download Andromeda binary
51+
echo %ERROR_PREFIX% Please check your internet connection and try again
52+
goto :error_exit
53+
)
54+
55+
REM Move to install directory
56+
move "%TEMP_FILE%" "%BINARY_PATH%" >nul 2>&1
57+
if errorlevel 1 (
58+
echo %ERROR_PREFIX% Failed to move binary to install directory
59+
del "%TEMP_FILE%" 2>nul
60+
goto :error_exit
61+
)
62+
63+
echo %SUCCESS_PREFIX% Andromeda installed to: %BINARY_PATH%
64+
65+
REM Check if install directory is in PATH
66+
echo %PATH% | find /i "%INSTALL_DIR%" >nul
67+
if errorlevel 1 (
68+
echo %WARNING_PREFIX% Install directory '%INSTALL_DIR%' is not in your PATH.
69+
echo %WARNING_PREFIX% Adding it to your user PATH environment variable...
70+
71+
REM Add to user PATH
72+
for /f "tokens=2*" %%a in ('reg query "HKCU\\Environment" /v PATH 2^>nul') do set "USER_PATH=%%b"
73+
if "!USER_PATH!"=="" (
74+
set "NEW_PATH=%INSTALL_DIR%"
75+
) else (
76+
set "NEW_PATH=!USER_PATH!;%INSTALL_DIR%"
77+
)
78+
79+
reg add "HKCU\\Environment" /v PATH /t REG_EXPAND_SZ /d "!NEW_PATH!" /f >nul 2>&1
80+
if errorlevel 1 (
81+
echo %WARNING_PREFIX% Failed to update PATH automatically.
82+
echo %WARNING_PREFIX% Please add '%INSTALL_DIR%' to your PATH manually:
83+
echo %WARNING_PREFIX% 1. Open System Properties ^> Environment Variables
84+
echo %WARNING_PREFIX% 2. Add '%INSTALL_DIR%' to your user PATH variable
85+
) else (
86+
echo %SUCCESS_PREFIX% Added '%INSTALL_DIR%' to your PATH.
87+
echo %WARNING_PREFIX% Please restart your Command Prompt for PATH changes to take effect.
88+
)
89+
)
90+
91+
REM Verify installation
92+
echo %INFO_PREFIX% Verifying installation...
93+
"%BINARY_PATH%" --version >nul 2>&1
94+
if errorlevel 1 (
95+
echo %WARNING_PREFIX% Installation completed but verification failed.
96+
echo %WARNING_PREFIX% You may need to restart your terminal.
97+
) else (
98+
echo %SUCCESS_PREFIX% Installation verified successfully!
99+
)
100+
101+
echo.
102+
echo %SUCCESS_PREFIX% Andromeda has been installed successfully!
103+
echo %INFO_PREFIX% Try running: andromeda --help
104+
echo %INFO_PREFIX% Note: You may need to restart your terminal for PATH changes to take effect.
105+
goto :end
106+
107+
:show_help
108+
echo Andromeda Installation Script for Windows
109+
echo.
110+
echo Usage: install.bat [OPTIONS]
111+
echo.
112+
echo Options:
113+
echo --help, -h, /? Show this help message
114+
echo.
115+
echo This script will download the Andromeda binary from the GitHub release
116+
echo and install it to %%USERPROFILE%%\\.local\\bin
117+
echo.
118+
echo The script will automatically add the install directory to your PATH.
119+
goto :end
120+
121+
:error_exit
122+
echo %ERROR_PREFIX% Installation failed!
123+
exit /b 1
124+
125+
:end
126+
pause
127+
`;
128+
129+
return new Response(installScript, {
130+
headers: {
131+
"Content-Type": "text/plain; charset=utf-8",
132+
"Content-Disposition": "attachment; filename=install.bat",
133+
"Cache-Control": "public, max-age=3600", // Cache for 1 hour
134+
},
135+
});
136+
}

routes/install.ps1.ts

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
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

Comments
 (0)