跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

windows-powershell-media.smoke.ps1

44 行 · 3.2 KB历史下载
1#requires -Version 5.1
2# Exercise the packaged media builder on a disposable Windows development runner.
3[CmdletBinding()]
4param([Parameter(Mandatory)][string]$GuestToolsDirectory)
5$ErrorActionPreference = 'Stop'
6if ([Environment]::OSVersion.Platform -ne 'Win32NT' -or ![Environment]::Is64BitProcess) {
7 throw 'The PowerShell guest media smoke requires a 64-bit Windows runner.'
8}
9. (Join-Path $GuestToolsDirectory 'windows-guest-media.ps1')
10$scratch = [IO.Directory]::CreateDirectory((Join-Path ([IO.Path]::GetTempPath()) ('Cage guest media ' + [guid]::NewGuid().ToString('N'))))
11try {
12 $iso = Join-Path $scratch.FullName 'guest-tools.iso'
13 New-WindowsGuestAnswerISO $iso ([xml]'<unattend xmlns="urn:schemas-microsoft-com:unattend"/>')
14 $null = Mount-DiskImage -ImagePath $iso -StorageType ISO -Access ReadOnly
15 try {
16 $timer = [Diagnostics.Stopwatch]::StartNew()
17 do {
18 $volume = @(Get-DiskImage -ImagePath $iso | Get-Volume -ErrorAction SilentlyContinue)
19 if ($volume.Count -eq 1 -and $volume[0].DriveLetter) { break }
20 Start-Sleep -Milliseconds 250
21 } while ($timer.Elapsed.TotalSeconds -lt 15)
22 if ($volume.Count -ne 1 -or !$volume[0].DriveLetter) { throw 'Cage guest tools DVD did not acquire a drive letter.' }
23 $disc = [IO.DriveInfo]::new(('{0}:\' -f $volume[0].DriveLetter))
24 if ($disc.DriveFormat -ne 'UDF' -or $disc.VolumeLabel -ne 'CAGE_ANSWER') { throw 'Expected the Cage UDF answer DVD.' }
25 $root = $disc.RootDirectory.FullName
26 $answer = [xml][IO.File]::ReadAllText((Join-Path $root 'Autounattend.xml'))
27 $ns = [Xml.XmlNamespaceManager]::new($answer.NameTable)
28 $ns.AddNamespace('u', 'urn:schemas-microsoft-com:unattend')
29 $steps = $answer.SelectNodes('/u:unattend/u:settings[@pass="specialize"]/u:component[@name="Microsoft-Windows-Deployment"]/u:RunSynchronous/u:RunSynchronousCommand/u:Path', $ns)
30 $installerHash = (Get-FileHash -LiteralPath (Join-Path $root 'install.cmd') -Algorithm SHA256).Hash
31 if ($steps.Count -ne 1 -or !$steps[0].InnerText.Contains($installerHash)) { throw 'The answer file does not pin the guest installer on the DVD.' }
32 $zip = Join-Path $root 'PowerShell.zip'
33 if ((Get-FileHash -LiteralPath $zip -Algorithm SHA256).Hash -ne $GuestPowerShellSHA256) { throw 'PowerShell archive on the DVD has an unexpected digest.' }
34 $runtime = Join-Path $scratch.FullName 'runtime'
35 Add-Type -AssemblyName System.IO.Compression.FileSystem
36 [IO.Compression.ZipFile]::ExtractToDirectory($zip, $runtime)
37 } finally { $null = Dismount-DiskImage -ImagePath $iso }
38
39 $version = @(& (Join-Path $runtime 'pwsh.exe') -NoLogo -NoProfile -NonInteractive -Command '$PSVersionTable.PSVersion.ToString(); [Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString()')
40 if ($LASTEXITCODE -ne 0 -or $version.Count -ne 2 -or $version[0] -ne $GuestPowerShellVersion -or $version[1] -ne 'X64') {
41 throw "Unexpected guest PowerShell runtime response: $version"
42 }
43 Write-Output "Verified packaged UDF answer DVD and native Windows x64 PowerShell $GuestPowerShellVersion."
44} finally { $scratch.Delete($true) }