dua 설치 스크립트 최신 릴리스 태그 필터링 오류 수정

This commit is contained in:
mcchae committed 2026-10-31 04:28:07 +09:00
1 parent 8f2177b3b5
commit 5a67e7bbcf
4 files changed
+351 -194

No files matched your search

+195 -96
View File
@@ -1,18 +1,24 @@
#Requires -Version 5.1
<#
.SYNOPSIS
Installs dua (Disk Usage Analyzer).
Installs dua (Disk Usage Analyzer) from GitHub releases.
.DESCRIPTION
Installs dua via winget (Byron.dua-cli) on Windows.
dua is a fast disk usage analyzer with interactive TUI mode.
Auto-detects the latest CLI release (v*) from
https://github.com/Byron/dua-cli/releases, downloads the zip archive
matching your Windows architecture, and installs dua.exe into
$env:USERPROFILE\.local\bin.
Supported platforms:
- Windows x64 (AMD64 / Intel 64bit)
- Windows ARM64
- Windows x86 (32bit)
Prerequisites:
- winget (Windows Package Manager) — built into Windows 10 1709+
.PARAMETER InstallDir
Directory to install dua.exe. Default: $env:USERPROFILE\.local\bin
.PARAMETER AddToPath
Whether to permanently add InstallDir to user PATH. Default: $true
.EXAMPLE
.\install-dua.ps1
@@ -26,7 +32,10 @@
#>
[CmdletBinding()]
param()
param(
[string] $InstallDir = "$env:USERPROFILE\.local\bin",
[bool] $AddToPath = $true
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
@@ -34,6 +43,13 @@ $ErrorActionPreference = 'Stop'
# Force TLS 1.2+ for HTTPS downloads (required on Windows 10 / PowerShell 5.1)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# ────────────────────────────────────────────
# Constants
# ────────────────────────────────────────────
$REPO = "Byron/dua-cli"
$API_URL = "https://api.github.com/repos/$REPO/releases"
$FALLBACK_TAG = "v2.46.0"
# ────────────────────────────────────────────
# Utility functions
# ────────────────────────────────────────────
@@ -43,111 +59,194 @@ function Success { Write-Host "[OK] $args" -ForegroundColor Green }
function ErrExit { Write-Host "[ERROR] $args" -ForegroundColor Red; exit 1 }
# ────────────────────────────────────────────
# Step 1: Install dua
# Architecture detection
# ────────────────────────────────────────────
Info "Installing dua (Disk Usage Analyzer)..."
function Get-Platform {
$envArch = $env:PROCESSOR_ARCHITEW6432
if (-not $envArch) { $envArch = $env:PROCESSOR_ARCHITECTURE }
$duaCmd = Get-Command dua -ErrorAction SilentlyContinue
if ($duaCmd) {
$currentVer = & dua --version 2>$null
if (-not $currentVer) { $currentVer = "unknown" }
Info "dua is already installed ($currentVer). Skipping installation."
} else {
if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
ErrExit "winget is required. Install it from the Microsoft Store or https://learn.microsoft.com/en-us/windows/package-manager/winget/"
switch -Regex ($envArch) {
'^AMD64$' { return "x86_64-pc-windows-msvc" }
'^ARM64$' { return "aarch64-pc-windows-msvc" }
'^x86$' { return "i686-pc-windows-msvc" }
}
winget install --id Byron.dua-cli --accept-package-agreements --accept-source-agreements 2>&1 | Out-Null
Success "dua installed via winget"
}
# ────────────────────────────────────────────
# Verify dua is available and add to PATH permanently if needed
# ────────────────────────────────────────────
$duaBin = $null
# 1) Try current PATH
$duaCmd = Get-Command dua -ErrorAction SilentlyContinue
if ($duaCmd) {
$duaBin = $duaCmd.Source
}
# 2) Refresh PATH from registry (winget may have added paths)
if (-not $duaBin) {
$env:Path = [System.Environment]::GetEnvironmentVariable('Path', 'User') + ';' + [System.Environment]::GetEnvironmentVariable('Path', 'Machine')
$duaCmd = Get-Command dua -ErrorAction SilentlyContinue
if ($duaCmd) {
$duaBin = $duaCmd.Source
try {
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
switch ($arch) {
'X64' { return "x86_64-pc-windows-msvc" }
'Arm64' { return "aarch64-pc-windows-msvc" }
'X86' { return "i686-pc-windows-msvc" }
default { ErrExit "Unsupported architecture: $arch" }
}
} catch {
ErrExit "Failed to detect architecture: $_"
}
}
# 3) Search common locations where winget installs
if (-not $duaBin) {
$searchDirs = @(
(Join-Path $env:LOCALAPPDATA 'Microsoft\WinGet\Links'),
(Join-Path $env:LOCALAPPDATA 'Programs\dua-cli'),
'C:\Program Files\dua-cli',
'C:\Program Files (x86)\dua-cli'
)
foreach ($dir in $searchDirs) {
if (Test-Path $dir) {
$candidate = Join-Path $dir 'dua.exe'
if (Test-Path $candidate) { $duaBin = $candidate; break }
# ────────────────────────────────────────────
# Get latest stable CLI release tag (starts with 'v')
# ────────────────────────────────────────────
function Get-LatestTag {
Info "Fetching latest dua release from GitHub API..."
try {
$releases = Invoke-RestMethod -Uri $API_URL -UseBasicParsing `
-Headers @{ 'User-Agent' = 'install-dua-ps1' } -TimeoutSec 15
# Byron/dua-cli also publishes 'dua-core-v*' library tags without binary assets.
# Filter only CLI releases whose tag_name starts with 'v' and have assets.
$latest = $releases | Where-Object {
$_.prerelease -eq $false -and
$_.tag_name -like 'v*' -and
$_.assets -and
$_.assets.Count -gt 0
} | Select-Object -First 1
if ($latest -and $latest.tag_name) {
return $latest.tag_name
}
} catch {
Warn "GitHub API lookup failed: $_"
}
Warn "Using fallback release tag: $FALLBACK_TAG"
return $FALLBACK_TAG
}
# ────────────────────────────────────────────
# Build download URL
# ────────────────────────────────────────────
function Get-DownloadUrl {
param([string]$Tag, [string]$Triple)
$filename = "dua-${Tag}-${Triple}.zip"
return "https://github.com/$REPO/releases/download/$Tag/$filename"
}
# ────────────────────────────────────────────
# Download, extract & install
# ────────────────────────────────────────────
function Install-Dua {
param([string]$Url)
$tmpDir = Join-Path $env:TEMP "dua_install_$(Get-Random)"
New-Item -ItemType Directory -Path $tmpDir -Force | Out-Null
try {
$zipPath = Join-Path $tmpDir "dua.zip"
Info "Downloading: $Url"
try {
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $Url -OutFile $zipPath -UseBasicParsing
$ProgressPreference = 'Continue'
} catch {
ErrExit "Download failed from $Url : $_"
}
Info "Extracting archive..."
Expand-Archive -Path $zipPath -DestinationPath $tmpDir -Force
$duaExe = Get-ChildItem -Path $tmpDir -Recurse -Filter "dua.exe" |
Select-Object -First 1
if (-not $duaExe) {
ErrExit "Cannot find 'dua.exe' in the downloaded archive."
}
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
$destPath = Join-Path $InstallDir "dua.exe"
Info "Installing to: $destPath"
Copy-Item -Path $duaExe.FullName -Destination $destPath -Force
Success "dua installed to $destPath"
return $destPath
} 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)
$normalizedDir = $Dir.TrimEnd('\')
if ($env:Path -notlike "*$normalizedDir*") {
$env:Path = "$normalizedDir;$env:Path"
Info "Added $normalizedDir to current session PATH."
}
$currentPath = [Environment]::GetEnvironmentVariable('Path', 'User')
if (-not $currentPath) { $currentPath = '' }
$dirs = @($currentPath -split ';' | Where-Object { $_ -ne '' })
$alreadyInPath = $false
foreach ($d in $dirs) {
if ($d.Trim().TrimEnd('\') -eq $normalizedDir) {
$alreadyInPath = $true
break
}
}
# Recurse under WinGet/Packages for dua
if (-not $duaBin -and (Test-Path (Join-Path $env:LOCALAPPDATA 'Microsoft\WinGet\Packages'))) {
$found = Get-ChildItem -Path (Join-Path $env:LOCALAPPDATA 'Microsoft\WinGet\Packages') -Recurse -Filter 'dua.exe' -ErrorAction SilentlyContinue | Select-Object -First 1
if ($found) { $duaBin = $found.FullName }
}
}
if ($duaBin) {
# Add dua's directory to PATH for this session
$duaDir = Split-Path $duaBin
if ($env:Path -notlike "*$duaDir*") {
$env:Path = "$duaDir;$env:Path"
Info "Added $duaDir to PATH for this session"
}
Success "dua is available: $duaBin"
# Permanently add dua's directory to user PATH if not already there
$userPath = [System.Environment]::GetEnvironmentVariable('Path', 'User')
if ($userPath -notlike "*$duaDir*") {
[System.Environment]::SetEnvironmentVariable('Path', "$duaDir;$userPath", 'User')
Success "Added $duaDir to user PATH permanently (takes effect on next login)"
if (-not $alreadyInPath) {
$newPath = if ($currentPath) { "$normalizedDir;$currentPath" } else { $normalizedDir }
[Environment]::SetEnvironmentVariable('Path', $newPath, 'User')
Success "Added '$normalizedDir' to User PATH permanently."
Warn "Open a new terminal for PATH changes to take full effect."
} else {
Info "$duaDir already in user PATH"
Info "'$normalizedDir' is already in User PATH."
}
} else {
Warn "dua was not found in PATH after installation."
Warn "Please restart your terminal or add dua's directory to your PATH manually."
}
# ────────────────────────────────────────────
# Step 2: Post-install notes
# Main
# ────────────────────────────────────────────
Info ""
Info "=================================================="
Success "dua installation complete!"
Info "=================================================="
if ($duaBin) {
function Main {
Info "===== dua (Disk Usage Analyzer) install script (Windows PowerShell) ====="
$triple = Get-Platform
Info "Detected platform: $triple"
$tag = Get-LatestTag
Info "Release tag: $tag"
$url = Get-DownloadUrl -Tag $tag -Triple $triple
$duaBin = Install-Dua -Url $url
if ($AddToPath) {
Add-ToUserPath -Dir $InstallDir
} else {
Warn "Skipping automatic PATH registration."
Warn "Add to PATH manually: $InstallDir"
}
Info ""
Info "dua binary: $duaBin"
Info "=================================================="
Success "dua installation complete!"
Info "=================================================="
if ($duaBin -and (Test-Path $duaBin)) {
$ver = & $duaBin --version 2>$null
Info "Installed version: $ver ($duaBin)"
}
Info ""
Info "Getting started:"
Info " dua - Show disk usage of current directory"
Info " dua /path/to/dir - Show disk usage of specific directory"
Info " dua i - Interactive mode (explore & delete)"
Info " dua --help - Show help"
Info ""
Info "Interactive mode shortcuts:"
Info " Arrow keys / h/j/k/l - Navigate"
Info " ? - Show help"
Info " d - Delete selected entry"
Info " q / Esc - Quit"
}
Info ""
Info "IMPORTANT: Close this terminal and open a new one to use dua."
Info "PATH changes require a new terminal session to take effect."
Info ""
Info "Getting started:"
Info " dua - Show disk usage of current directory"
Info " dua /path/to/dir - Show disk usage of specific directory"
Info " dua i - Interactive mode (explore & delete)"
Info " dua --help - Show help"
Info ""
Info "Interactive mode shortcuts:"
Info " Arrow keys / h/j/k/l - Navigate"
Info " ? - Show help"
Info " d - Delete selected entry"
Info " q / Esc - Quit"
Main