2026-05-12 16:33:08 +09:00
|
|
|
#Requires -Version 5.1
|
2026-05-12 15:12:52 +09:00
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
2026-05-12 16:33:08 +09:00
|
|
|
Installs bottom(btm) process monitor from GitHub Nightly releases.
|
2026-05-12 15:12:52 +09:00
|
|
|
|
|
|
|
|
.DESCRIPTION
|
2026-05-12 16:33:08 +09:00
|
|
|
Auto-detects the latest Nightly release from
|
|
|
|
|
https://github.com/ClementTsang/bottom/releases, downloads the zip
|
|
|
|
|
file matching your Windows architecture, and installs it.
|
2026-05-12 15:12:52 +09:00
|
|
|
|
2026-05-12 16:33:08 +09:00
|
|
|
Supported architectures:
|
2026-05-12 15:12:52 +09:00
|
|
|
- x64 (AMD64 / Intel 64bit)
|
2026-05-12 16:33:08 +09:00
|
|
|
- ARM64 (Snapdragon X Elite, Qualcomm ARM, etc.)
|
2026-05-12 15:12:52 +09:00
|
|
|
|
|
|
|
|
.PARAMETER InstallDir
|
2026-05-12 16:33:08 +09:00
|
|
|
Directory to install btm.exe. Default: $env:USERPROFILE\.local\bin
|
2026-05-12 15:12:52 +09:00
|
|
|
|
|
|
|
|
.PARAMETER AddToPath
|
2026-05-12 16:33:08 +09:00
|
|
|
Whether to permanently add InstallDir to user PATH. Default: $true
|
2026-05-12 15:12:52 +09:00
|
|
|
|
|
|
|
|
.EXAMPLE
|
|
|
|
|
.\install-bottom.ps1
|
|
|
|
|
.\install-bottom.ps1 -InstallDir "C:\tools\bin"
|
|
|
|
|
.\install-bottom.ps1 -AddToPath $false
|
|
|
|
|
|
|
|
|
|
.NOTES
|
2026-05-12 16:33:08 +09:00
|
|
|
If execution policy error occurs:
|
2026-05-12 15:12:52 +09:00
|
|
|
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
[CmdletBinding()]
|
|
|
|
|
param(
|
|
|
|
|
[string] $InstallDir = "$env:USERPROFILE\.local\bin",
|
|
|
|
|
[bool] $AddToPath = $true
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
Set-StrictMode -Version Latest
|
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
|
|
|
|
|
|
# ────────────────────────────────────────────
|
2026-05-12 16:33:08 +09:00
|
|
|
# Constants
|
2026-05-12 15:12:52 +09:00
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
$REPO = "ClementTsang/bottom"
|
|
|
|
|
$API_URL = "https://api.github.com/repos/$REPO/releases"
|
|
|
|
|
|
|
|
|
|
# ────────────────────────────────────────────
|
2026-05-12 16:33:08 +09:00
|
|
|
# Utility functions
|
2026-05-12 15:12:52 +09:00
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
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 }
|
|
|
|
|
|
|
|
|
|
# ────────────────────────────────────────────
|
2026-05-12 16:33:08 +09:00
|
|
|
# Enforce TLS 1.2 (for Windows 7/8.1 compatibility)
|
2026-05-12 15:12:52 +09:00
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
|
|
|
|
|
|
|
|
# ────────────────────────────────────────────
|
2026-05-12 16:33:08 +09:00
|
|
|
# Architecture detection
|
2026-05-12 15:12:52 +09:00
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
function Get-Platform {
|
2026-05-12 16:33:08 +09:00
|
|
|
# 1) Check environment variables first (even 32-bit PowerShell on
|
|
|
|
|
# Windows ARM can correctly detect OS architecture)
|
|
|
|
|
# - Native process : PROCESSOR_ARCHITECTURE = AMD64 / ARM64 / x86
|
2026-05-12 15:12:52 +09:00
|
|
|
# - WOW64(32bit on 64bit): PROCESSOR_ARCHITECTURE = x86,
|
2026-05-12 16:33:08 +09:00
|
|
|
# PROCESSOR_ARCHITEW6432 = AMD64 or ARM64 (actual OS arch)
|
2026-05-12 15:12:52 +09:00
|
|
|
$envArch = $env:PROCESSOR_ARCHITEW6432
|
|
|
|
|
if (-not $envArch) { $envArch = $env:PROCESSOR_ARCHITECTURE }
|
|
|
|
|
|
|
|
|
|
switch -Regex ($envArch) {
|
|
|
|
|
'^AMD64$' { return "x86_64-pc-windows-msvc" }
|
|
|
|
|
'^ARM64$' { return "aarch64-pc-windows-msvc" }
|
|
|
|
|
'^x86$' { return "i686-pc-windows-msvc" }
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 16:33:08 +09:00
|
|
|
# 2) Fallback: .NET RuntimeInformation (requires PS 5.1 + .NET Framework 4.7.1+)
|
2026-05-12 15:12:52 +09:00
|
|
|
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" }
|
2026-05-12 16:33:08 +09:00
|
|
|
default { Write-Err "Unsupported architecture: $arch" }
|
2026-05-12 15:12:52 +09:00
|
|
|
}
|
|
|
|
|
} catch {
|
2026-05-12 16:33:08 +09:00
|
|
|
Write-Err "Failed to detect architecture: $_"
|
2026-05-12 15:12:52 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# ────────────────────────────────────────────
|
2026-05-12 16:33:08 +09:00
|
|
|
# Get latest Nightly release tag
|
2026-05-12 15:12:52 +09:00
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
function Get-LatestNightlyTag {
|
2026-05-12 16:33:08 +09:00
|
|
|
Write-Info "Fetching latest Nightly release from GitHub API..."
|
2026-05-12 15:12:52 +09:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$releases = Invoke-RestMethod -Uri $API_URL -UseBasicParsing `
|
|
|
|
|
-Headers @{ 'User-Agent' = 'install-bottom-ps1' }
|
|
|
|
|
} catch {
|
2026-05-12 16:33:08 +09:00
|
|
|
Write-Err "Failed to call GitHub API: $_"
|
2026-05-12 15:12:52 +09:00
|
|
|
}
|
|
|
|
|
|
2026-05-12 16:33:08 +09:00
|
|
|
# Get first item where prerelease=true and tag_name starts with 'nightly-'
|
2026-05-12 15:12:52 +09:00
|
|
|
$nightly = $releases | Where-Object {
|
|
|
|
|
$_.prerelease -eq $true -and $_.tag_name -like 'nightly-*'
|
|
|
|
|
} | Select-Object -First 1
|
|
|
|
|
|
|
|
|
|
if (-not $nightly) {
|
2026-05-12 16:33:08 +09:00
|
|
|
Write-Err "Could not find Nightly release."
|
2026-05-12 15:12:52 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $nightly.tag_name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# ────────────────────────────────────────────
|
2026-05-12 16:33:08 +09:00
|
|
|
# Build download URL
|
2026-05-12 15:12:52 +09:00
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
function Get-DownloadUrl {
|
|
|
|
|
param([string]$Tag, [string]$Triple)
|
|
|
|
|
$filename = "bottom_${Triple}.zip"
|
|
|
|
|
return "https://github.com/$REPO/releases/download/$Tag/$filename"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# ────────────────────────────────────────────
|
2026-05-12 16:33:08 +09:00
|
|
|
# Download, extract & install
|
2026-05-12 15:12:52 +09:00
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
function Install-Bottom {
|
|
|
|
|
param([string]$Url)
|
|
|
|
|
|
2026-05-12 16:33:08 +09:00
|
|
|
# Create temp directory
|
2026-05-12 15:12:52 +09:00
|
|
|
$tmpDir = Join-Path $env:TEMP "bottom_install_$(Get-Random)"
|
|
|
|
|
New-Item -ItemType Directory -Path $tmpDir | Out-Null
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$zipPath = Join-Path $tmpDir "bottom.zip"
|
|
|
|
|
|
2026-05-12 16:33:08 +09:00
|
|
|
Write-Info "Downloading: $Url"
|
2026-05-12 15:12:52 +09:00
|
|
|
try {
|
2026-05-12 16:33:08 +09:00
|
|
|
# Suppress progress bar in PowerShell 5+
|
2026-05-12 15:12:52 +09:00
|
|
|
$ProgressPreference = 'SilentlyContinue'
|
|
|
|
|
Invoke-WebRequest -Uri $Url -OutFile $zipPath -UseBasicParsing
|
|
|
|
|
$ProgressPreference = 'Continue'
|
|
|
|
|
} catch {
|
2026-05-12 16:33:08 +09:00
|
|
|
Write-Err "Download failed: $_"
|
2026-05-12 15:12:52 +09:00
|
|
|
}
|
|
|
|
|
|
2026-05-12 16:33:08 +09:00
|
|
|
Write-Info "Extracting..."
|
2026-05-12 15:12:52 +09:00
|
|
|
Expand-Archive -Path $zipPath -DestinationPath $tmpDir -Force
|
|
|
|
|
|
2026-05-12 16:33:08 +09:00
|
|
|
# Find btm.exe
|
2026-05-12 15:12:52 +09:00
|
|
|
$btmExe = Get-ChildItem -Path $tmpDir -Recurse -Filter "btm.exe" |
|
|
|
|
|
Select-Object -First 1
|
|
|
|
|
if (-not $btmExe) {
|
2026-05-12 16:33:08 +09:00
|
|
|
Write-Err "Cannot find 'btm.exe' in the archive."
|
2026-05-12 15:12:52 +09:00
|
|
|
}
|
|
|
|
|
|
2026-05-12 16:33:08 +09:00
|
|
|
# Create install directory
|
2026-05-12 15:12:52 +09:00
|
|
|
if (-not (Test-Path $InstallDir)) {
|
|
|
|
|
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$destPath = Join-Path $InstallDir "btm.exe"
|
2026-05-12 16:33:08 +09:00
|
|
|
Write-Info "Installing: $destPath"
|
2026-05-12 15:12:52 +09:00
|
|
|
Copy-Item -Path $btmExe.FullName -Destination $destPath -Force
|
|
|
|
|
|
2026-05-12 16:33:08 +09:00
|
|
|
Write-Success "Installation complete!"
|
2026-05-12 15:12:52 +09:00
|
|
|
|
2026-05-12 16:33:08 +09:00
|
|
|
# Check version
|
|
|
|
|
Write-Info "Version check:"
|
2026-05-12 15:12:52 +09:00
|
|
|
& $destPath --version
|
|
|
|
|
|
|
|
|
|
} finally {
|
2026-05-12 16:33:08 +09:00
|
|
|
# Cleanup temp files
|
2026-05-12 15:12:52 +09:00
|
|
|
if (Test-Path $tmpDir) {
|
|
|
|
|
Remove-Item -Path $tmpDir -Recurse -Force -ErrorAction SilentlyContinue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# ────────────────────────────────────────────
|
2026-05-12 16:33:08 +09:00
|
|
|
# Add to PATH (user environment variable)
|
2026-05-12 15:12:52 +09:00
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
function Add-ToUserPath {
|
|
|
|
|
param([string]$Dir)
|
|
|
|
|
|
|
|
|
|
$currentPath = [Environment]::GetEnvironmentVariable('PATH', 'User')
|
|
|
|
|
if (-not $currentPath) { $currentPath = '' }
|
2026-05-12 16:33:08 +09:00
|
|
|
# Force array even with single result (for safe -contains check)
|
2026-05-12 15:12:52 +09:00
|
|
|
$dirs = @($currentPath -split ';' | Where-Object { $_ -ne '' })
|
|
|
|
|
|
|
|
|
|
if ($dirs -contains $Dir) {
|
2026-05-12 16:33:08 +09:00
|
|
|
Write-Info "'$Dir' is already in your PATH."
|
2026-05-12 15:12:52 +09:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$newPath = ($dirs + $Dir) -join ';'
|
|
|
|
|
[Environment]::SetEnvironmentVariable('PATH', $newPath, 'User')
|
|
|
|
|
|
2026-05-12 16:33:08 +09:00
|
|
|
# Also reflect in current session
|
2026-05-12 15:12:52 +09:00
|
|
|
$env:PATH = "$env:PATH;$Dir"
|
|
|
|
|
|
2026-05-12 16:33:08 +09:00
|
|
|
Write-Success "'$Dir' has been permanently added to user PATH."
|
|
|
|
|
Write-Warn "Open a new terminal for PATH changes to take effect."
|
2026-05-12 15:12:52 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
# 메인
|
|
|
|
|
# ────────────────────────────────────────────
|
|
|
|
|
function Main {
|
2026-05-12 16:33:08 +09:00
|
|
|
Write-Info "===== bottom(btm) install script (Windows PowerShell) ====="
|
2026-05-12 15:12:52 +09:00
|
|
|
|
|
|
|
|
$triple = Get-Platform
|
2026-05-12 16:33:08 +09:00
|
|
|
Write-Info "Detected platform: $triple"
|
2026-05-12 15:12:52 +09:00
|
|
|
|
|
|
|
|
$tag = Get-LatestNightlyTag
|
2026-05-12 16:33:08 +09:00
|
|
|
Write-Info "Latest Nightly tag: $tag"
|
2026-05-12 15:12:52 +09:00
|
|
|
|
|
|
|
|
$url = Get-DownloadUrl -Tag $tag -Triple $triple
|
|
|
|
|
Install-Bottom -Url $url
|
|
|
|
|
|
|
|
|
|
if ($AddToPath) {
|
|
|
|
|
Add-ToUserPath -Dir $InstallDir
|
|
|
|
|
} else {
|
2026-05-12 16:33:08 +09:00
|
|
|
Write-Warn "Skipping automatic PATH registration."
|
|
|
|
|
Write-Warn "Add to PATH manually: $InstallDir"
|
2026-05-12 15:12:52 +09:00
|
|
|
}
|
|
|
|
|
|
2026-05-12 16:33:08 +09:00
|
|
|
Write-Success "All tasks completed."
|
|
|
|
|
Write-Info "Usage: btm"
|
2026-05-12 15:12:52 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Main
|