Initial commit; from install-bottom
This commit is contained in:
commit
a07e58ce04
5 files changed
+601
No files matched your search
@@ -0,0 +1,232 @@
|
||||
#Requires -Version 5.1
|
||||
<#
|
||||
.SYNOPSIS
|
||||
bottom(btm) 프로세스 모니터를 GitHub Nightly 최신 버전으로 설치합니다.
|
||||
|
||||
.DESCRIPTION
|
||||
https://github.com/ClementTsang/bottom/releases 에서 최신 Nightly 릴리스를
|
||||
자동으로 탐지하고, 현재 Windows 아키텍처에 맞는 zip 파일을 다운로드하여
|
||||
설치합니다.
|
||||
|
||||
지원 아키텍처:
|
||||
- x64 (AMD64 / Intel 64bit)
|
||||
- ARM64 (Snapdragon X Elite, Qualcomm ARM 등)
|
||||
|
||||
.PARAMETER InstallDir
|
||||
btm.exe 를 설치할 디렉토리. 기본값: $env:USERPROFILE\.local\bin
|
||||
|
||||
.PARAMETER AddToPath
|
||||
InstallDir 을 영구적으로 사용자 PATH에 추가할지 여부. 기본값: $true
|
||||
|
||||
.EXAMPLE
|
||||
.\install-bottom.ps1
|
||||
.\install-bottom.ps1 -InstallDir "C:\tools\bin"
|
||||
.\install-bottom.ps1 -AddToPath $false
|
||||
|
||||
.NOTES
|
||||
실행 정책 오류 발생 시:
|
||||
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string] $InstallDir = "$env:USERPROFILE\.local\bin",
|
||||
[bool] $AddToPath = $true
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# 상수
|
||||
# ────────────────────────────────────────────
|
||||
$REPO = "ClementTsang/bottom"
|
||||
$API_URL = "https://api.github.com/repos/$REPO/releases"
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# 유틸리티 함수
|
||||
# ────────────────────────────────────────────
|
||||
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 }
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# TLS 1.2 강제 (Windows 7/8.1 대비)
|
||||
# ────────────────────────────────────────────
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# 아키텍처 감지
|
||||
# ────────────────────────────────────────────
|
||||
function Get-Platform {
|
||||
# 1) 환경변수를 먼저 확인 (Windows on ARM의 32-bit PowerShell에서도 OS 아키를 정확히 판별)
|
||||
# - 네이티브 프로세스 : PROCESSOR_ARCHITECTURE = AMD64 / ARM64 / x86
|
||||
# - WOW64(32bit on 64bit): PROCESSOR_ARCHITECTURE = x86,
|
||||
# PROCESSOR_ARCHITEW6432 = AMD64 또는 ARM64 (실제 OS 아키)
|
||||
$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" }
|
||||
}
|
||||
|
||||
# 2) Fallback: .NET RuntimeInformation (PS 5.1 + .NET Framework 4.7.1+ 필요)
|
||||
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 { Write-Err "지원하지 않는 아키텍처: $arch" }
|
||||
}
|
||||
} catch {
|
||||
Write-Err "아키텍처 감지에 실패했습니다: $_"
|
||||
}
|
||||
}
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# 최신 Nightly 릴리스 태그 가져오기
|
||||
# ────────────────────────────────────────────
|
||||
function Get-LatestNightlyTag {
|
||||
Write-Info "GitHub API로 최신 Nightly 릴리스 정보를 조회합니다..."
|
||||
|
||||
try {
|
||||
$releases = Invoke-RestMethod -Uri $API_URL -UseBasicParsing `
|
||||
-Headers @{ 'User-Agent' = 'install-bottom-ps1' }
|
||||
} catch {
|
||||
Write-Err "GitHub API 호출에 실패했습니다: $_"
|
||||
}
|
||||
|
||||
# prerelease=true 이고 tag_name 이 'nightly-' 로 시작하는 첫 번째 항목
|
||||
$nightly = $releases | Where-Object {
|
||||
$_.prerelease -eq $true -and $_.tag_name -like 'nightly-*'
|
||||
} | Select-Object -First 1
|
||||
|
||||
if (-not $nightly) {
|
||||
Write-Err "Nightly 릴리스를 찾을 수 없습니다."
|
||||
}
|
||||
|
||||
return $nightly.tag_name
|
||||
}
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# 다운로드 URL 조합
|
||||
# ────────────────────────────────────────────
|
||||
function Get-DownloadUrl {
|
||||
param([string]$Tag, [string]$Triple)
|
||||
$filename = "bottom_${Triple}.zip"
|
||||
return "https://github.com/$REPO/releases/download/$Tag/$filename"
|
||||
}
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# 다운로드 & 압축 해제 & 설치
|
||||
# ────────────────────────────────────────────
|
||||
function Install-Bottom {
|
||||
param([string]$Url)
|
||||
|
||||
# 임시 디렉토리 생성
|
||||
$tmpDir = Join-Path $env:TEMP "bottom_install_$(Get-Random)"
|
||||
New-Item -ItemType Directory -Path $tmpDir | Out-Null
|
||||
|
||||
try {
|
||||
$zipPath = Join-Path $tmpDir "bottom.zip"
|
||||
|
||||
Write-Info "다운로드 중: $Url"
|
||||
try {
|
||||
# PowerShell 5+ 에서 진행률 표시
|
||||
$ProgressPreference = 'SilentlyContinue'
|
||||
Invoke-WebRequest -Uri $Url -OutFile $zipPath -UseBasicParsing
|
||||
$ProgressPreference = 'Continue'
|
||||
} catch {
|
||||
Write-Err "다운로드 실패: $_"
|
||||
}
|
||||
|
||||
Write-Info "압축 해제 중..."
|
||||
Expand-Archive -Path $zipPath -DestinationPath $tmpDir -Force
|
||||
|
||||
# btm.exe 찾기
|
||||
$btmExe = Get-ChildItem -Path $tmpDir -Recurse -Filter "btm.exe" |
|
||||
Select-Object -First 1
|
||||
if (-not $btmExe) {
|
||||
Write-Err "압축 파일에서 'btm.exe'를 찾을 수 없습니다."
|
||||
}
|
||||
|
||||
# 설치 디렉토리 생성
|
||||
if (-not (Test-Path $InstallDir)) {
|
||||
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
|
||||
}
|
||||
|
||||
$destPath = Join-Path $InstallDir "btm.exe"
|
||||
Write-Info "설치 중: $destPath"
|
||||
Copy-Item -Path $btmExe.FullName -Destination $destPath -Force
|
||||
|
||||
Write-Success "설치 완료!"
|
||||
|
||||
# 버전 확인
|
||||
Write-Info "버전 확인:"
|
||||
& $destPath --version
|
||||
|
||||
} finally {
|
||||
# 임시 파일 정리
|
||||
if (Test-Path $tmpDir) {
|
||||
Remove-Item -Path $tmpDir -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# PATH 등록 (사용자 환경변수)
|
||||
# ────────────────────────────────────────────
|
||||
function Add-ToUserPath {
|
||||
param([string]$Dir)
|
||||
|
||||
$currentPath = [Environment]::GetEnvironmentVariable('PATH', 'User')
|
||||
if (-not $currentPath) { $currentPath = '' }
|
||||
# 결과가 단일 항목일 때도 배열로 강제 (-contains 안전성 확보)
|
||||
$dirs = @($currentPath -split ';' | Where-Object { $_ -ne '' })
|
||||
|
||||
if ($dirs -contains $Dir) {
|
||||
Write-Info "'$Dir' 은 이미 PATH에 등록되어 있습니다."
|
||||
return
|
||||
}
|
||||
|
||||
$newPath = ($dirs + $Dir) -join ';'
|
||||
[Environment]::SetEnvironmentVariable('PATH', $newPath, 'User')
|
||||
|
||||
# 현재 세션에도 반영
|
||||
$env:PATH = "$env:PATH;$Dir"
|
||||
|
||||
Write-Success "'$Dir' 을 사용자 PATH에 영구 등록했습니다."
|
||||
Write-Warn "새 터미널을 열어야 PATH 변경이 적용됩니다."
|
||||
}
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# 메인
|
||||
# ────────────────────────────────────────────
|
||||
function Main {
|
||||
Write-Info "===== bottom(btm) 설치 스크립트 (Windows PowerShell) ====="
|
||||
|
||||
$triple = Get-Platform
|
||||
Write-Info "감지된 플랫폼: $triple"
|
||||
|
||||
$tag = Get-LatestNightlyTag
|
||||
Write-Info "최신 Nightly 태그: $tag"
|
||||
|
||||
$url = Get-DownloadUrl -Tag $tag -Triple $triple
|
||||
Install-Bottom -Url $url
|
||||
|
||||
if ($AddToPath) {
|
||||
Add-ToUserPath -Dir $InstallDir
|
||||
} else {
|
||||
Write-Warn "PATH 자동 등록을 건너뜁니다."
|
||||
Write-Warn "수동으로 PATH에 추가하세요: $InstallDir"
|
||||
}
|
||||
|
||||
Write-Success "모든 작업이 완료되었습니다."
|
||||
Write-Info "사용법: btm"
|
||||
}
|
||||
|
||||
Main
|
||||
Reference in new issue
Block a user