ttyd 추가
This commit is contained in:
1 parent
4d8e423070
commit
575a20c753
6 files changed
+370
-1
No files matched your search
@@ -0,0 +1,133 @@
|
||||
#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"
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# 메인 설치 프로세스
|
||||
# ────────────────────────────────────────────
|
||||
|
||||
# 1) GitHub 최신 릴리스 정보 획득
|
||||
Write-Info "GitHub API를 통해 ttyd 최신 릴리스 정보를 가져오는 중..."
|
||||
try {
|
||||
$release = Invoke-RestMethod -Uri $API_URL -UseBasicParsing -Headers @{ 'User-Agent' = 'install-ttyd-ps1' }
|
||||
} catch {
|
||||
Write-Err "GitHub API 호출에 실패했습니다: $_"
|
||||
}
|
||||
|
||||
$tagName = $release.tag_name
|
||||
Write-Info "최신 ttyd 버전 확인 완료: $tagName"
|
||||
|
||||
# 2) ttyd.win32.exe 에셋 탐색
|
||||
$assetName = "ttyd.win32.exe"
|
||||
$asset = $release.assets | Where-Object { $_.name -eq $assetName } | Select-Object -First 1
|
||||
|
||||
if (-not $asset) {
|
||||
Write-Err "릴리스($tagName)에서 '$assetName' 바이너리를 찾을 수 없습니다."
|
||||
}
|
||||
|
||||
$downloadUrl = $asset.browser_download_url
|
||||
$destExeName = "ttyd.exe"
|
||||
|
||||
# 3) 다운로드 및 디렉토리 생성
|
||||
if (-not (Test-Path $InstallDir)) {
|
||||
Write-Info "설치 디렉토리 생성 중: $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 "바이너리 다운로드 중: $downloadUrl"
|
||||
$ProgressPreference = 'SilentlyContinue' # 다운로드 진행 바 숨김으로 속도 향상
|
||||
Invoke-WebRequest -Uri $downloadUrl -OutFile $tmpFilePath -UseBasicParsing
|
||||
$ProgressPreference = 'Continue'
|
||||
|
||||
Write-Info "설치 경로로 바이너리 배포 중: $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 "현재 세션 PATH에 $InstallDir 경로를 임시 추가했습니다."
|
||||
}
|
||||
|
||||
$userPath = [System.Environment]::GetEnvironmentVariable('Path', 'User')
|
||||
if ($userPath -notlike "*$InstallDir*") {
|
||||
[System.Environment]::SetEnvironmentVariable('Path', "$InstallDir;$userPath", 'User')
|
||||
Write-Success "사용자 PATH 환경 변수에 $InstallDir 경로를 영구 등록했습니다."
|
||||
Write-Warn "변경된 PATH 설정을 반영하려면 열려 있는 터미널 창을 재시작해 주세요."
|
||||
} else {
|
||||
Write-Info "$InstallDir 경로는 이미 사용자 PATH에 등록되어 있습니다."
|
||||
}
|
||||
}
|
||||
|
||||
# 5) 설치 완료 검증
|
||||
if (Test-Path $destPath) {
|
||||
Write-Host ""
|
||||
Write-Host "==================================================" -ForegroundColor Green
|
||||
Write-Success "ttyd ($tagName) 설치가 완료되었습니다!"
|
||||
Write-Host "==================================================" -ForegroundColor Green
|
||||
Write-Info "실행 명령어: ttyd --version"
|
||||
} else {
|
||||
Write-Err "설치가 성공적으로 완료되지 않은 것으로 보입니다. 설치 파일 존재 여부를 확인해 주세요."
|
||||
}
|
||||
Reference in new issue
Block a user