fix: prevent install.ps1 from crashing PowerShell on error
When run via `irm ... | iex`, `exit` terminates the entire PowerShell session. Wrapped the installer in a function and replaced all `exit` calls with `return` so errors are reported cleanly without killing the terminal. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+39
-36
@@ -1,54 +1,52 @@
|
||||
# Transmute CLI installer for Windows
|
||||
# Usage: irm https://raw.githubusercontent.com/noauf/Transmute/main/install.ps1 | iex
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
function Install-Transmute {
|
||||
$REPO = "noauf/Transmute"
|
||||
$BINARY = "transmute"
|
||||
|
||||
$REPO = "noauf/Transmute"
|
||||
$BINARY = "transmute"
|
||||
Write-Host ""
|
||||
Write-Host " Transmute CLI installer"
|
||||
Write-Host " ======================"
|
||||
Write-Host ""
|
||||
|
||||
Write-Host ""
|
||||
Write-Host " Transmute CLI installer"
|
||||
Write-Host " ======================"
|
||||
Write-Host ""
|
||||
|
||||
# Detect architecture
|
||||
$ARCH = if ([System.Environment]::Is64BitOperatingSystem) {
|
||||
if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") { "arm64" } else { "x86_64" }
|
||||
} else {
|
||||
# Detect architecture
|
||||
if (-not [System.Environment]::Is64BitOperatingSystem) {
|
||||
Write-Host " Error: 32-bit Windows is not supported" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
return
|
||||
}
|
||||
$ARCH = if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") { "arm64" } else { "x86_64" }
|
||||
|
||||
Write-Host " OS: windows"
|
||||
Write-Host " Arch: $ARCH"
|
||||
Write-Host ""
|
||||
Write-Host " OS: windows"
|
||||
Write-Host " Arch: $ARCH"
|
||||
Write-Host ""
|
||||
|
||||
$ASSET = "$BINARY-windows-$ARCH.zip"
|
||||
$ASSET = "$BINARY-windows-$ARCH.zip"
|
||||
|
||||
# Get latest release tag
|
||||
Write-Host " Fetching latest release..."
|
||||
try {
|
||||
# Get latest release tag
|
||||
Write-Host " Fetching latest release..."
|
||||
try {
|
||||
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$REPO/releases/latest" -Headers @{ "User-Agent" = "transmute-installer" }
|
||||
$TAG = $release.tag_name
|
||||
} catch {
|
||||
} catch {
|
||||
Write-Host " Error: could not fetch latest release: $_" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (-not $TAG) {
|
||||
if (-not $TAG) {
|
||||
Write-Host " Error: could not determine latest release" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Write-Host " Latest version: $TAG"
|
||||
Write-Host " Latest version: $TAG"
|
||||
|
||||
$DOWNLOAD_URL = "https://github.com/$REPO/releases/download/$TAG/$ASSET"
|
||||
$DOWNLOAD_URL = "https://github.com/$REPO/releases/download/$TAG/$ASSET"
|
||||
|
||||
# Create temp directory
|
||||
$TMP_DIR = Join-Path $env:TEMP "transmute-install-$(Get-Random)"
|
||||
New-Item -ItemType Directory -Path $TMP_DIR | Out-Null
|
||||
# Create temp directory
|
||||
$TMP_DIR = Join-Path $env:TEMP "transmute-install-$(Get-Random)"
|
||||
New-Item -ItemType Directory -Path $TMP_DIR | Out-Null
|
||||
|
||||
try {
|
||||
try {
|
||||
$ZIP_PATH = Join-Path $TMP_DIR $ASSET
|
||||
|
||||
Write-Host " Downloading $ASSET..."
|
||||
@@ -65,7 +63,7 @@ try {
|
||||
|
||||
if (-not (Test-Path $EXE_SOURCE)) {
|
||||
Write-Host " Error: could not find $EXE_NAME in archive" -ForegroundColor Red
|
||||
exit 1
|
||||
return
|
||||
}
|
||||
|
||||
# Determine install directory
|
||||
@@ -76,7 +74,7 @@ try {
|
||||
Copy-Item -Path $EXE_SOURCE -Destination $INSTALL_PATH -Force
|
||||
|
||||
Write-Host ""
|
||||
Write-Host " Installed transmute $TAG to $INSTALL_PATH"
|
||||
Write-Host " Installed transmute $TAG to $INSTALL_PATH" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
|
||||
# Add to PATH if not already there
|
||||
@@ -94,6 +92,11 @@ try {
|
||||
Write-Host " transmute --help Show all options"
|
||||
Write-Host ""
|
||||
|
||||
} finally {
|
||||
} catch {
|
||||
Write-Host " Error: $_" -ForegroundColor Red
|
||||
} finally {
|
||||
Remove-Item -Recurse -Force $TMP_DIR -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
Install-Transmute
|
||||
|
||||
Reference in New Issue
Block a user