mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-04-29 04:26:59 +00:00
188 lines
6.3 KiB
PowerShell
188 lines
6.3 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" }
|
|
$TangledRepo = if ($env:ATCR_TANGLED_REPO) { $env:ATCR_TANGLED_REPO } else { "https://tangled.org/did:plc:e3kzdezk5gsirzh7eoqplc64" }
|
|
|
|
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 "x86_64" } # x64
|
|
12 { return "arm64" } # ARM64
|
|
default {
|
|
Write-Host "Unsupported architecture: $arch" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
}
|
|
|
|
$Arch = Get-Architecture
|
|
Write-Host "Detected: Windows $Arch" -ForegroundColor Green
|
|
|
|
# Resolve the latest version via the tangled /tags/latest redirect
|
|
function Get-LatestVersion {
|
|
Write-Host "Resolving latest version..." -ForegroundColor Yellow
|
|
|
|
try {
|
|
$response = Invoke-WebRequest -Uri "$TangledRepo/tags/latest" -UseBasicParsing -MaximumRedirection 0 -ErrorAction SilentlyContinue
|
|
$location = $response.Headers.Location
|
|
} catch {
|
|
# PowerShell 5 throws when -MaximumRedirection 0 receives a redirect; grab it off the exception.
|
|
$location = $_.Exception.Response.Headers.Location
|
|
if ($location) { $location = $location.ToString() }
|
|
}
|
|
|
|
if (-not $location) {
|
|
Write-Host "Failed to resolve latest version from $TangledRepo/tags/latest" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
$tag = $location.TrimEnd('/').Split('/')[-1]
|
|
if (-not $tag.StartsWith('v')) {
|
|
Write-Host "Unexpected redirect location: $location" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "Found latest version: $tag" -ForegroundColor Green
|
|
return $tag
|
|
}
|
|
|
|
# Build the download URL from version and platform
|
|
function Get-DownloadUrl {
|
|
param([string]$Version, [string]$Arch)
|
|
|
|
$versionClean = $Version.TrimStart('v')
|
|
$fileName = "docker-credential-atcr_${versionClean}_Windows_${Arch}.tar.gz"
|
|
return "$TangledRepo/tags/$Version/download/$fileName"
|
|
}
|
|
|
|
# Determine version and download URL
|
|
if ($env:ATCR_VERSION) {
|
|
$Version = $env:ATCR_VERSION
|
|
Write-Host "Using specified version: $Version" -ForegroundColor Yellow
|
|
} else {
|
|
$Version = Get-LatestVersion
|
|
}
|
|
|
|
$DownloadUrl = Get-DownloadUrl -Version $Version -Arch $Arch
|
|
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
|
|
$archivePath = Join-Path $tempDir "docker-credential-atcr.tar.gz"
|
|
|
|
try {
|
|
Invoke-WebRequest -Uri $DownloadUrl -OutFile $archivePath -UseBasicParsing
|
|
} catch {
|
|
Write-Host "Failed to download release: $_" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "Extracting..." -ForegroundColor Yellow
|
|
# Modern Windows ships tar.exe; use it to handle .tar.gz produced by goreleaser.
|
|
& tar.exe -xzf $archivePath -C $tempDir
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "Failed to extract archive" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# 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
|
|
}
|