agent-dev-env 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/LICENSE +21 -0
  2. package/dist/assets/bridge/bridge.js +202 -0
  3. package/dist/assets/guest/guest-agent-mac.js +586 -0
  4. package/dist/assets/guest/guest-agent-ubuntu.js +481 -0
  5. package/dist/assets/guest/guest-agent-windows.js +466 -0
  6. package/dist/assets/images/mac/CHANGELOG.md +265 -0
  7. package/dist/assets/images/mac/README.md +63 -0
  8. package/dist/assets/images/mac/sandbox.pkr.hcl +468 -0
  9. package/dist/assets/images/mac/vars/sandbox-macos-tahoe.pkrvars.hcl +39 -0
  10. package/dist/assets/images/ubuntu-arm64-vmware/CHANGELOG.md +239 -0
  11. package/dist/assets/images/ubuntu-arm64-vmware/README.md +177 -0
  12. package/dist/assets/images/ubuntu-arm64-vmware/autoinstall/meta-data +2 -0
  13. package/dist/assets/images/ubuntu-arm64-vmware/autoinstall/user-data +34 -0
  14. package/dist/assets/images/ubuntu-arm64-vmware/sandbox.pkr.hcl +776 -0
  15. package/dist/assets/images/ubuntu-arm64-vmware/vars/sandbox-ubuntu-24-04-arm64-vmware.pkrvars.hcl +71 -0
  16. package/dist/assets/images/windows-arm64-qemu/CHANGELOG.md +209 -0
  17. package/dist/assets/images/windows-arm64-qemu/README.md +142 -0
  18. package/dist/assets/images/windows-arm64-qemu/autounattend.xml +325 -0
  19. package/dist/assets/images/windows-arm64-qemu/qemu-with-tpm.sh +170 -0
  20. package/dist/assets/images/windows-arm64-qemu/sandbox.pkr.hcl +1012 -0
  21. package/dist/assets/images/windows-arm64-qemu/vars/sandbox-windows-11-arm64-qemu.pkrvars.hcl +83 -0
  22. package/dist/assets/images/windows-arm64-vmware/CHANGELOG.md +270 -0
  23. package/dist/assets/images/windows-arm64-vmware/README.md +171 -0
  24. package/dist/assets/images/windows-arm64-vmware/autounattend.xml +311 -0
  25. package/dist/assets/images/windows-arm64-vmware/sandbox.pkr.hcl +1036 -0
  26. package/dist/assets/images/windows-arm64-vmware/vars/sandbox-windows-11-arm64-vmware.pkrvars.hcl +83 -0
  27. package/dist/assets/rules/agent-rules-linux.md +68 -0
  28. package/dist/assets/rules/agent-rules.md +71 -0
  29. package/dist/assets/watchdog/watch-build-ocr.swift +40 -0
  30. package/dist/assets/watchdog/watch-build.py +275 -0
  31. package/dist/cli.js +52 -0
  32. package/dist/commands/delete.js +179 -0
  33. package/dist/commands/doctor.js +165 -0
  34. package/dist/commands/list.js +38 -0
  35. package/dist/commands/not-yet.js +15 -0
  36. package/dist/commands/register.js +150 -0
  37. package/dist/commands/run.js +65 -0
  38. package/dist/commands/status.js +142 -0
  39. package/dist/commands/stop.js +186 -0
  40. package/dist/commands/sync.js +98 -0
  41. package/dist/lib/exec.js +250 -0
  42. package/dist/lib/ghcr.js +82 -0
  43. package/dist/lib/git.js +100 -0
  44. package/dist/lib/logger.js +87 -0
  45. package/dist/lib/network.js +63 -0
  46. package/dist/lib/paths.js +116 -0
  47. package/dist/lib/platform.js +87 -0
  48. package/dist/lib/prompt.js +66 -0
  49. package/dist/lib/qemu.js +373 -0
  50. package/dist/lib/regex.js +9 -0
  51. package/dist/lib/ssh.js +230 -0
  52. package/dist/lib/tart.js +210 -0
  53. package/dist/lib/template.js +35 -0
  54. package/dist/lib/vars.js +99 -0
  55. package/dist/lib/vmrun.js +334 -0
  56. package/dist/lifecycle/build-macos.js +23 -0
  57. package/dist/lifecycle/build-qemu.js +204 -0
  58. package/dist/lifecycle/build-shared.js +355 -0
  59. package/dist/lifecycle/build-ubuntu.js +184 -0
  60. package/dist/lifecycle/build-watchdog.js +146 -0
  61. package/dist/lifecycle/build-windows-vmware.js +112 -0
  62. package/dist/lifecycle/build.js +55 -0
  63. package/dist/lifecycle/catalog.js +165 -0
  64. package/dist/lifecycle/deploy.js +161 -0
  65. package/dist/lifecycle/tag.js +77 -0
  66. package/dist/lifecycle/watch-build.js +64 -0
  67. package/dist/runners/bridges.js +153 -0
  68. package/dist/runners/framework.js +66 -0
  69. package/dist/runners/macos-bridges.js +143 -0
  70. package/dist/runners/macos-guest.js +76 -0
  71. package/dist/runners/macos-rules.js +77 -0
  72. package/dist/runners/macos-summary.js +145 -0
  73. package/dist/runners/macos.js +258 -0
  74. package/dist/runners/openchamber.js +60 -0
  75. package/dist/runners/options.js +56 -0
  76. package/dist/runners/qemu-image.js +183 -0
  77. package/dist/runners/rules.js +49 -0
  78. package/dist/runners/ubuntu-bridges.js +154 -0
  79. package/dist/runners/ubuntu-guest.js +136 -0
  80. package/dist/runners/ubuntu-image.js +26 -0
  81. package/dist/runners/ubuntu-rules.js +86 -0
  82. package/dist/runners/ubuntu-shared.js +65 -0
  83. package/dist/runners/ubuntu-summary.js +141 -0
  84. package/dist/runners/ubuntu.js +117 -0
  85. package/dist/runners/vmware-common.js +158 -0
  86. package/dist/runners/vmware-image.js +242 -0
  87. package/dist/runners/windows-autologon.js +119 -0
  88. package/dist/runners/windows-bridges.js +136 -0
  89. package/dist/runners/windows-guest.js +213 -0
  90. package/dist/runners/windows-image.js +23 -0
  91. package/dist/runners/windows-qemu-summary.js +85 -0
  92. package/dist/runners/windows-qemu.js +189 -0
  93. package/dist/runners/windows-shared.js +68 -0
  94. package/dist/runners/windows-summary.js +104 -0
  95. package/dist/runners/windows.js +96 -0
  96. package/dist/settings/common.js +107 -0
  97. package/dist/settings/macos-copy.js +223 -0
  98. package/dist/settings/macos.js +41 -0
  99. package/dist/settings/ubuntu-copy.js +223 -0
  100. package/dist/settings/ubuntu.js +68 -0
  101. package/package.json +52 -0
