152 lines
6.4 KiB
PowerShell
152 lines
6.4 KiB
PowerShell
#Requires -Version 5.1
|
|
<#
|
|
.SYNOPSIS
|
|
GitHub Releases에서 최신 ttyd 안정 버전을 다운로드하고 Windows 환경에 설치합니다.
|
|
|
|
.DESCRIPTION
|
|
https://github.com/tsl0922/ttyd/releases 에서 제공하는 최신 Windows 릴리스인
|
|
ttyd.win32.exe 바이너리를 다운로드하여 지정된 디렉토리에 ttyd.exe로 설치하고
|
|
사용자 PATH 환경 변수에 영구적으로 등록합니다.
|
|
|
|
.PARAMETER InstallDir
|
|
ttyd.exe가 설치될 디렉토리 경로입니다. 기본값: $env:USERPROFILE\.local\bin
|
|
|
|
.PARAMETER AddToPath
|
|
설치 디렉토리를 사용자 PATH 환경 변수에 영구적으로 추가할지 여부입니다. 기본값: $true
|
|
|
|
.EXAMPLE
|
|
.\install-ttyd.ps1
|
|
.\install-ttyd.ps1 -InstallDir "C:\tools\bin"
|
|
.\install-ttyd.ps1 -AddToPath $false
|
|
|
|
# Windows 원라인 원격 실행 명령어:
|
|
powershell -ExecutionPolicy Bypass -c "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; $t=\"$env:TEMP\install-ttyd.ps1\"; iwr -useb 'https://gl.isitsoft.kr/publicproj/install-sh/-/raw/main/install-ttyd.ps1' -OutFile $t; & $t"
|
|
|
|
.NOTES
|
|
실행 정책 에러가 발생하는 경우 다음 명령어로 해결할 수 있습니다:
|
|
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
param(
|
|
[string] $InstallDir = "$env:USERPROFILE\.local\bin",
|
|
[bool] $AddToPath = $true
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
# HTTPS 다운로드를 위한 TLS 1.2 강제 (Windows 7/10 및 PowerShell 5.1 호환성 보장)
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
|
|
# ────────────────────────────────────────────
|
|
# 유틸리티 함수 정의
|
|
# ────────────────────────────────────────────
|
|
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 }
|
|
|
|
# ────────────────────────────────────────────
|
|
# 상수 정의
|
|
# ────────────────────────────────────────────
|
|
$REPO = "tsl0922/ttyd"
|
|
$API_URL = "https://api.github.com/repos/$REPO/releases/latest"
|
|
$FALLBACK_TAG = "1.7.7"
|
|
|
|
# ────────────────────────────────────────────
|
|
# 메인 설치 프로세스
|
|
# ────────────────────────────────────────────
|
|
|
|
# 1) GitHub 최신 릴리스 정보 획득
|
|
Write-Info "Fetching latest ttyd release information from GitHub API..."
|
|
$release = $null
|
|
$tagName = $FALLBACK_TAG
|
|
try {
|
|
$release = Invoke-RestMethod -Uri $API_URL -UseBasicParsing -Headers @{ 'User-Agent' = 'install-ttyd-ps1' } -TimeoutSec 15
|
|
if ($release -and $release.tag_name -and $release.assets -and $release.assets.Count -gt 0) {
|
|
$tagName = $release.tag_name
|
|
}
|
|
} catch {
|
|
Write-Warn "GitHub API call failed: $_. Using fallback tag: $FALLBACK_TAG"
|
|
}
|
|
|
|
Write-Info "Target ttyd version: $tagName"
|
|
|
|
# 2) ttyd.win32.exe 에셋 탐색
|
|
$assetName = "ttyd.win32.exe"
|
|
$asset = $null
|
|
if ($release -and $release.assets) {
|
|
$asset = $release.assets | Where-Object { $_.name -eq $assetName } | Select-Object -First 1
|
|
}
|
|
|
|
if ($asset -and $asset.browser_download_url) {
|
|
$downloadUrl = $asset.browser_download_url
|
|
} else {
|
|
$downloadUrl = "https://github.com/$REPO/releases/download/$tagName/$assetName"
|
|
}
|
|
$fallbackUrl = "https://github.com/$REPO/releases/download/$FALLBACK_TAG/$assetName"
|
|
$destExeName = "ttyd.exe"
|
|
|
|
# 3) 다운로드 및 디렉토리 생성
|
|
if (-not (Test-Path $InstallDir)) {
|
|
Write-Info "Creating installation directory: $InstallDir"
|
|
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
|
|
}
|
|
|
|
$destPath = Join-Path $InstallDir $destExeName
|
|
$tmpDir = Join-Path $env:TEMP "ttyd_install_$(Get-Random)"
|
|
New-Item -ItemType Directory -Path $tmpDir -Force | Out-Null
|
|
$tmpFilePath = Join-Path $tmpDir $assetName
|
|
|
|
try {
|
|
Write-Info "Downloading binary: $downloadUrl"
|
|
$ProgressPreference = 'SilentlyContinue'
|
|
try {
|
|
Invoke-WebRequest -Uri $downloadUrl -OutFile $tmpFilePath -UseBasicParsing
|
|
} catch {
|
|
if ($downloadUrl -ne $fallbackUrl) {
|
|
Write-Warn "Primary download failed. Retrying with fallback version ($FALLBACK_TAG): $fallbackUrl"
|
|
Invoke-WebRequest -Uri $fallbackUrl -OutFile $tmpFilePath -UseBasicParsing
|
|
} else {
|
|
throw
|
|
}
|
|
}
|
|
$ProgressPreference = 'Continue'
|
|
|
|
Write-Info "Deploying binary to install path: $destPath"
|
|
Move-Item -Path $tmpFilePath -Destination $destPath -Force
|
|
} finally {
|
|
if (Test-Path $tmpDir) {
|
|
Remove-Item -Path $tmpDir -Recurse -Force -ErrorAction SilentlyContinue
|
|
}
|
|
}
|
|
|
|
# 4) PATH 환경 변수 등록
|
|
if ($AddToPath) {
|
|
if ($env:Path -notlike "*$InstallDir*") {
|
|
$env:Path = "$InstallDir;$env:Path"
|
|
Write-Info "Temporarily added $InstallDir to current session PATH."
|
|
}
|
|
|
|
$userPath = [System.Environment]::GetEnvironmentVariable('Path', 'User')
|
|
if ($userPath -notlike "*$InstallDir*") {
|
|
[System.Environment]::SetEnvironmentVariable('Path', "$InstallDir;$userPath", 'User')
|
|
Write-Success "Permanently added $InstallDir to User PATH."
|
|
Write-Warn "Please restart your terminal window to apply the updated PATH environment variable."
|
|
} else {
|
|
Write-Info "$InstallDir is already registered in User PATH."
|
|
}
|
|
}
|
|
|
|
# 5) 설치 완료 검증
|
|
if (Test-Path $destPath) {
|
|
Write-Host ""
|
|
Write-Host "==================================================" -ForegroundColor Green
|
|
Write-Success "ttyd ($tagName) installation completed successfully!"
|
|
Write-Host "==================================================" -ForegroundColor Green
|
|
Write-Info "Run command: ttyd --version"
|
|
} else {
|
|
Write-Err "Installation seems to have failed. Please check if the binary exists at the destination path."
|
|
}
|