Skip to content

Commit 2f33f3a

Browse files
committed
feat: better install
1 parent daffd49 commit 2f33f3a

File tree

4 files changed

+101
-18
lines changed

4 files changed

+101
-18
lines changed

routes/community/index.tsx

Whitespace-only changes.

routes/install.bat.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ REM This script downloads and installs Andromeda on Windows systems
77
88
REM Configuration
99
set "REPO=tryandromeda/andromeda"
10-
set "VERSION=0.1.0-draft1"
1110
set "ASSET_NAME=andromeda-windows-amd64.exe"
1211
set "INSTALL_DIR=%USERPROFILE%\\.local\\bin"
1312
@@ -22,6 +21,18 @@ if "%1"=="--help" goto :show_help
2221
if "%1"=="-h" goto :show_help
2322
if "%1"=="/?" goto :show_help
2423
24+
echo %INFO_PREFIX% Fetching latest release information...
25+
26+
REM Get latest version using PowerShell
27+
set "VERSION="
28+
for /f "delims=" %%i in ('powershell -Command "try { (Invoke-RestMethod 'https://api.github.com/repos/%REPO%/releases/latest').tag_name } catch { '' }" 2^>nul') do set "VERSION=%%i"
29+
30+
if "%VERSION%"=="" (
31+
echo %ERROR_PREFIX% Failed to fetch latest version from GitHub API
32+
echo %ERROR_PREFIX% Please check your internet connection and try again
33+
goto :error_exit
34+
)
35+
2536
echo %INFO_PREFIX% Installing Andromeda %VERSION% for Windows...
2637
2738
REM Construct download URL
@@ -112,8 +123,8 @@ echo.
112123
echo Options:
113124
echo --help, -h, /? Show this help message
114125
echo.
115-
echo This script will download the Andromeda binary from the GitHub release
116-
echo and install it to %%USERPROFILE%%\\.local\\bin
126+
echo This script will automatically fetch the latest Andromeda release
127+
echo from GitHub and install it to %%USERPROFILE%%\\.local\\bin
117128
echo.
118129
echo The script will automatically add the install directory to your PATH.
119130
goto :end

routes/install.ps1.ts

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
export function handler(): Response {
2-
const installScript = `# Andromeda Installation Script for Windows
1+
// deno-lint-ignore require-await
2+
export async function handler(): Promise<Response> {
3+
const latestVersionScript = `# Andromeda Installation Script for Windows
34
# This script downloads and installs Andromeda on Windows systems
45
56
param(
@@ -9,7 +10,6 @@ param(
910
1011
# Configuration
1112
$Repo = "tryandromeda/andromeda"
12-
$Version = "0.1.0-draft1"
1313
$AssetName = "andromeda-windows-amd64.exe"
1414
1515
# Colors for output
@@ -67,7 +67,7 @@ function Show-Help {
6767
Write-Host " .\\install.ps1 # Install to default location" -ForegroundColor $Colors.White
6868
Write-Host " .\\install.ps1 -InstallDir 'C:\\tools' # Install to custom location" -ForegroundColor $Colors.White
6969
Write-Host ""
70-
Write-Host "This script will download the Andromeda binary from the GitHub release" -ForegroundColor $Colors.White
70+
Write-Host "This script will download the latest Andromeda binary from GitHub" -ForegroundColor $Colors.White
7171
Write-Host "and install it to the specified directory." -ForegroundColor $Colors.White
7272
}
7373
@@ -76,11 +76,52 @@ function Test-Administrator {
7676
return $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
7777
}
7878
79+
function Get-LatestRelease {
80+
Write-Status "Getting latest release information..."
81+
82+
$ReleaseApiUrl = "https://api.github.com/repos/$Repo/releases/latest"
83+
$Headers = @{
84+
"Accept" = "application/vnd.github.v3+json"
85+
"User-Agent" = "Andromeda-Installer/1.0"
86+
}
87+
88+
try {
89+
$Response = Invoke-RestMethod -Uri $ReleaseApiUrl -Headers $Headers -ErrorAction Stop
90+
$Version = $Response.tag_name
91+
92+
# Find the correct asset
93+
$Asset = $Response.assets | Where-Object { $_.name -eq $AssetName }
94+
if (-not $Asset) {
95+
Write-Error "Could not find asset '$AssetName' in the latest release."
96+
exit 1
97+
}
98+
99+
return @{
100+
Version = $Version
101+
DownloadUrl = $Asset.browser_download_url
102+
}
103+
}
104+
catch {
105+
Write-Error "Failed to get latest release: $($_.Exception.Message)"
106+
Write-Warning "Falling back to direct download URL pattern..."
107+
108+
# Fallback to direct URL with latest
109+
return @{
110+
Version = "latest"
111+
DownloadUrl = "https://github.com/$Repo/releases/latest/download/$AssetName"
112+
}
113+
}
114+
}
115+
79116
function Install-Andromeda {
80-
Write-Status "Installing Andromeda $Version for Windows..."
117+
Write-Status "Preparing to install Andromeda for Windows..."
118+
119+
# Get latest release info
120+
$ReleaseInfo = Get-LatestRelease
121+
$Version = $ReleaseInfo.Version
122+
$DownloadUrl = $ReleaseInfo.DownloadUrl
81123
82-
# Construct download URL
83-
$DownloadUrl = "https://github.com/$Repo/releases/download/$Version/$AssetName"
124+
Write-Status "Installing Andromeda $Version for Windows..."
84125
Write-Status "Download URL: $DownloadUrl"
85126
86127
try {
@@ -96,10 +137,14 @@ function Install-Andromeda {
96137
97138
Write-Status "Downloading Andromeda binary..."
98139
99-
# Use System.Net.WebClient for compatibility
100-
$WebClient = New-Object System.Net.WebClient
101-
$WebClient.DownloadFile($DownloadUrl, $TempFile)
102-
$WebClient.Dispose()
140+
# Use Invoke-WebRequest for better compatibility and progress
141+
try {
142+
Invoke-WebRequest -Uri $DownloadUrl -OutFile $TempFile -ErrorAction Stop
143+
}
144+
catch {
145+
Write-Error "Failed to download Andromeda binary: $($_.Exception.Message)"
146+
throw
147+
}
103148
104149
# Move to install directory
105150
Move-Item -Path $TempFile -Destination $BinaryPath -Force
@@ -176,7 +221,7 @@ if ($ExecutionPolicy -eq "Restricted") {
176221
Install-Andromeda
177222
`;
178223

179-
return new Response(installScript, {
224+
return new Response(latestVersionScript, {
180225
headers: {
181226
"Content-Type": "text/plain; charset=utf-8",
182227
"Content-Disposition": "attachment; filename=install.ps1",

routes/install.sh.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,32 @@ NC='\\033[0m' # No Color
1515
1616
# Configuration
1717
REPO="tryandromeda/andromeda"
18-
VERSION="0.1.0-draft1"
1918
INSTALL_DIR="$HOME/.local/bin"
2019
20+
# Function to get latest release version from GitHub API
21+
get_latest_version() {
22+
local api_url="https://api.github.com/repos/$REPO/releases/latest"
23+
local version
24+
25+
print_status "Fetching latest release information..."
26+
27+
if command_exists curl; then
28+
version=$(curl -s "$api_url" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\\1/')
29+
elif command_exists wget; then
30+
version=$(wget -qO- "$api_url" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\\1/')
31+
else
32+
print_error "Neither curl nor wget is available. Cannot fetch latest version."
33+
exit 1
34+
fi
35+
36+
if [ -z "$version" ]; then
37+
print_error "Failed to fetch latest version from GitHub API"
38+
exit 1
39+
fi
40+
41+
echo "$version"
42+
}
43+
2144
# Function to print colored output
2245
print_status() {
2346
echo -e "\${BLUE}[INFO]\${NC} $1"
@@ -95,6 +118,10 @@ download_file() {
95118
96119
# Main installation function
97120
install_andromeda() {
121+
# Get the latest version
122+
local VERSION
123+
VERSION=$(get_latest_version)
124+
98125
print_status "Installing Andromeda $VERSION..."
99126
100127
# Detect platform
@@ -167,8 +194,8 @@ if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
167194
echo "Environment Variables:"
168195
echo " INSTALL_DIR Installation directory (default: \\$HOME/.local/bin)"
169196
echo ""
170-
echo "This script will automatically detect your platform and download"
171-
echo "the appropriate Andromeda binary from the GitHub release."
197+
echo "This script will automatically fetch the latest Andromeda release"
198+
echo "from GitHub and download the appropriate binary for your platform."
172199
exit 0
173200
fi
174201

0 commit comments

Comments
 (0)