@@ -0,0 +1,325 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!--
3
+ autounattend.xml — Windows 11 ARM64 unattended install for the Packer
4
+ QEMU build (images/windows-arm64-qemu/sandbox.pkr.hcl).
5
+
6
+ Windows Setup probes attached removable media for Autounattend.xml at
7
+ the root and applies it before the language picker. The CD is built by
8
+ Packer's cd_files from this file + the drivers/ tree staged by the
9
+ build flow (the ARM64 viostor/vioscsi/NetKVM driver subset
10
+ extracted from virtio-win.iso). WinPE drive-letter enumeration on
11
+ ARM64 + EFI is non-deterministic, so the driver paths below list
12
+ D:..G: candidates.
13
+
14
+ Schema components carry processorArchitecture="arm64". The
15
+ Administrator password must stay in sync with the winrm_password
16
+ variable in vars/sandbox-windows-11-arm64-qemu.pkrvars.hcl — change both together.
17
+
18
+ References:
19
+ - https://learn.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/
20
+ - Recipe verified end-to-end on Apple Silicon in the mac-vms project
21
+ (https://github.com/bbirkinbine/mac-vms, packer/windows-11-arm64/).
22
+ -->
23
+ <unattend xmlns="urn:schemas-microsoft-com:unattend">
24
+
25
+ <settings pass="windowsPE">
26
+
27
+ <!-- Virtio drivers for the QEMU emulated disk + NIC. Without viostor
28
+ WinPE can't see the boot disk (the template uses disk_interface
29
+ "virtio"); without NetKVM the NIC has no driver and WinRM never
30
+ comes up. -->
31
+ <component name="Microsoft-Windows-PnpCustomizationsWinPE"
32
+ processorArchitecture="arm64"
33
+ publicKeyToken="31bf3856ad364e35"
34
+ language="neutral" versionScope="nonSxS"
35
+ xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
36
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
37
+ <DriverPaths>
38
+ <PathAndCredentials wcm:action="add" wcm:keyValue="viostor-d">
39
+ <Path>D:\drivers\staging\viostor</Path>
40
+ </PathAndCredentials>
41
+ <PathAndCredentials wcm:action="add" wcm:keyValue="viostor-e">
42
+ <Path>E:\drivers\staging\viostor</Path>
43
+ </PathAndCredentials>
44
+ <PathAndCredentials wcm:action="add" wcm:keyValue="viostor-f">
45
+ <Path>F:\drivers\staging\viostor</Path>
46
+ </PathAndCredentials>
47
+ <PathAndCredentials wcm:action="add" wcm:keyValue="viostor-g">
48
+ <Path>G:\drivers\staging\viostor</Path>
49
+ </PathAndCredentials>
50
+ <PathAndCredentials wcm:action="add" wcm:keyValue="vioscsi-d">
51
+ <Path>D:\drivers\staging\vioscsi</Path>
52
+ </PathAndCredentials>
53
+ <PathAndCredentials wcm:action="add" wcm:keyValue="vioscsi-e">
54
+ <Path>E:\drivers\staging\vioscsi</Path>
55
+ </PathAndCredentials>
56
+ <PathAndCredentials wcm:action="add" wcm:keyValue="vioscsi-f">
57
+ <Path>F:\drivers\staging\vioscsi</Path>
58
+ </PathAndCredentials>
59
+ <PathAndCredentials wcm:action="add" wcm:keyValue="vioscsi-g">
60
+ <Path>G:\drivers\staging\vioscsi</Path>
61
+ </PathAndCredentials>
62
+ <PathAndCredentials wcm:action="add" wcm:keyValue="NetKVM-d">
63
+ <Path>D:\drivers\staging\NetKVM</Path>
64
+ </PathAndCredentials>
65
+ <PathAndCredentials wcm:action="add" wcm:keyValue="NetKVM-e">
66
+ <Path>E:\drivers\staging\NetKVM</Path>
67
+ </PathAndCredentials>
68
+ <PathAndCredentials wcm:action="add" wcm:keyValue="NetKVM-f">
69
+ <Path>F:\drivers\staging\NetKVM</Path>
70
+ </PathAndCredentials>
71
+ <PathAndCredentials wcm:action="add" wcm:keyValue="NetKVM-g">
72
+ <Path>G:\drivers\staging\NetKVM</Path>
73
+ </PathAndCredentials>
74
+ </DriverPaths>
75
+ </component>
76
+
77
+ <component name="Microsoft-Windows-International-Core-WinPE"
78
+ processorArchitecture="arm64"
79
+ publicKeyToken="31bf3856ad364e35"
80
+ language="neutral" versionScope="nonSxS"
81
+ xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
82
+ <SetupUILanguage>
83
+ <UILanguage>en-US</UILanguage>
84
+ </SetupUILanguage>
85
+ <InputLocale>en-US</InputLocale>
86
+ <SystemLocale>en-US</SystemLocale>
87
+ <UILanguage>en-US</UILanguage>
88
+ <UserLocale>en-US</UserLocale>
89
+ </component>
90
+
91
+ <component name="Microsoft-Windows-Setup"
92
+ processorArchitecture="arm64"
93
+ publicKeyToken="31bf3856ad364e35"
94
+ language="neutral" versionScope="nonSxS"
95
+ xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
96
+
97
+ <!-- Pure-UEFI layout for ARM64: ESP + MSR + Windows. -->
98
+ <DiskConfiguration>
99
+ <Disk wcm:action="add">
100
+ <DiskID>0</DiskID>
101
+ <WillWipeDisk>true</WillWipeDisk>
102
+ <CreatePartitions>
103
+ <CreatePartition wcm:action="add">
104
+ <Order>1</Order>
105
+ <Type>EFI</Type>
106
+ <Size>300</Size>
107
+ </CreatePartition>
108
+ <CreatePartition wcm:action="add">
109
+ <Order>2</Order>
110
+ <Type>MSR</Type>
111
+ <Size>16</Size>
112
+ </CreatePartition>
113
+ <CreatePartition wcm:action="add">
114
+ <Order>3</Order>
115
+ <Type>Primary</Type>
116
+ <Extend>true</Extend>
117
+ </CreatePartition>
118
+ </CreatePartitions>
119
+ <ModifyPartitions>
120
+ <ModifyPartition wcm:action="add">
121
+ <Order>1</Order>
122
+ <PartitionID>1</PartitionID>
123
+ <Format>FAT32</Format>
124
+ <Label>System</Label>
125
+ </ModifyPartition>
126
+ <ModifyPartition wcm:action="add">
127
+ <Order>2</Order>
128
+ <PartitionID>2</PartitionID>
129
+ </ModifyPartition>
130
+ <ModifyPartition wcm:action="add">
131
+ <Order>3</Order>
132
+ <PartitionID>3</PartitionID>
133
+ <Format>NTFS</Format>
134
+ <Label>Windows</Label>
135
+ <Letter>C</Letter>
136
+ </ModifyPartition>
137
+ </ModifyPartitions>
138
+ </Disk>
139
+ </DiskConfiguration>
140
+
141
+ <!-- Multi-edition ISO: pick Pro by image name. If the release uses
142
+ a different SKU label (e.g. "Windows 11 Pro for ARM"), the
143
+ install halts — check with `dism /Get-WimInfo` on the ISO. -->
144
+ <ImageInstall>
145
+ <OSImage>
146
+ <InstallTo>
147
+ <DiskID>0</DiskID>
148
+ <PartitionID>3</PartitionID>
149
+ </InstallTo>
150
+ <InstallFrom>
151
+ <MetaData wcm:action="add">
152
+ <Key>/IMAGE/NAME</Key>
153
+ <Value>Windows 11 Pro</Value>
154
+ </MetaData>
155
+ </InstallFrom>
156
+ </OSImage>
157
+ </ImageInstall>
158
+
159
+ <UserData>
160
+ <AcceptEula>true</AcceptEula>
161
+ <FullName>agent-sandbox</FullName>
162
+ <Organization>agent-sandbox</Organization>
163
+ <!-- Generic install key for Windows 11 Pro: lets Setup complete
164
+ without prompting; does NOT activate (the sandbox runs
165
+ unactivated with a watermark). -->
166
+ <ProductKey>
167
+ <Key>VK7JG-NPHTM-C97JM-9MPGT-3V66T</Key>
168
+ <WillShowUI>OnError</WillShowUI>
169
+ </ProductKey>
170
+ </UserData>
171
+
172
+ <!-- Bypass the Win11 hardware-requirements checks. swtpm provides a
173
+ real TPM 2.0 and edk2 provides UEFI Secure Boot, but `-cpu
174
+ host` advertises Apple Silicon to the guest and Apple Silicon
175
+ is not on Microsoft's supported CPU list, so BypassCPUCheck is
176
+ mandatory; the rest are belt-and-braces. RunSynchronous in the
177
+ windowsPE pass runs strictly before Setup's hardware probe. -->
178
+ <RunSynchronous>
179
+ <RunSynchronousCommand wcm:action="add">
180
+ <Order>1</Order>
181
+ <Path>reg add HKLM\System\Setup\LabConfig /v BypassTPMCheck /t REG_DWORD /d 1 /f</Path>
182
+ </RunSynchronousCommand>
183
+ <RunSynchronousCommand wcm:action="add">
184
+ <Order>2</Order>
185
+ <Path>reg add HKLM\System\Setup\LabConfig /v BypassSecureBootCheck /t REG_DWORD /d 1 /f</Path>
186
+ </RunSynchronousCommand>
187
+ <RunSynchronousCommand wcm:action="add">
188
+ <Order>3</Order>
189
+ <Path>reg add HKLM\System\Setup\LabConfig /v BypassRAMCheck /t REG_DWORD /d 1 /f</Path>
190
+ </RunSynchronousCommand>
191
+ <RunSynchronousCommand wcm:action="add">
192
+ <Order>4</Order>
193
+ <Path>reg add HKLM\System\Setup\LabConfig /v BypassCPUCheck /t REG_DWORD /d 1 /f</Path>
194
+ </RunSynchronousCommand>
195
+ <RunSynchronousCommand wcm:action="add">
196
+ <Order>5</Order>
197
+ <Path>reg add HKLM\System\Setup\LabConfig /v BypassStorageCheck /t REG_DWORD /d 1 /f</Path>
198
+ </RunSynchronousCommand>
199
+ </RunSynchronous>
200
+ </component>
201
+ </settings>
202
+
203
+ <settings pass="specialize">
204
+ <component name="Microsoft-Windows-Shell-Setup"
205
+ processorArchitecture="arm64"
206
+ publicKeyToken="31bf3856ad364e35"
207
+ language="neutral" versionScope="nonSxS"
208
+ xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
209
+ <!-- NetBIOS computer names are limited to 15 chars — longer names
210
+ fail the specialize pass with hrResult=0x80220005. -->
211
+ <ComputerName>win11-sandbox</ComputerName>
212
+ <TimeZone>UTC</TimeZone>
213
+ <RegisteredOrganization>agent-sandbox</RegisteredOrganization>
214
+ <RegisteredOwner>agent-sandbox</RegisteredOwner>
215
+ </component>
216
+ <component name="Microsoft-Windows-International-Core"
217
+ processorArchitecture="arm64"
218
+ publicKeyToken="31bf3856ad364e35"
219
+ language="neutral" versionScope="nonSxS"
220
+ xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
221
+ <InputLocale>en-US</InputLocale>
222
+ <SystemLocale>en-US</SystemLocale>
223
+ <UILanguage>en-US</UILanguage>
224
+ <UserLocale>en-US</UserLocale>
225
+ </component>
226
+ </settings>
227
+
228
+ <settings pass="oobeSystem">
229
+ <component name="Microsoft-Windows-Shell-Setup"
230
+ processorArchitecture="arm64"
231
+ publicKeyToken="31bf3856ad364e35"
232
+ language="neutral" versionScope="nonSxS"
233
+ xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
234
+
235
+ <OOBE>
236
+ <HideEULAPage>true</HideEULAPage>
237
+ <HideLocalAccountScreen>true</HideLocalAccountScreen>
238
+ <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen>
239
+ <!-- Bypasses the Microsoft-account requirement on Win11 24H2. If a
240
+ future release blocks this too, add BYPASSNRO registry writes
241
+ via RunSynchronous in the specialize pass. -->
242
+ <HideOnlineAccountScreens>true</HideOnlineAccountScreens>
243
+ <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
244
+ <NetworkLocation>Work</NetworkLocation>
245
+ <ProtectYourPC>3</ProtectYourPC>
246
+ <SkipUserOOBE>true</SkipUserOOBE>
247
+ <SkipMachineOOBE>true</SkipMachineOOBE>
248
+ </OOBE>
249
+
250
+ <UserAccounts>
251
+ <AdministratorPassword>
252
+ <!-- MUST match winrm_password in the vars file. -->
253
+ <Value>sandbox1</Value>
254
+ <PlainText>true</PlainText>
255
+ </AdministratorPassword>
256
+ <LocalAccounts>
257
+ <LocalAccount wcm:action="add">
258
+ <Name>Administrator</Name>
259
+ <Group>Administrators</Group>
260
+ <Password>
261
+ <Value>sandbox1</Value>
262
+ <PlainText>true</PlainText>
263
+ </Password>
264
+ <Description>Local admin; also the SSH/RDP account of the sandbox.</Description>
265
+ <DisplayName>Administrator</DisplayName>
266
+ </LocalAccount>
267
+ </LocalAccounts>
268
+ </UserAccounts>
269
+
270
+ <!-- LogonCount=1: exactly one auto-login (the first OOBE boot, where
271
+ FirstLogonCommands brings up WinRM); Windows clears
272
+ AutoAdminLogon itself afterwards. -->
273
+ <AutoLogon>
274
+ <Username>Administrator</Username>
275
+ <Password>
276
+ <Value>sandbox1</Value>
277
+ <PlainText>true</PlainText>
278
+ </Password>
279
+ <Enabled>true</Enabled>
280
+ <LogonCount>1</LogonCount>
281
+ </AutoLogon>
282
+
283
+ <!-- Bring up WinRM so Packer's provisioners can connect.
284
+ Order is load-bearing:
285
+ 1. Install the staged ARM64 virtio drivers into the running
286
+ OS's driver store — NetKVM does NOT survive the WinPE ->
287
+ installed-system handoff (install.wim carries no ARM64
288
+ virtio NIC driver), so the NIC is dead until pnputil
289
+ registers it. Drive letters differ from the WinPE phase,
290
+ so scan D:..I: for the staging tree.
291
+ 2. Wait for the NIC to attach and complete DHCP, then force
292
+ the network category to Private (WinRM's AllowUnencrypted
293
+ refuses to apply on Public).
294
+ 3. Enable + configure WinRM (Basic + AllowUnencrypted) and
295
+ open port 5985. -->
296
+ <FirstLogonCommands>
297
+ <SynchronousCommand wcm:action="add">
298
+ <Order>1</Order>
299
+ <Description>Install ARM64 virtio drivers into the driver store</Description>
300
+ <CommandLine>powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; $found=$false; foreach ($l in 'D','E','F','G','H','I') { $p = ${l} + ':\drivers\staging'; if (Test-Path $p) { Get-ChildItem -Path $p -Recurse -Filter *.inf | ForEach-Object { pnputil.exe /add-driver $_.FullName /install | Out-Null }; $found=$true; break } }; if (-not $found) { Write-Error 'drivers\staging not found on D:..I: — unattend CD missing or relocated' }"</CommandLine>
301
+ </SynchronousCommand>
302
+ <SynchronousCommand wcm:action="add">
303
+ <Order>2</Order>
304
+ <Description>Wait for network and force profile to Private</Description>
305
+ <CommandLine>powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "for ($i=0; $i -lt 60; $i++) { $p = Get-NetConnectionProfile -ErrorAction SilentlyContinue; if ($p) { break }; Start-Sleep 2 }; Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private"</CommandLine>
306
+ </SynchronousCommand>
307
+ <SynchronousCommand wcm:action="add">
308
+ <Order>3</Order>
309
+ <Description>Enable WinRM service</Description>
310
+ <CommandLine>powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Set-Service -Name WinRM -StartupType Automatic; Start-Service WinRM"</CommandLine>
311
+ </SynchronousCommand>
312
+ <SynchronousCommand wcm:action="add">
313
+ <Order>4</Order>
314
+ <Description>Configure WinRM listener and auth</Description>
315
+ <CommandLine>powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "winrm quickconfig -quiet; winrm set winrm/config/service '@{AllowUnencrypted=\"true\"}'; winrm set winrm/config/service/auth '@{Basic=\"true\"}'"</CommandLine>
316
+ </SynchronousCommand>
317
+ <SynchronousCommand wcm:action="add">
318
+ <Order>5</Order>
319
+ <Description>Open firewall for WinRM</Description>
320
+ <CommandLine>powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "New-NetFirewallRule -Name 'WinRM HTTP-In' -DisplayName 'WinRM HTTP-In' -Profile Any -LocalPort 5985 -Protocol TCP -Action Allow"</CommandLine>
321
+ </SynchronousCommand>
322
+ </FirstLogonCommands>
323
+ </component>
324
+ </settings>
325
+ </unattend>
@@ -0,0 +1,170 @@
1
+ #!/bin/bash
2
+ # qemu-with-tpm.sh — wrapper around qemu-system-aarch64 that fills in the
3
+ # gaps Packer's qemu plugin can't generate for an ARM64 Windows build.
4
+ #
5
+ # Packer's qemu plugin treats `qemuargs` as a *replacement* for all
6
+ # auto-generated args, not an append — so instead of qemuargs, this script
7
+ # sits between Packer and qemu: Packer invokes it as if it were qemu, it
8
+ # forwards every arg verbatim (with surgical edits) and appends its
9
+ # additions at the end.
10
+ #
11
+ # What it adds / rewrites:
12
+ #
13
+ # 1. TPM 2.0 via the swtpm Unix socket (Windows 11 system requirement).
14
+ # 2. `ramfb` simple linear framebuffer. ARM `virt` machines ship no
15
+ # graphics card by default; ramfb works because EFI firmware writes
16
+ # to it directly (via GOP) — virtio-gpu needs guest drivers the
17
+ # Windows installer doesn't have yet. (The build stages the ARM64
18
+ # viogpudo driver onto the unattend CD anyway, so the *runtime*
19
+ # runner can boot the built image with virtio-gpu-pci and the guest
20
+ # driver store resolves it.)
21
+ # 3. USB controller + keyboard + tablet (no input devices otherwise;
22
+ # usb-tablet gives absolute pointing).
23
+ # 4. virtio-win.iso attached as a CD-ROM via usb-storage, so the built
24
+ # image can install virtio-win-guest-tools (full driver suite + qemu
25
+ # guest agent). The boot-critical ARM64 driver subset WinPE needs at
26
+ # install time is bundled into the unattend CD by the build flow, not
27
+ # this CD.
28
+ # 5. Rewrite of Packer-generated CD-ROM drives to usb-storage. QEMU's
29
+ # ARM `virt` machine has no IDE/SATA controller, and WinPE has no
30
+ # in-box driver for the plugin's default CD attachment; it does
31
+ # include the xHCI/USB stack, so usb-storage CDs are visible
32
+ # immediately.
33
+ #
34
+ # USB enumeration order is load-bearing: EDK2 walks USB devices in argv
35
+ # order looking for `\EFI\Boot\bootaa64.efi`. The install ISO's
36
+ # usb-storage device MUST come before virtio-win.iso's, otherwise EDK2
37
+ # bails to the EFI Shell instead of booting Windows Setup.
38
+ #
39
+ # Required env (exported by the agent-dev-env CLI build flow):
40
+ # SWTPM_SOCK — absolute path to the swtpm Unix socket
41
+ # VIRTIO_WIN_ISO_PATH — absolute path to virtio-win.iso
42
+ # QEMU_WITH_TPM_LOG — log file for the final qemu invocation
43
+ # (build/windows-arm64-qemu/packer_cache/
44
+ # qemu-with-tpm.cmd.log)
45
+ #
46
+ # Adapted from bbirkinbine/mac-vms (MIT):
47
+ # https://github.com/bbirkinbine/mac-vms/blob/main/scripts/qemu-with-tpm.sh
48
+
49
+ set -euo pipefail
50
+
51
+ # Packer's qemu plugin probes the qemu binary with `-version` before it
52
+ # spawns the VM; answer it directly instead of erroring on the env checks
53
+ # below (SWTPM_SOCK/VIRTIO_WIN_ISO_PATH are only set for real VM runs).
54
+ if [[ "${1:-}" == "-version" || "${1:-}" == "--version" ]]; then
55
+ exec qemu-system-aarch64 "$@"
56
+ fi
57
+
58
+ if [[ -z "${SWTPM_SOCK:-}" ]]; then
59
+ echo "ERROR: SWTPM_SOCK not set; `agent-dev-env build` must export it." >&2
60
+ exit 1
61
+ fi
62
+
63
+ if [[ ! -S "${SWTPM_SOCK}" ]]; then
64
+ echo "ERROR: SWTPM_SOCK=${SWTPM_SOCK} is not a Unix socket. Is swtpm running?" >&2
65
+ exit 1
66
+ fi
67
+
68
+ if [[ -z "${VIRTIO_WIN_ISO_PATH:-}" ]]; then
69
+ echo "ERROR: VIRTIO_WIN_ISO_PATH not set; `agent-dev-env build` must export it." >&2
70
+ exit 1
71
+ fi
72
+
73
+ if [[ ! -f "${VIRTIO_WIN_ISO_PATH}" ]]; then
74
+ echo "ERROR: VIRTIO_WIN_ISO_PATH=${VIRTIO_WIN_ISO_PATH} does not exist." >&2
75
+ exit 1
76
+ fi
77
+
78
+ # ---- rewrite Packer-generated CD-ROM drives to usb-storage ---------------
79
+ #
80
+ # Walk $@: for every `-drive` whose value contains `media=cdrom`, strip the
81
+ # `if=...` and `index=...` keys, append `if=none,id=cd<N>`, and emit a
82
+ # matching `-device usb-storage,drive=cd<N>` after all argument rewriting
83
+ # is done. Non-cdrom drives (notably `if=pflash` for EFI firmware/vars and
84
+ # `if=virtio` for the qcow2 system disk) pass through untouched.
85
+
86
+ rewritten_args=()
87
+ device_appends=()
88
+ cd_counter=0
89
+
90
+ args=("$@")
91
+ i=0
92
+ while (( i < ${#args[@]} )); do
93
+ arg="${args[$i]}"
94
+ if [[ "$arg" == "-drive" ]] && (( i + 1 < ${#args[@]} )); then
95
+ val="${args[$((i + 1))]}"
96
+ if [[ "$val" == *"media=cdrom"* ]]; then
97
+ stripped="$(printf '%s' "$val" \
98
+ | sed -E 's/(^|,)if=[^,]*//g; s/(^|,)index=[^,]*//g; s/^,+//; s/,,+/,/g; s/,$//')"
99
+ cd_id="cd-pkr-${cd_counter}"
100
+ cd_counter=$((cd_counter + 1))
101
+ rewritten_args+=("-drive" "${stripped},if=none,id=${cd_id}")
102
+ # bus=usb.0 explicit: the xhci controller defined in `extras` below
103
+ # is the only USB bus on this VM, and unqualified `-device
104
+ # usb-storage` can fail-fast on "no usb bus" because qemu resolves
105
+ # device buses in argv order on ARM virt.
106
+ device_appends+=("-device" "usb-storage,drive=${cd_id},bus=usb.0")
107
+ i=$((i + 2))
108
+ continue
109
+ fi
110
+ fi
111
+ rewritten_args+=("$arg")
112
+ i=$((i + 1))
113
+ done
114
+
115
+ # ---- our own appends ------------------------------------------------------
116
+ #
117
+ # Ordering is load-bearing for two independent reasons:
118
+ #
119
+ # 1. qemu-xhci MUST come before any usb-storage entries (both the
120
+ # rewritten Packer cdroms in device_appends and our own virtio-win
121
+ # attach below) — qemu's device-graph resolution can fail at parse
122
+ # time if a usb-* device is seen before its bus exists.
123
+ #
124
+ # 2. The Packer install ISO's usb-storage device MUST enumerate before
125
+ # virtio-win.iso's (see the header comment on USB enumeration
126
+ # order).
127
+ #
128
+ # So the argv layout is split into two extras chunks:
129
+ # - bus_extras (xhci + input + tpm + ramfb) — defines the USB bus
130
+ # - virtio_win_storage (our virtio-win.iso usb-storage) — emitted LAST
131
+ # with device_appends (Packer's CDs as usb-storage) wedged between.
132
+
133
+ bus_extras=(
134
+ -chardev "socket,id=chrtpm,path=${SWTPM_SOCK}"
135
+ -tpmdev "emulator,id=tpm0,chardev=chrtpm"
136
+ # ppi=off: QEMU 11.1's HVF memory path aborts on the PPI region (a 1 KB,
137
+ # non-page-aligned RAM device) with HV_BAD_ARGUMENT — hv_vm_unmap rejects
138
+ # the unaligned size. Windows does not need PPI; disabling it dodges the
139
+ # regression. See https://gitlab.com/qemu-project/qemu/-/issues for the
140
+ # accel/hvf "Simplify hvf_set_phys_mem" fallout.
141
+ -device "tpm-tis-device,tpmdev=tpm0,ppi=off"
142
+ -device "ramfb"
143
+ -device "qemu-xhci,id=usb"
144
+ -device "usb-kbd,bus=usb.0"
145
+ -device "usb-tablet,bus=usb.0"
146
+ )
147
+
148
+ virtio_win_storage=(
149
+ -drive "file=${VIRTIO_WIN_ISO_PATH},media=cdrom,if=none,id=cd-virtio-win"
150
+ -device "usb-storage,drive=cd-virtio-win,bus=usb.0"
151
+ )
152
+
153
+ final_argv=(
154
+ "${rewritten_args[@]}"
155
+ "${bus_extras[@]}"
156
+ "${device_appends[@]}"
157
+ "${virtio_win_storage[@]}"
158
+ )
159
+
160
+ # Log the final qemu invocation so future "Qemu failed to start" errors
161
+ # are debuggable without PACKER_LOG=1. The build flow exports the
162
+ # per-image log path; the fallback matches the old platform-dir layout
163
+ # for standalone runs.
164
+ qemu_log_file="${QEMU_WITH_TPM_LOG:-packer_cache/qemu-with-tpm.cmd.log}"
165
+ {
166
+ echo "==> $(date -u +%FT%TZ) qemu-system-aarch64 invocation"
167
+ printf ' %q\n' qemu-system-aarch64 "${final_argv[@]}"
168
+ } >"$qemu_log_file" 2>/dev/null || true
169
+
170
+ exec qemu-system-aarch64 "${final_argv[@]}"