#Requires -Version 5.1 Set-StrictMode -Version 2.0 $ErrorActionPreference = 'Stop' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $Repository = 'https://i.3001.co.kr' $ExpectedCliSha256 = 'bf1da57cc190bf0ad5e5189e834cbe4f36814eea7a8243eb22f09fab2be6dfb6' $Root = Join-Path $env:LOCALAPPDATA 'Programs\3001' $App = Join-Path $Root 'app' $Bin = Join-Path $Root 'bin' $Downloads = Join-Path $env:USERPROFILE 'Downloads' $Stamp = Get-Date -Format 'yyyyMMdd-HHmmss' $LogPath = Join-Path $Downloads "3001_BOOTSTRAP_$Stamp.log" $TempFile = Join-Path $env:TEMP "3001-cli-$([guid]::NewGuid().ToString('N')).ps1" $TranscriptStarted = $false try { Start-Transcript -LiteralPath $LogPath -Force | Out-Null $TranscriptStarted = $true Write-Host '' Write-Host ('=' * 64) Write-Host ' 3001 CLI 설치' Write-Host ('=' * 64) Write-Host "저장소: $Repository" Write-Host "설치 위치: $Root" Write-Host '' foreach ($path in @($Root, $App, $Bin)) { if (-not (Test-Path -LiteralPath $path)) { New-Item -ItemType Directory -Path $path -Force | Out-Null } } $cliUri = "$Repository/3001.ps1" Write-Host "다운로드: $cliUri" Invoke-WebRequest -Uri $cliUri -OutFile $TempFile -UseBasicParsing $ActualCliSha256 = (Get-FileHash -LiteralPath $TempFile -Algorithm SHA256).Hash.ToLowerInvariant() Write-Host "예상 SHA-256: $ExpectedCliSha256" Write-Host "실제 SHA-256: $ActualCliSha256" if ($ActualCliSha256 -ne $ExpectedCliSha256) { throw '3001 CLI의 SHA-256 검증에 실패했습니다. 설치를 중단합니다.' } $cliPath = Join-Path $App '3001.ps1' Move-Item -LiteralPath $TempFile -Destination $cliPath -Force $launcherPath = Join-Path $Bin '3001.cmd' $launcher = "@echo off`r`npowershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -File `"$cliPath`" %*`r`n" Set-Content -LiteralPath $launcherPath -Value $launcher -Encoding ASCII $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') $pathParts = @() if (-not [string]::IsNullOrWhiteSpace($userPath)) { $pathParts = @($userPath -split ';' | Where-Object { $_ }) } $alreadyRegistered = $false foreach ($part in $pathParts) { if ($part.TrimEnd('\') -ieq $Bin.TrimEnd('\')) { $alreadyRegistered = $true break } } if (-not $alreadyRegistered) { $newUserPath = if ([string]::IsNullOrWhiteSpace($userPath)) { $Bin } else { "$userPath;$Bin" } [Environment]::SetEnvironmentVariable('Path', $newUserPath, 'User') } if (@($env:Path -split ';') -notcontains $Bin) { $env:Path = "$Bin;$env:Path" } Write-Host '' Write-Host '3001 CLI 설치 완료' -ForegroundColor Green Write-Host '바로 사용할 명령:' Write-Host ' 3001 list' Write-Host ' 3001 pcdiag' Write-Host '' & $launcherPath version } catch { Write-Host '' Write-Host "설치 실패: $($_.Exception.Message)" -ForegroundColor Red throw } finally { if (Test-Path -LiteralPath $TempFile) { Remove-Item -LiteralPath $TempFile -Force -ErrorAction SilentlyContinue } if ($TranscriptStarted) { try { Stop-Transcript | Out-Null } catch { } } Write-Host '' Write-Host "로그 파일: $LogPath" }