241 lines
9.7 KiB
PowerShell
241 lines
9.7 KiB
PowerShell
#Requires -Version 5.1
|
|
<#
|
|
.SYNOPSIS
|
|
Installs lazydocker terminal UI for Docker from GitHub releases.
|
|
|
|
.DESCRIPTION
|
|
Auto-detects the latest release from
|
|
https://github.com/jesseduffield/lazydocker/releases, downloads the zip
|
|
file matching your Windows architecture, and installs it.
|
|
|
|
Supported architectures:
|
|
- x64 (AMD64 / Intel 64bit)
|
|
- ARM64 (Snapdragon X Elite, Qualcomm ARM, etc.)
|
|
|
|
.PARAMETER InstallDir
|
|
Directory to install lazydocker.exe. Default: $env:USERPROFILE\.local\bin
|
|
|
|
.PARAMETER AddToPath
|
|
Whether to permanently add InstallDir to user PATH. Default: $true
|
|
|
|
.EXAMPLE
|
|
.\install-lazydocker.ps1
|
|
.\install-lazydocker.ps1 -InstallDir "C:\tools\bin"
|
|
.\install-lazydocker.ps1 -AddToPath $false
|
|
|
|
# One-liner install from remote (works on Windows 10+):
|
|
powershell -ExecutionPolicy Bypass -c "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; $t=\"$env:TEMP\install-lazydocker.ps1\"; iwr -useb 'https://gl.isitsoft.kr/publicproj/install-sh/-/raw/main/install-lazydocker.ps1' -OutFile $t; & $t"
|
|
|
|
# With parameters:
|
|
powershell -ExecutionPolicy Bypass -c "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; $t=\"$env:TEMP\install-lazydocker.ps1\"; iwr -useb 'https://gl.isitsoft.kr/publicproj/install-sh/-/raw/main/install-lazydocker.ps1' -OutFile $t; & $t -InstallDir 'C:\tools\bin'"
|
|
|
|
.NOTES
|
|
If execution policy error occurs:
|
|
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
param(
|
|
[string] $InstallDir = "$env:USERPROFILE\.local\bin",
|
|
[bool] $AddToPath = $true
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
# ────────────────────────────────────────────
|
|
# Constants
|
|
# ────────────────────────────────────────────
|
|
$REPO = "jesseduffield/lazydocker"
|
|
$API_URL = "https://api.github.com/repos/$REPO/releases"
|
|
|
|
# ────────────────────────────────────────────
|
|
# Utility functions
|
|
# ────────────────────────────────────────────
|
|
function Write-Info { param([string]$msg) Write-Host "[INFO] $msg" -ForegroundColor Cyan }
|
|
function Write-Warn { param([string]$msg) Write-Host "[WARN] $msg" -ForegroundColor Yellow }
|
|
function Write-Success { param([string]$msg) Write-Host "[OK] $msg" -ForegroundColor Green }
|
|
function Write-Err { param([string]$msg) Write-Host "[ERROR] $msg" -ForegroundColor Red; exit 1 }
|
|
|
|
# ────────────────────────────────────────────
|
|
# Enforce TLS 1.2+ for HTTPS downloads (required on Windows 10 / PowerShell 5.1)
|
|
# ────────────────────────────────────────────
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
|
|
# ────────────────────────────────────────────
|
|
# Architecture detection
|
|
# ────────────────────────────────────────────
|
|
function Get-Platform {
|
|
$envArch = $env:PROCESSOR_ARCHITEW6432
|
|
if (-not $envArch) { $envArch = $env:PROCESSOR_ARCHITECTURE }
|
|
|
|
switch -Regex ($envArch) {
|
|
'^AMD64$' { return "Windows_x86_64" }
|
|
'^ARM64$' { return "Windows_arm64" }
|
|
'^x86$' { return "Windows_x86" }
|
|
}
|
|
|
|
try {
|
|
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
|
|
switch ($arch) {
|
|
'X64' { return "Windows_x86_64" }
|
|
'Arm64' { return "Windows_arm64" }
|
|
'X86' { return "Windows_x86" }
|
|
default { Write-Err "Unsupported architecture: $arch" }
|
|
}
|
|
} catch {
|
|
Write-Err "Failed to detect architecture: $_"
|
|
}
|
|
}
|
|
|
|
# ────────────────────────────────────────────
|
|
# Get latest stable release tag
|
|
# ────────────────────────────────────────────
|
|
function Get-LatestTag {
|
|
Write-Info "Fetching latest release from GitHub API..."
|
|
|
|
try {
|
|
$releases = Invoke-RestMethod -Uri $API_URL -UseBasicParsing `
|
|
-Headers @{ 'User-Agent' = 'install-lazydocker-ps1' }
|
|
} catch {
|
|
Write-Err "Failed to call GitHub API: $_"
|
|
}
|
|
|
|
$latest = $releases | Where-Object { $_.prerelease -eq $false } | Select-Object -First 1
|
|
|
|
if (-not $latest) {
|
|
Write-Err "Could not find latest release."
|
|
}
|
|
|
|
return $latest.tag_name
|
|
}
|
|
|
|
# ────────────────────────────────────────────
|
|
# Build download URL
|
|
# ────────────────────────────────────────────
|
|
function Get-DownloadUrl {
|
|
param([string]$Tag, [string]$Platform)
|
|
$version = $Tag -replace '^v', ''
|
|
$filename = "lazydocker_${version}_${Platform}.zip"
|
|
return "https://github.com/$REPO/releases/download/$Tag/$filename"
|
|
}
|
|
|
|
# ────────────────────────────────────────────
|
|
# Download, extract & install
|
|
# ────────────────────────────────────────────
|
|
function Install-Lazydocker {
|
|
param([string]$Url)
|
|
|
|
$tmpDir = Join-Path $env:TEMP "lazydocker_install_$(Get-Random)"
|
|
New-Item -ItemType Directory -Path $tmpDir | Out-Null
|
|
|
|
try {
|
|
$zipPath = Join-Path $tmpDir "lazydocker.zip"
|
|
|
|
Write-Info "Downloading: $Url"
|
|
try {
|
|
$ProgressPreference = 'SilentlyContinue'
|
|
Invoke-WebRequest -Uri $Url -OutFile $zipPath -UseBasicParsing
|
|
$ProgressPreference = 'Continue'
|
|
} catch {
|
|
Write-Err "Download failed: $_"
|
|
}
|
|
|
|
Write-Info "Extracting..."
|
|
Expand-Archive -Path $zipPath -DestinationPath $tmpDir -Force
|
|
|
|
$lazydockerExe = Get-ChildItem -Path $tmpDir -Recurse -Filter "lazydocker.exe" |
|
|
Select-Object -First 1
|
|
if (-not $lazydockerExe) {
|
|
Write-Err "Cannot find 'lazydocker.exe' in the archive."
|
|
}
|
|
|
|
if (-not (Test-Path $InstallDir)) {
|
|
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
|
|
}
|
|
|
|
$destPath = Join-Path $InstallDir "lazydocker.exe"
|
|
|
|
# Check if lazydocker.exe is currently running (locked)
|
|
if (Test-Path $destPath) {
|
|
try {
|
|
$testStream = [System.IO.File]::Open($destPath, 'Open', 'ReadWrite', 'Delete')
|
|
$testStream.Close()
|
|
$testStream.Dispose()
|
|
} catch {
|
|
Write-Err "lazydocker.exe is currently running. Please close lazydocker and run this script again."
|
|
}
|
|
}
|
|
|
|
Write-Info "Installing: $destPath"
|
|
Copy-Item -Path $lazydockerExe.FullName -Destination $destPath -Force
|
|
|
|
Write-Success "Installation complete!"
|
|
|
|
Write-Info "Version check:"
|
|
try {
|
|
& $destPath --version
|
|
} catch {
|
|
Write-Warn "Cannot run version check (lazydocker may need a new terminal session to start)."
|
|
}
|
|
|
|
} finally {
|
|
if (Test-Path $tmpDir) {
|
|
Remove-Item -Path $tmpDir -Recurse -Force -ErrorAction SilentlyContinue
|
|
}
|
|
}
|
|
}
|
|
|
|
# ────────────────────────────────────────────
|
|
# Add to PATH (user environment variable)
|
|
# ────────────────────────────────────────────
|
|
function Add-ToUserPath {
|
|
param([string]$Dir)
|
|
|
|
$currentPath = [Environment]::GetEnvironmentVariable('PATH', 'User')
|
|
if (-not $currentPath) { $currentPath = '' }
|
|
$dirs = @($currentPath -split ';' | Where-Object { $_ -ne '' })
|
|
|
|
if ($dirs -contains $Dir) {
|
|
Write-Info "'$Dir' is already in your PATH."
|
|
return
|
|
}
|
|
|
|
$newPath = ($dirs + $Dir) -join ';'
|
|
[Environment]::SetEnvironmentVariable('PATH', $newPath, 'User')
|
|
|
|
$env:PATH = "$env:PATH;$Dir"
|
|
|
|
Write-Success "'$Dir' has been permanently added to user PATH."
|
|
Write-Warn "Open a new terminal for PATH changes to take effect."
|
|
}
|
|
|
|
# ────────────────────────────────────────────
|
|
# Main
|
|
# ────────────────────────────────────────────
|
|
function Main {
|
|
Write-Info "===== lazydocker install script (Windows PowerShell) ====="
|
|
|
|
$platform = Get-Platform
|
|
Write-Info "Detected platform: $platform"
|
|
|
|
$tag = Get-LatestTag
|
|
Write-Info "Latest release: $tag"
|
|
|
|
$url = Get-DownloadUrl -Tag $tag -Platform $platform
|
|
Install-Lazydocker -Url $url
|
|
|
|
if ($AddToPath) {
|
|
Add-ToUserPath -Dir $InstallDir
|
|
} else {
|
|
Write-Warn "Skipping automatic PATH registration."
|
|
Write-Warn "Add to PATH manually: $InstallDir"
|
|
}
|
|
|
|
Write-Success "All tasks completed."
|
|
Write-Info ""
|
|
Write-Info "IMPORTANT: Close this terminal and open a new one to use lazydocker."
|
|
Write-Info "PATH changes require a new terminal session to take effect."
|
|
}
|
|
|
|
Main |