27 lines
1.5 KiB
PowerShell
27 lines
1.5 KiB
PowerShell
# 빌드머신에 vd-build 공개키 (재)설치 — .env 자격증명으로 접속해 authorized_keys 정리.
|
|
# 사용: pwsh -File build\remote\install-buildkey.ps1
|
|
$ErrorActionPreference = 'Stop'
|
|
$repo = Split-Path $PSScriptRoot -Parent | Split-Path -Parent
|
|
$cfg = @{}
|
|
Get-Content (Join-Path $repo '.env') | ForEach-Object {
|
|
$line = $_.TrimEnd("`r")
|
|
if ($line -match '^([A-Z_]+)=(.*)$') { $cfg[$matches[1]] = $matches[2] }
|
|
}
|
|
$pubkey = (Get-Content "$env:USERPROFILE\.ssh\id_ed25519_vd.pub" -Raw).Trim()
|
|
$machines = @(
|
|
@{ Name = 'MAC'; Host = $cfg['MAC_OS_HOST']; User = $cfg['MAC_OS_USER']; Pw = $cfg['MAC_OS_PASSWORD'] },
|
|
@{ Name = 'LINUX'; Host = $cfg['LINUX_OS_HOST']; User = $cfg['LINUX_OS_USER']; Pw = $cfg['LINUX_OS_PASSWORD'] }
|
|
)
|
|
foreach ($m in $machines) {
|
|
$sec = ConvertTo-SecureString $m.Pw -AsPlainText -Force
|
|
$cred = [Management.Automation.PSCredential]::new($m.User, $sec)
|
|
$s = New-SSHSession -ComputerName $m.Host -Credential $cred -AcceptKey -ConnectionTimeout 15 -ErrorAction Stop
|
|
$cmds = @(
|
|
'mkdir -p ~/.ssh && chmod 700 ~/.ssh',
|
|
"sed -i '/ vd-build$/d' ~/.ssh/authorized_keys 2>/dev/null; echo '$pubkey' >> ~/.ssh/authorized_keys",
|
|
'chmod 600 ~/.ssh/authorized_keys'
|
|
)
|
|
foreach ($c in $cmds) { Invoke-SSHCommand -SessionId $s.SessionId -Command $c -TimeOut 10 | Out-Null }
|
|
Remove-SSHSession -SessionId $s.SessionId | Out-Null
|
|
Write-Output "$($m.Name) ($($m.Host)): build key installed"
|
|
}
|