mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-04-22 01:10:36 +00:00
150 lines
4.8 KiB
PowerShell
150 lines
4.8 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" }
|
|
$Version = "v0.0.1"
|
|
$TagHash = "c6cfbaf1723123907f9d23e300f6f72081e65006"
|
|
$TangledRepo = "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 "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
|
|
|
|
|
|
if ($env:ATCR_VERSION) {
|
|
$Version = $env:ATCR_VERSION
|
|
Write-Host "Using specified version: $Version" -ForegroundColor Yellow
|
|
} else {
|
|
Write-Host "Using version: $Version" -ForegroundColor Green
|
|
}
|
|
|
|
# Download and install binary
|
|
function Install-Binary {
|
|
param (
|
|
[string]$Version,
|
|
[string]$Arch
|
|
)
|
|
|
|
$versionClean = $Version.TrimStart('v')
|
|
$fileName = "docker-credential-atcr_${versionClean}_Windows_${Arch}.zip"
|
|
$downloadUrl = "$TangledRepo/tags/$TagHash/download/$fileName"
|
|
|
|
Write-Host "Downloading from: $downloadUrl" -ForegroundColor Yellow
|
|
|
|
$tempDir = New-Item -ItemType Directory -Path "$env:TEMP\atcr-install-$(Get-Random)" -Force
|
|
$zipPath = Join-Path $tempDir $fileName
|
|
|
|
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 -Version $Version -Arch $Arch
|
|
Add-ToPath
|
|
Test-Installation
|
|
Show-Configuration
|
|
} catch {
|
|
Write-Host "Installation failed: $_" -ForegroundColor Red
|
|
exit 1
|
|
}
|