mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-08-31 13:17:09 +00:00
198 lines
6.4 KiB
PowerShell
198 lines
6.4 KiB
PowerShell
# ATCR Credential Helper Installation Script for Windows
|
|
# Usage: iwr -useb https://atcr.io/install.ps1 | iex
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
# Configuration
|
|
$BinaryName = "docker-credential-atcr.exe"
|
|
$InstallDir = if ($env:ATCR_INSTALL_DIR) { $env:ATCR_INSTALL_DIR } else { "$env:ProgramFiles\ATCR" }
|
|
$ApiUrl = if ($env:ATCR_API_URL) { $env:ATCR_API_URL } else { "https://atcr.io/api/credential-helper/version" }
|
|
|
|
# Fallback configuration (used if API is unavailable)
|
|
$FallbackVersion = "v0.0.1"
|
|
$FallbackTangledRepo = "https://tangled.org/evan.jarrett.net/at-container-registry"
|
|
|
|
Write-Host "ATCR Credential Helper Installer for Windows" -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
# Detect architecture
|
|
function Get-Architecture {
|
|
$arch = (Get-WmiObject Win32_Processor).Architecture
|
|
switch ($arch) {
|
|
9 { return @{ Display = "x86_64"; Key = "amd64" } } # x64
|
|
12 { return @{ Display = "arm64"; Key = "arm64" } } # ARM64
|
|
default {
|
|
Write-Host "Unsupported architecture: $arch" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
}
|
|
|
|
$ArchInfo = Get-Architecture
|
|
$Arch = $ArchInfo.Display
|
|
$ArchKey = $ArchInfo.Key
|
|
$PlatformKey = "windows_$ArchKey"
|
|
|
|
Write-Host "Detected: Windows $Arch" -ForegroundColor Green
|
|
|
|
# Fetch version info from API
|
|
function Get-VersionInfo {
|
|
Write-Host "Fetching latest version info..." -ForegroundColor Yellow
|
|
|
|
try {
|
|
$response = Invoke-WebRequest -Uri $ApiUrl -UseBasicParsing -TimeoutSec 10
|
|
$json = $response.Content | ConvertFrom-Json
|
|
|
|
if ($json.latest -and $json.download_urls.$PlatformKey) {
|
|
return @{
|
|
Version = $json.latest
|
|
DownloadUrl = $json.download_urls.$PlatformKey
|
|
}
|
|
}
|
|
} catch {
|
|
Write-Host "API unavailable, using fallback version" -ForegroundColor Yellow
|
|
}
|
|
|
|
return $null
|
|
}
|
|
|
|
# Get download URL for fallback
|
|
function Get-FallbackUrl {
|
|
param([string]$Version, [string]$Arch)
|
|
|
|
$versionClean = $Version.TrimStart('v')
|
|
# Note: Windows builds use .zip format
|
|
$fileName = "docker-credential-atcr_${versionClean}_Windows_${Arch}.zip"
|
|
return "$FallbackTangledRepo/tags/$Version/download/$fileName"
|
|
}
|
|
|
|
# Determine version and download URL
|
|
$Version = $null
|
|
$DownloadUrl = $null
|
|
|
|
if ($env:ATCR_VERSION) {
|
|
$Version = $env:ATCR_VERSION
|
|
$DownloadUrl = Get-FallbackUrl -Version $Version -Arch $Arch
|
|
Write-Host "Using specified version: $Version" -ForegroundColor Yellow
|
|
} else {
|
|
$versionInfo = Get-VersionInfo
|
|
|
|
if ($versionInfo) {
|
|
$Version = $versionInfo.Version
|
|
$DownloadUrl = $versionInfo.DownloadUrl
|
|
Write-Host "Found latest version: $Version" -ForegroundColor Green
|
|
} else {
|
|
$Version = $FallbackVersion
|
|
$DownloadUrl = Get-FallbackUrl -Version $Version -Arch $Arch
|
|
Write-Host "Using fallback version: $Version" -ForegroundColor Yellow
|
|
}
|
|
}
|
|
|
|
Write-Host "Installing version: $Version" -ForegroundColor Green
|
|
|
|
# Download and install binary
|
|
function Install-Binary {
|
|
param (
|
|
[string]$DownloadUrl
|
|
)
|
|
|
|
Write-Host "Downloading from: $DownloadUrl" -ForegroundColor Yellow
|
|
|
|
$tempDir = New-Item -ItemType Directory -Path "$env:TEMP\atcr-install-$(Get-Random)" -Force
|
|
$zipPath = Join-Path $tempDir "docker-credential-atcr.zip"
|
|
|
|
try {
|
|
Invoke-WebRequest -Uri $DownloadUrl -OutFile $zipPath -UseBasicParsing
|
|
} catch {
|
|
Write-Host "Failed to download release: $_" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "Extracting..." -ForegroundColor Yellow
|
|
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
|
|
|
|
# Create install directory
|
|
if (-not (Test-Path $InstallDir)) {
|
|
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
|
|
}
|
|
|
|
# Install binary
|
|
$binaryPath = Join-Path $tempDir $BinaryName
|
|
$destPath = Join-Path $InstallDir $BinaryName
|
|
|
|
Copy-Item -Path $binaryPath -Destination $destPath -Force
|
|
|
|
# Clean up
|
|
Remove-Item -Path $tempDir -Recurse -Force
|
|
|
|
Write-Host "Installed $BinaryName to $InstallDir" -ForegroundColor Green
|
|
}
|
|
|
|
# Add to PATH if not already present
|
|
function Add-ToPath {
|
|
$currentPath = [Environment]::GetEnvironmentVariable("Path", "Machine")
|
|
|
|
if ($currentPath -notlike "*$InstallDir*") {
|
|
Write-Host "Adding $InstallDir to system PATH..." -ForegroundColor Yellow
|
|
|
|
# Check if running as administrator
|
|
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
|
|
|
if ($isAdmin) {
|
|
[Environment]::SetEnvironmentVariable("Path", "$currentPath;$InstallDir", "Machine")
|
|
$env:Path = "$env:Path;$InstallDir"
|
|
Write-Host "Added to PATH successfully" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "WARNING: Not running as administrator. Cannot update system PATH." -ForegroundColor Yellow
|
|
Write-Host "Please add $InstallDir to your PATH manually or re-run as administrator." -ForegroundColor Yellow
|
|
}
|
|
}
|
|
}
|
|
|
|
# Verify installation
|
|
function Test-Installation {
|
|
$binaryPath = Join-Path $InstallDir $BinaryName
|
|
|
|
if (Test-Path $binaryPath) {
|
|
Write-Host "Verification successful!" -ForegroundColor Green
|
|
|
|
# Try to run version command
|
|
try {
|
|
& $binaryPath version
|
|
} catch {
|
|
Write-Host "Binary installed but PATH may need to be refreshed." -ForegroundColor Yellow
|
|
Write-Host "Please restart your terminal or run: refreshenv" -ForegroundColor Yellow
|
|
}
|
|
} else {
|
|
Write-Host "Installation failed: binary not found at $binaryPath" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
# Show configuration instructions
|
|
function Show-Configuration {
|
|
Write-Host ""
|
|
Write-Host "Installation complete!" -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host "To use ATCR with Docker, configure Docker to use this credential helper:" -ForegroundColor Yellow
|
|
Write-Host ' Edit %USERPROFILE%\.docker\config.json and add:'
|
|
Write-Host ' {
|
|
"credHelpers": {
|
|
"atcr.io": "atcr"
|
|
}
|
|
}'
|
|
Write-Host ""
|
|
Write-Host "Note: You may need to restart your terminal for PATH changes to take effect." -ForegroundColor Yellow
|
|
}
|
|
|
|
# Main installation flow
|
|
try {
|
|
Install-Binary -DownloadUrl $DownloadUrl
|
|
Add-ToPath
|
|
Test-Installation
|
|
Show-Configuration
|
|
} catch {
|
|
Write-Host "Installation failed: $_" -ForegroundColor Red
|
|
exit 1
|
|
}
|