Files
install-sh/install-helix.ps1
T
2026-06-02 11:20:59 +09:00

214 lines
9.7 KiB
PowerShell

#Requires -Version 5.1
<#
.SYNOPSIS
Installs Helix Editor (TUI text editor) and its runtime directory on Windows.
.DESCRIPTION
Auto-detects the latest release from https://github.com/helix-editor/helix/releases,
downloads the x86_64-windows.zip archive, extracts it, installs hx.exe
to your local bin directory, and deploys the essential runtime files
to %APPDATA%\helix\runtime.
Supported architectures:
- Windows x64 (AMD64 / Intel 64bit)
.PARAMETER InstallDir
Directory to install hx.exe. Default: $env:USERPROFILE\.local\bin
.PARAMETER AddToPath
Whether to permanently add InstallDir to user PATH. Default: $true
.EXAMPLE
.\install-helix.ps1
# One-liner install from remote (works on Windows 10+):
powershell -ExecutionPolicy Bypass -c "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; $t=\"$env:TEMP\install-helix.ps1\"; iwr -useb 'https://gl.isitsoft.kr/publicproj/install-sh/-/raw/main/install-helix.ps1' -OutFile $t; & $t"
.NOTES
If execution policy error occurs:
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 = "helix-editor/helix"
$API_URL = "https://api.github.com/repos/$REPO/releases/latest"
$HELIX_CONFIG_DIR = Join-Path $env:APPDATA "helix"
# ────────────────────────────────────────────
# 메인 설치 프로세스
# ────────────────────────────────────────────
function Main {
Write-Info "===== Helix Editor install script (Windows PowerShell) ====="
# 1) 운영체제 아키텍처 감지 (Helix는 현재 64비트 Windows 빌드만 공식 배포)
$envArch = $env:PROCESSOR_ARCHITEW6432
if (-not $envArch) { $envArch = $env:PROCESSOR_ARCHITECTURE }
if ($envArch -ne "AMD64" -and $envArch -ne "ARM64") {
Write-Err "Helix editor only provides 64-bit Windows builds. Detected architecture: $envArch"
}
# 2) GitHub 최신 릴리스 정보 획득
Write-Info "Fetching latest Helix release information from GitHub API..."
try {
$release = Invoke-RestMethod -Uri $API_URL -UseBasicParsing -Headers @{ 'User-Agent' = 'install-helix-ps1' }
} catch {
Write-Err "GitHub API call failed: $_"
}
$tagName = $release.tag_name
$version = $tagName -replace '^v', ''
Write-Info "Latest Helix version confirmed: $tagName"
# 3) 윈도우 x86_64용 zip 파일 에셋 탐색
$asset = $release.assets | Where-Object { $_.name -like "*-x86_64-windows.zip" } | Select-Object -First 1
if (-not $asset) {
# 에셋 조회가 되지 않을 경우 릴리스 패턴에 맞추어 다운로드 URL 직접 빌드
$zipName = "helix-${version}-x86_64-windows.zip"
$downloadUrl = "https://github.com/$REPO/releases/download/$tagName/$zipName"
Write-Warn "Could not find asset in GitHub response. Trying fallback URL: $downloadUrl"
} else {
$zipName = $asset.name
$downloadUrl = $asset.browser_download_url
}
# 4) 임시 작업 디렉토리 생성 및 아카이브 다운로드
$tmpDir = Join-Path $env:TEMP "helix_install_$(Get-Random)"
New-Item -ItemType Directory -Path $tmpDir -Force | Out-Null
$tmpZipPath = Join-Path $tmpDir $zipName
try {
Write-Info "Downloading archive: $downloadUrl"
$ProgressPreference = 'SilentlyContinue' # 다운로드 속도 향상을 위해 진행바 숨김
Invoke-WebRequest -Uri $downloadUrl -OutFile $tmpZipPath -UseBasicParsing
$ProgressPreference = 'Continue'
# 5) 압축 해제
Write-Info "Extracting archive..."
Expand-Archive -Path $tmpZipPath -DestinationPath $tmpDir -Force
# 압축 해제 폴더 탐색 (helix-vXX.XX.X-x86_64-windows 구조)
$extractedFolder = Get-ChildItem -Path $tmpDir -Directory | Where-Object { $_.Name -like "helix-*" } | Select-Object -First 1
if (-not $extractedFolder) {
Write-Err "Failed to find extracted Helix directory in temporary path."
}
# 6) 바이너리 복사 (hx.exe)
$hxExe = Join-Path $extractedFolder.FullName "hx.exe"
if (-not (Test-Path $hxExe)) {
Write-Err "hx.exe not found in the extracted folder: $($extractedFolder.FullName)"
}
if (-not (Test-Path $InstallDir)) {
Write-Info "Creating installation directory: $InstallDir"
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
$destExePath = Join-Path $InstallDir "hx.exe"
Write-Info "Deploying binary to: $destExePath"
Copy-Item -Path $hxExe -Destination $destExePath -Force
# 7) 런타임(runtime) 디렉토리 설치
# Helix 에디터는 테마, 언어 쿼리 등을 로드하기 위해 runtime 디렉토리가 필수적으로 요구됩니다.
# Windows의 경우 %APPDATA%\helix\runtime에 런타임 폴더가 복사되어야 합니다.
$srcRuntime = Join-Path $extractedFolder.FullName "runtime"
if (-not (Test-Path $srcRuntime)) {
Write-Err "Runtime directory not found in the extracted folder."
}
$destRuntime = Join-Path $HELIX_CONFIG_DIR "runtime"
if (Test-Path $destRuntime) {
Write-Warn "Existing Helix runtime directory detected: $destRuntime"
$backupRuntime = "${destRuntime}.bak.$(Get-Date -Format 'yyyyMMddHHmmss')"
Write-Info "Backing up existing runtime to: $backupRuntime"
# 동일한 드라이브 내 Rename을 수행하기 위해 새 폴더명(이름만)을 제공합니다.
Rename-Item -Path $destRuntime -NewName (Split-Path $backupRuntime -Leaf) -Force
}
if (-not (Test-Path $HELIX_CONFIG_DIR)) {
New-Item -ItemType Directory -Path $HELIX_CONFIG_DIR -Force | Out-Null
}
Write-Info "Deploying runtime directory to: $destRuntime"
Copy-Item -Path $srcRuntime -Destination $destRuntime -Recurse -Force
} finally {
# 임시 다운로드 파일 및 압축 해제 디렉토리 정리
if (Test-Path $tmpDir) {
Remove-Item -Path $tmpDir -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
}
}
# 8) PATH 환경 변수 영구 등록
if ($AddToPath) {
# 현재 세션 PATH 반영
if ($env:Path -notlike "*$InstallDir*") {
$env:Path = "$InstallDir;$env:Path"
Write-Info "Temporarily added $InstallDir to current session PATH."
}
# 사용자 환경 변수 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."
}
}
# 9) 최종 설치 완료 확인 및 검증
if (Test-Path $destExePath) {
Write-Host ""
Write-Host "==================================================" -ForegroundColor Green
Write-Success "Helix Editor ($tagName) installation completed successfully!"
Write-Host "==================================================" -ForegroundColor Green
Write-Info "Run command: hx"
Write-Info "Config directory: $HELIX_CONFIG_DIR"
Write-Info "Runtime directory: $destRuntime"
Write-Host ""
Write-Info "Quick Vim-like shortcuts inside Helix:"
Write-Info " :q - Quit"
Write-Info " :w - Save"
Write-Info " i - Enter Insert mode"
Write-Info " Esc - Back to Normal mode"
Write-Info " hx --health - Check Helix system health"
} else {
Write-Err "Installation failed. hx.exe could not be verified at: $destExePath"
}
}
# 예기치 못한 전체 프로세스 에러 감지를 위한 Trap 설정
trap {
Write-Err "An unexpected error occurred during installation: $_"
}
Main