#Requires -Version 5.1 <# .SYNOPSIS Installs dua (Disk Usage Analyzer). .DESCRIPTION Installs dua via winget (Byron.dua-cli) on Windows. dua is a fast disk usage analyzer with interactive TUI mode. Supported platforms: - Windows x64 (AMD64 / Intel 64bit) - Windows ARM64 Prerequisites: - winget (Windows Package Manager) — built into Windows 10 1709+ .EXAMPLE .\install-dua.ps1 # One-liner install from remote (works on Windows 10+): powershell -ExecutionPolicy Bypass -c "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; $t=\"$env:TEMP\install-dua.ps1\"; iwr -useb 'https://gl.isitsoft.kr/publicproj/install-sh/-/raw/main/install-dua.ps1' -OutFile $t; & $t" .NOTES If execution policy error occurs: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser #> [CmdletBinding()] param() Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' # Force TLS 1.2+ for HTTPS downloads (required on Windows 10 / PowerShell 5.1) [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # ──────────────────────────────────────────── # Utility functions # ──────────────────────────────────────────── function Info { Write-Host "[INFO] $args" -ForegroundColor Cyan } function Warn { Write-Host "[WARN] $args" -ForegroundColor Yellow } function Success { Write-Host "[OK] $args" -ForegroundColor Green } function ErrExit { Write-Host "[ERROR] $args" -ForegroundColor Red; exit 1 } # ──────────────────────────────────────────── # Step 1: Install dua # ──────────────────────────────────────────── Info "Installing dua (Disk Usage Analyzer)..." $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/" } 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 } } # 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 } } } # 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)" } else { Info "$duaDir 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 # ──────────────────────────────────────────── Info "" Info "==================================================" Success "dua installation complete!" Info "==================================================" if ($duaBin) { Info "" Info "dua binary: $duaBin" } 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"