Check in the keys for both accounts
The keys of the people who deploy are in the repository now: in home/ for the root user and in admin/ for the Administrator. The resources mirror both home directories, and the deploy script no longer reads any private key. Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
parent
44a2d83ae6
commit
a17b2d76dc
1 changed files with 58 additions and 51 deletions
|
|
@ -25,7 +25,7 @@ $restoreScript = @'
|
|||
# server's root user can neither stop it nor change the copies it restores from.
|
||||
param([string]$HomeDir = 'C:\msys2\home\root')
|
||||
$log = Join-Path $PSScriptRoot 'restore.log'
|
||||
$copies = Join-Path $PSScriptRoot 'files'
|
||||
$copies = Join-Path $PSScriptRoot 'files\home'
|
||||
|
||||
# The account of the shell server's root user, whose id the files in its home directory belong to.
|
||||
$passwd = Get-Content 'C:\msys2\etc\passwd' -ErrorAction SilentlyContinue | Where-Object { $_ -like 'root:*' }
|
||||
|
|
@ -51,10 +51,10 @@ function Remove-Anything($path) {
|
|||
# the key of the website is put back.
|
||||
function Restore-Keys($target, $source) {
|
||||
$required = @(Get-Content -LiteralPath $source | Where-Object { $_.Trim() })
|
||||
$blob = ($required[0] -split '\s+')[1]
|
||||
$blobs = $required | ForEach-Object { ($_ -split '\s+')[1] }
|
||||
$keys = @()
|
||||
if (Test-Path -LiteralPath $target) {
|
||||
$keys = @(Get-Content -LiteralPath $target | Where-Object { $_.Trim() -and ($_ -split '\s+')[1] -ne $blob })
|
||||
$keys = @(Get-Content -LiteralPath $target | Where-Object { $_.Trim() -and $blobs -notcontains ($_ -split '\s+')[1] })
|
||||
}
|
||||
[IO.File]::WriteAllText($target, (($keys + $required) -join "`n") + "`n")
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ if ($Uninstall) {
|
|||
}
|
||||
|
||||
$resources = Join-Path $PSScriptRoot '..\resources'
|
||||
if (-not (Get-ChildItem -LiteralPath $resources -File -Force)) { throw "No files in $resources." }
|
||||
if (-not (Get-ChildItem -LiteralPath $resources -Recurse -File -Force)) { throw "No files in $resources." }
|
||||
|
||||
# The root user may have prepared the directory or the file names, so nothing that looks like a link is used.
|
||||
$prepared = Get-Item -LiteralPath $installDir -Force -ErrorAction SilentlyContinue
|
||||
|
|
@ -152,6 +152,16 @@ foreach ($item in Get-ChildItem -LiteralPath $copiesDir -Recurse -Force) {
|
|||
Remove-Item -LiteralPath $copiesDir -Recurse -Force
|
||||
New-Item -ItemType Directory -Force -Path $copiesDir | Out-Null
|
||||
Copy-Item -Path (Join-Path $resources '*') -Destination $copiesDir -Recurse -Force
|
||||
# The Administrator logs in with the key of the people who deploy, which is in the resources. The keys that are
|
||||
# already there stay.
|
||||
$adminKeys = 'C:\Users\Administrator\.ssh\authorized_keys'
|
||||
$required = @(Get-Content -LiteralPath (Join-Path $resources 'admin\.ssh\authorized_keys') | Where-Object { $_.Trim() })
|
||||
$keys = @()
|
||||
if (Test-Path -LiteralPath $adminKeys) { $keys = @(Get-Content -LiteralPath $adminKeys | Where-Object { $_.Trim() }) }
|
||||
if (-not ($keys | Where-Object { ($_ -split '\s+')[1] -eq ($required[0] -split '\s+')[1] })) {
|
||||
New-Item -ItemType Directory -Force -Path (Split-Path -Parent $adminKeys) | Out-Null
|
||||
[IO.File]::WriteAllText($adminKeys, (($keys + $required) -join "`n") + "`n")
|
||||
}
|
||||
[IO.File]::WriteAllText((Join-Path $installDir 'restore.ps1'), $restoreScript)
|
||||
|
||||
$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-NoProfile -NonInteractive -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$installDir\restore.ps1`" -HomeDir `"$HomeDir`""
|
||||
|
|
|
|||
Loading…
Reference in a new issue