@reallroboto/qbbox 0.0.0-stage → 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.
package/qbbox ADDED
@@ -0,0 +1,427 @@
1
+ #!/bin/bash
2
+ # qbbox: one disposable QBD Box on the operator Mac. QEMU+HVF, Windows 11 Arm, online, Mac + private ranges blocked.
3
+ # qbbox firmware build the UEFI firmware with the patched ramfb driver
4
+ # qbbox qemu build qemu-system-aarch64 with the 60 fps display patch
5
+ # qbbox golden build the Golden from the media cache + Windows Update, unattended
6
+ # qbbox up boot the Box; first boot creates its overlay on the Golden
7
+ # qbbox qbd install the QBD trial in the running Box, QBD updater blocked
8
+ # qbbox sdk unpack qbxmlops170.xml from the SDK installer in the running Box, SDK not installed
9
+ # qbbox push-qb copy the qb installed on the Mac (or --from <tarball>) into the running Box
10
+ # qbbox destroy power off the Box and delete its overlay
11
+ set -euo pipefail
12
+
13
+ # Package dir, also when started through the npm bin symlink.
14
+ repo=$(dirname "$(/bin/realpath "$0")")
15
+ home=$HOME/.qbbox
16
+ media=$home/media
17
+ share=/opt/homebrew/share/qemu
18
+ llvm=/opt/homebrew/opt/llvm
19
+ brew=/opt/homebrew/bin/brew
20
+ # Display mode, seen over VNC: firmware and Windows (viogpudo) take it from virtio-gpu. Golden runs at 200 %, so
21
+ # 1512×945 logical, as an RDP session on a Retina Mac.
22
+ xres=3024 yres=1890
23
+ ssh_opts=(-o BatchMode=yes -o ConnectTimeout=5 -o "UserKnownHostsFile=$home/known_hosts" -o StrictHostKeyChecking=accept-new)
24
+
25
+ die() { echo "qbbox: $*" >&2; exit 1; }
26
+
27
+ mkdir -p "$media"
28
+ chmod 700 "$home"
29
+
30
+ # sha_ok <sha256> <file>: the file has that SHA-256.
31
+ sha_ok() { echo "$1 $2" | /usr/bin/shasum -a 256 -c --status -; }
32
+
33
+ # need <file> <url> <sha256>: fetch into the media cache if missing, then check the hash.
34
+ need() {
35
+ local file=$media/$1
36
+ if [ ! -e "$file" ]; then
37
+ [ -n "$2" ] || die "missing $file"
38
+ curl -fL --retry 3 -o "$file.part" "$2"
39
+ mv "$file.part" "$file"
40
+ fi
41
+ [ -z "$3" ] || sha_ok "$3" "$file" || die "SHA-256 mismatch: $file; delete it to fetch again"
42
+ }
43
+
44
+ # deps: Xcode Command Line Tools, then every Brewfile formula; brew installs the missing ones.
45
+ deps() {
46
+ xcode-select -p >/dev/null 2>&1 || die "missing Xcode Command Line Tools: run xcode-select --install"
47
+ [ -x "$brew" ] || die "missing Homebrew: install it from https://brew.sh"
48
+ "$brew" bundle check --file "$repo/Brewfile" >/dev/null ||
49
+ "$brew" bundle install --file "$repo/Brewfile" ||
50
+ die "brew bundle install failed: see the brew output above"
51
+ }
52
+
53
+ # win11_iso: Windows 11 Arm64 ISO, en-US, fetched through the API the Microsoft download page calls, as Rufus'
54
+ # Fido (pbatard/Fido) does; edition and SHA-256 from that page. The hash file beside the ISO: checked on every use.
55
+ win11_iso() {
56
+ local iso=$media/win11arm.iso page=https://www.microsoft.com/en-us/software-download/windows11arm64
57
+ # ISO deleted (mismatch, new release) or hash file not one SHA-256: the hash file goes, the ISO is checked or fetched again.
58
+ if [ ! -e "$iso" ] || ! grep -qxE '[0-9a-f]{64}' "$iso.sha256" 2>/dev/null; then rm -f "$iso.sha256"; fi
59
+ if [ ! -e "$iso.sha256" ]; then
60
+ # Fido's constants: download session check (vlscppe, ov-df) and the page's API profile.
61
+ local api=https://www.microsoft.com/software-download-connector/api profile=606624d44113
62
+ local instance=560dc9f3-1aa5-4a2f-b63c-9e18f8d0e175 sid html edition hash js w rticks sku url
63
+ local blocked="cannot reach vlscppe.microsoft.com (CNAME h-microsoft.online-metrix.net) or ov-df.microsoft.com: offline, or a DNS block list stops them"
64
+ html=$(curl -fsSL "$page") || die "cannot read $page"
65
+ # No match leaves the value empty (pipefail): checked right after.
66
+ edition=$(grep -oE '<option value="[0-9]+">Windows 11 \(multi-edition ISO for Arm64\)' <<<"$html" | grep -oE '[0-9]+' | head -1) || true
67
+ hash=$(grep -oE '<td>English 64-bit</td><td>[A-Fa-f0-9]{64}' <<<"$html" | grep -oE '[A-Fa-f0-9]{64}' | tr '[:upper:]' '[:lower:]') || true
68
+ [ -n "$hash" ] || die "$page changed: no English SHA-256 found"
69
+ if [ -e "$iso" ]; then
70
+ # ISO from before the hash file: kept when it is the release the page publishes.
71
+ sha_ok "$hash" "$iso" ||
72
+ die "$iso is not the release $page publishes: delete it, qbbox then fetches the current one"
73
+ else
74
+ [ -n "$edition" ] || die "$page changed: no Arm64 edition found"
75
+ sid=$(uuidgen | tr '[:upper:]' '[:lower:]')
76
+ curl -fsS -o /dev/null "https://vlscppe.microsoft.com/tags?org_id=y6jn8c31&session_id=$sid" || die "$blocked"
77
+ # mdt.js carries the w and rticks values the ov-df reply must echo back.
78
+ js=$(curl -fsS "https://ov-df.microsoft.com/mdt.js?instanceId=$instance&PageId=si&session_id=$sid") || die "$blocked"
79
+ w=$(grep -oE '[?&]w=[A-F0-9]+' <<<"$js" | head -1 | cut -d= -f2) || true
80
+ rticks=$(grep -oE 'rticks="\+?[0-9]+' <<<"$js" | head -1 | grep -oE '[0-9]+') || true
81
+ [ -n "$w" ] && [ -n "$rticks" ] || die "ov-df.microsoft.com changed its reply: update from Fido"
82
+ curl -fsS -o /dev/null "https://ov-df.microsoft.com/?session_id=$sid&CustomerId=$instance&PageId=si&w=$w&mdt=$(($(date +%s) * 1000))&rticks=$rticks" || die "$blocked"
83
+ sku=$(curl -fsS "$api/getskuinformationbyproductedition?profile=$profile&productEditionId=$edition&SKU=undefined&friendlyFileName=undefined&Locale=en-US&sessionID=$sid" |
84
+ python3 -c 'import json, sys; r = json.load(sys.stdin); i = [s["Id"] for s in r.get("Skus") or [] if s["Language"] == "English"]; print(i[0]) if i else sys.exit("Microsoft: " + json.dumps(r.get("Errors")))') ||
85
+ die "SKU request for edition $edition failed"
86
+ # Microsoft may refuse a download request (error 715-123130): try again later, or from another network.
87
+ url=$(curl -fsS -H "Referer: $page" "$api/GetProductDownloadLinksBySku?profile=$profile&productEditionId=undefined&SKU=$sku&friendlyFileName=undefined&Locale=en-US&sessionID=$sid" |
88
+ python3 -c 'import json, sys; r = json.load(sys.stdin); u = [o["Uri"] for o in r.get("ProductDownloadOptions") or [] if o["DownloadType"] == 2]; print(u[0]) if u else sys.exit("Microsoft: " + json.dumps(r.get("Errors")))') ||
89
+ die "Microsoft refused the ISO link: try again later or from another network, or download it from $page"
90
+ curl -fL --retry 3 -o "$iso.part" "$url" || die "ISO download failed: ${url%%\?*}"
91
+ sha_ok "$hash" "$iso.part" || die "SHA-256 mismatch: $iso.part, not the hash $page publishes"
92
+ mv "$iso.part" "$iso"
93
+ fi
94
+ echo "$hash" >"$iso.sha256"
95
+ fi
96
+ need win11arm.iso "" "$(cat "$iso.sha256")"
97
+ }
98
+
99
+ qmp() { printf '{"execute":"qmp_capabilities"}\n%s\n' "$1" | nc -U -w 2 "$home/qmp.sock" | tail -1; }
100
+ running() { [ -e "$home/qemu.pid" ] && kill -0 "$(cat "$home/qemu.pid")" 2>/dev/null; }
101
+ # QEMU deletes its pidfile on exit: callers read the pid first.
102
+ exited() { ! kill -0 "$1" 2>/dev/null; }
103
+ guest() { ssh "${ssh_opts[@]}" -p 2222 qb@127.0.0.1 "$@"; }
104
+ # OOBE runs its own explorer as defaultuser0: setup is done once qb has a desktop.
105
+ qb_desktop() { [[ $(guest '(Get-Process explorer -IncludeUserName -ErrorAction SilentlyContinue).UserName') == *'\qb'* ]]; }
106
+ boot_ticks() { guest '(Get-CimInstance Win32_OperatingSystem).LastBootUpTime.Ticks'; }
107
+ # rebooted <boot ticks>: the guest booted again since <boot ticks>, and qb has its desktop.
108
+ rebooted() { [[ $(boot_ticks) != "$1" ]] && qb_desktop; }
109
+ # windows-update.ps1 renames its result into place: the file exists = round done.
110
+ wu_done() { [[ $(guest 'Test-Path C:\Windows\Temp\qbbox-wu.json') == True* ]]; }
111
+
112
+ # wait_for <seconds> <command...>: retry every 10 s until the command succeeds.
113
+ wait_for() {
114
+ local deadline=$((SECONDS + $1)); shift
115
+ until "$@" >/dev/null 2>&1; do
116
+ [ $SECONDS -lt $deadline ] || die "timed out: $*"
117
+ sleep 10
118
+ done
119
+ }
120
+
121
+ # boot <disk> [QEMU args]: start <disk>.qcow2 with <disk>.vars.fd in the background.
122
+ boot() {
123
+ local disk=$1; shift
124
+ ! running || die "a Box is already running (pid $(cat "$home/qemu.pid"))"
125
+ [ -x "$home/qemu-system-aarch64" ] || die "no QEMU build: run qbbox qemu"
126
+ rm -f "$home/qmp.sock"
127
+ # -L: keymaps (VNC) and other data from the Homebrew qemu of the same version.
128
+ # Online: the guest block list (golden/setup.ps1) keeps the guest off the Mac (10.0.2.2) and private ranges.
129
+ # ipv6=off: the block list covers IPv4 only; the slirp IPv6 host alias fec0::2 would need its own rules.
130
+ "$home/qemu-system-aarch64" -L "$share" -nodefaults -name "qbbox-$disk" \
131
+ -machine virt,highmem=on,gic-version=3 -accel hvf -cpu host -smp 6,sockets=1,cores=6,threads=1 -m 8192 \
132
+ -drive if=pflash,format=raw,unit=0,readonly=on,file="$home/firmware.fd" \
133
+ -drive if=pflash,format=raw,unit=1,file="$home/$disk.vars.fd" \
134
+ -device virtio-gpu-pci,xres=$xres,yres=$yres \
135
+ -device qemu-xhci,id=xhci,p2=8,p3=8 -device usb-kbd,bus=xhci.0 -device usb-tablet,bus=xhci.0 \
136
+ -drive if=none,id=disk0,file="$home/$disk.qcow2",format=qcow2,discard=unmap,detect-zeroes=unmap,cache=writeback \
137
+ -device nvme,serial=qbbox,drive=disk0,bootindex=1 \
138
+ -netdev user,id=net0,ipv6=off,hostfwd=tcp:127.0.0.1:2222-:22,hostfwd=tcp:127.0.0.1:3389-:3389 -device virtio-net-pci,netdev=net0 \
139
+ -device virtio-rng-pci -rtc base=utc \
140
+ -display none -vnc 127.0.0.1:0,password=on \
141
+ -qmp unix:"$home/qmp.sock",server=on,wait=off \
142
+ -daemonize -pidfile "$home/qemu.pid" \
143
+ "$@"
144
+ # VNC auth uses the first 8 characters only.
145
+ qmp "{\"execute\":\"change-vnc-password\",\"arguments\":{\"password\":\"$(head -c 8 "$home/password")\"}}" >/dev/null
146
+ }
147
+
148
+ qemu_src() { need qemu-11.1.2.tar.xz https://download.qemu.org/qemu-11.1.2.tar.xz 731b5681e4bb18be313231579b8efd0296c5b015fa36dc533874b639ba838016; }
149
+
150
+ firmware() {
151
+ deps
152
+ qemu_src
153
+ local build=$home/build jobs
154
+ jobs=$(sysctl -n hw.ncpu)
155
+ rm -rf "$build" && mkdir -p "$build"
156
+ # Only edk2 and its build driver from the QEMU tree; the edk2 tree carries its submodules.
157
+ /usr/bin/bsdtar -xf "$media/qemu-11.1.2.tar.xz" -C "$build" --strip-components 2 qemu-11.1.2/roms/edk2 qemu-11.1.2/roms/edk2-build.py
158
+ cp "$repo/firmware/QemuRamfb.c" "$repo/firmware/QemuRamfbDxe.inf" "$build/edk2/OvmfPkg/QemuRamfbDxe/"
159
+ # C host tools only (BaseTools' Python tests need a bare `python`). The macOS SDK already
160
+ # defines UINT8_MAX etc.; BaseTools builds with -Werror.
161
+ make -C "$build/edk2/BaseTools/Source/C" -j"$jobs" CC=/usr/bin/clang CXX=/usr/bin/clang++ EXTRA_OPTFLAGS=-Wno-error >/dev/null
162
+ (cd "$build" && PATH="$llvm/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin" \
163
+ CLANGDWARF_BIN="$llvm/bin/" IASL_PREFIX=/opt/homebrew/bin/ PYTHON_COMMAND=python3 \
164
+ python3 edk2-build.py --config "$repo/firmware/edk2.config" --core edk2 --match armvirt.aa64 \
165
+ --toolchain CLANGDWARF --jobs "$jobs")
166
+ # QEMU's virt pflash takes exactly 64 MiB.
167
+ python3 -c 'import os, sys; os.truncate(sys.argv[1], 64 << 20)' "$build/out/qbbox-aarch64-code.fd"
168
+ mv "$build/out/qbbox-aarch64-code.fd" "$home/firmware.fd"
169
+ rm -rf "$build"
170
+ echo "firmware: $home/firmware.fd"
171
+ }
172
+
173
+ qemu() {
174
+ deps
175
+ qemu_src
176
+ # QEMU's configure needs Python >= 3.11 (tomllib); the Xcode python3 is 3.9.
177
+ local build=$home/build python=/opt/homebrew/bin/python3.14
178
+ rm -rf "$build" && mkdir -p "$build"
179
+ # roms/ = firmware sources, not needed for the emulator.
180
+ /usr/bin/bsdtar -xf "$media/qemu-11.1.2.tar.xz" -C "$build" --strip-components 1 --exclude qemu-11.1.2/roms
181
+ patch -d "$build" -p1 -s <"$repo/qemu/0001-ui-60fps-display-refresh.patch"
182
+ # Only what boot() uses (nettle: DES for the VNC password); glib, pixman, libslirp, nettle, dtc from Homebrew.
183
+ # The build signs the binary with the HVF entitlement.
184
+ (cd "$build" && ./configure --python="$python" --target-list=aarch64-softmmu --without-default-features \
185
+ --disable-docs --enable-hvf --enable-vnc --enable-slirp --enable-pixman --enable-nettle --enable-fdt=system \
186
+ --extra-cflags=-I/opt/homebrew/include --extra-ldflags=-L/opt/homebrew/lib >/dev/null)
187
+ ninja -C "$build/build" qemu-system-aarch64 >/dev/null
188
+ mv "$build/build/qemu-system-aarch64" "$home/qemu-system-aarch64"
189
+ rm -rf "$build"
190
+ "$home/qemu-system-aarch64" --version | head -1
191
+ }
192
+
193
+ golden() {
194
+ deps
195
+ [ -e "$home/firmware.fd" ] || die "no firmware: run qbbox firmware"
196
+ [ ! -e "$home/golden.qcow2" ] || die "golden.qcow2 exists; delete it to rebuild"
197
+ [ ! -e "$home/box.qcow2" ] || die "the Box overlay depends on the Golden: run qbbox destroy first"
198
+ [ -s "$home/authorized_keys" ] || die "missing $home/authorized_keys: agent + Mac public keys, one per line"
199
+ win11_iso
200
+ # virtio-win publishes no hash: pin from the first download, 2026-10-18.
201
+ need virtio-win-0.1.302.iso https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.302-1/virtio-win-0.1.302.iso 303f7ae40dad495d6ae474fdc571df58958a4dbc5c37a522d80f9a203867949d
202
+ need OpenSSH-ARM64-v10.0.0.0.msi https://github.com/PowerShell/Win32-OpenSSH/releases/download/10.0.0.0p2-Preview/OpenSSH-ARM64-v10.0.0.0.msi 7a17d0e22d004fb47ca4bfd8fef926fa305de4ebf70a6f3c7a29c39aabef0023
203
+ need node-v26.13.0-win-arm64.zip https://nodejs.org/dist/v26.13.0/node-v26.13.0-win-arm64.zip a9427139595156ef484e1fb08957676e09d4232368dd1743a2a9f93f3d241b14
204
+ need PowerShell-7.6.7-win-x64.zip https://github.com/PowerShell/PowerShell/releases/download/v7.6.7/PowerShell-7.6.7-win-x64.zip d2f952ebdbf24386cb8923553aa58e41a846db35a6155ea04c58142a4b16dbb7
205
+ # Hex: safe inside sed and XML.
206
+ [ -e "$home/password" ] || (umask 077 && openssl rand -hex 12 >"$home/password")
207
+
208
+ # Staged inside the state dir: it holds the plaintext password.
209
+ local cfg=$home/cfg
210
+ rm -rf "$cfg"
211
+ mkdir -p "$cfg/qbbox" "$cfg/\$WinPEDriver\$"
212
+ sed "s/__PASSWORD__/$(cat "$home/password")/" "$repo/golden/autounattend.xml" >"$cfg/autounattend.xml"
213
+ cp "$repo/golden/SetupComplete.cmd" "$repo/golden/setup.ps1" "$home/authorized_keys" "$cfg/qbbox/"
214
+ cp "$media/OpenSSH-ARM64-v10.0.0.0.msi" "$cfg/qbbox/OpenSSH-ARM64.msi"
215
+ cp "$media/node-v26.13.0-win-arm64.zip" "$cfg/qbbox/node.zip"
216
+ cp "$media/PowerShell-7.6.7-win-x64.zip" "$cfg/qbbox/pwsh.zip"
217
+ # Mounted, not extracted: the ISO stores w11 files as hard links to other folders.
218
+ local virtio driver
219
+ virtio=$(diskutil image attach --nobrowse --readOnly "$media/virtio-win-0.1.302.iso" | tail -1 | cut -f3)
220
+ for driver in NetKVM viorng viogpudo; do
221
+ mkdir "$cfg/\$WinPEDriver\$/$driver"
222
+ cp "$virtio/$driver/w11/ARM64/"* "$cfg/\$WinPEDriver\$/$driver/"
223
+ done
224
+ hdiutil detach -quiet "$virtio"
225
+ rm -f "$home/cfg.iso"
226
+ hdiutil makehybrid -quiet -iso -joliet -default-volume-name QBCFG -joliet-volume-name QBCFG -o "$home/cfg.iso" "$cfg"
227
+ rm -rf "$cfg"
228
+
229
+ # Windows reads a USB CD at ~1 MB/s under QEMU, an NVMe disk at full speed: the ISO's files go on a
230
+ # FAT32 disk, install.wim split under the 4 GB file limit (Setup reads install.swm).
231
+ local img=$home/installer.img dev iso vol
232
+ rm -f "$img"
233
+ mkfile -n 10g "$img"
234
+ dev=$(diskutil image attach --noMount "$img" | cut -f1)
235
+ diskutil quiet eraseDisk FAT32 WININST MBRFormat "$dev"
236
+ vol=$(diskutil info "${dev}s1" | sed -n 's/^ *Mount Point: *//p')
237
+ iso=$(diskutil image attach --nobrowse --readOnly "$media/win11arm.iso" | tail -1 | cut -f3)
238
+ (cd "$iso" && /usr/bin/bsdtar -c -f - --exclude ./sources/install.wim --no-xattrs --no-mac-metadata .) |
239
+ /usr/bin/bsdtar -x -f - -C "$vol" --no-xattrs --no-mac-metadata --no-same-owner --no-same-permissions
240
+ wimlib-imagex split "$iso/sources/install.wim" "$vol/sources/install.swm" 3800
241
+ hdiutil detach -quiet "$iso"
242
+ hdiutil detach -quiet "$dev"
243
+ # diskutil writes MBR disk signature 0; WinPE then sees the disk with no partitions.
244
+ printf '\x51\x42\x42\x58' | dd of="$img" bs=1 seek=440 conv=notrunc 2>/dev/null
245
+
246
+ qemu-img create -q -f qcow2 "$home/golden.qcow2" 64G
247
+ cp "$share/edk2-arm-vars.fd" "$home/golden.vars.fd"
248
+ # A new Golden has new SSH host keys.
249
+ rm -f "$home/known_hosts"
250
+ # Empty target first: firmware falls through to the installer; after Setup's reboot, Windows boots.
251
+ boot golden \
252
+ -drive if=none,id=installer,format=raw,readonly=on,file="$img" \
253
+ -device nvme,serial=qbinst,drive=installer,bootindex=2 \
254
+ -drive if=none,id=cfg,media=cdrom,readonly=on,file="$home/cfg.iso" \
255
+ -device usb-storage,bus=xhci.0,drive=cfg,removable=on
256
+
257
+ echo "golden: Windows Setup running, unattended; VNC 127.0.0.1:5900 stays dark until the first sign-in"
258
+ wait_for 1800 qb_desktop
259
+ # 200 %: every autologon session then starts at the DPI of an RDP session from a Retina Mac. QBW.EXE is
260
+ # system-DPI-aware: reads the DPI once per session, blurs on a later change. Set after the first sign-in,
261
+ # which resets the default profile's DPI.
262
+ guest "Set-ItemProperty 'HKCU:\\Control Panel\\Desktop' LogPixels 192 -Type DWord; Set-ItemProperty 'HKCU:\\Control Panel\\Desktop' Win8DpiScaling 1 -Type DWord"
263
+
264
+ # Every applicable Windows update, in rounds of task qbbox-wu (SYSTEM); a round that needs it reboots the guest.
265
+ # Only download outside the media cache: Golden build only (owner, 2026-10-21, qbcli#203).
266
+ scp "${ssh_opts[@]}" -P 2222 -q "$repo/guest/windows-update.ps1" qb@127.0.0.1:C:/Windows/Temp/
267
+ guest 'powershell -NoProfile -ExecutionPolicy Bypass -File C:\Windows\Temp\windows-update.ps1 -Register'
268
+ local round wu found code reboot ticks
269
+ for round in {1..10}; do
270
+ guest 'Remove-Item C:\Windows\Temp\qbbox-wu.json -ErrorAction SilentlyContinue; Start-ScheduledTask -TaskName qbbox-wu'
271
+ wait_for 7200 wu_done
272
+ wu=$(guest 'Get-Content C:\Windows\Temp\qbbox-wu.json' |
273
+ python3 -c 'import json, sys; r = json.load(sys.stdin); print(r["found"], r["resultCode"], r["rebootRequired"])')
274
+ read -r found code reboot <<<"$wu"
275
+ echo "golden: Windows Update round $round: $found found, resultCode $code, reboot $reboot"
276
+ # OperationResultCode 2 = Succeeded, 3 = SucceededWithErrors.
277
+ [[ $code == [23] ]] || die "Windows Update round $round failed: resultCode $code; error in guest C:\\Windows\\Temp\\qbbox-wu.json"
278
+ [ "$found" -ne 0 ] || break
279
+ if [ "$reboot" = True ]; then
280
+ ticks=$(boot_ticks)
281
+ guest 'Restart-Computer -Force' || true
282
+ wait_for 1800 rebooted "$ticks"
283
+ fi
284
+ done
285
+ [ "$found" -eq 0 ] || die "Windows Update: no round found 0 updates in 10 rounds"
286
+ # schtasks: Unregister-ScheduledTask asks to confirm.
287
+ guest 'schtasks.exe /Delete /TN qbbox-wu /F' >/dev/null
288
+ guest 'Remove-Item C:\Windows\Temp\windows-update.ps1, C:\Windows\Temp\qbbox-wu.json'
289
+ # Windows Update off in every job: no download or reboot mid-job. Patches come with the monthly Golden rebuild.
290
+ guest 'reg.exe add HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU /v NoAutoUpdate /t REG_DWORD /d 1 /f' >/dev/null
291
+ guest 'Get-NetFirewallRule -Name qbbox-block-private, qbbox-block-mac-tcp, qbbox-block-mac-udp -ErrorAction Stop' >/dev/null ||
292
+ die "Golden check failed: guest block list missing"
293
+ [[ $(guest '(Get-ItemProperty HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU).NoAutoUpdate') == 1* ]] ||
294
+ die "Golden check failed: Windows Update policy missing"
295
+
296
+ local pid
297
+ pid=$(cat "$home/qemu.pid")
298
+ guest 'Stop-Computer -Force' || true
299
+ wait_for 300 exited "$pid"
300
+ rm -f "$img" "$home/cfg.iso"
301
+ chmod 444 "$home/golden.qcow2" "$home/golden.vars.fd"
302
+ # Golden built online with the guest block list + Windows Update policy, both checked above: up needs it.
303
+ touch "$home/golden.online"
304
+ # Written last: up takes it as the mark of a finished Golden.
305
+ (cd "$home" && /usr/bin/shasum -a 256 golden.qcow2 golden.vars.fd >golden.sha256)
306
+ echo "golden: $home/golden.qcow2"
307
+ }
308
+
309
+ up() {
310
+ deps
311
+ [ -e "$home/golden.sha256" ] || die "no finished Golden: run qbbox golden"
312
+ # A Golden built before the online Box has no guest block list.
313
+ [ -e "$home/golden.online" ] || die "Golden predates the online Box: rebuild it (docs/golden.md#rebuild)"
314
+ if [ ! -e "$home/box.qcow2" ]; then
315
+ qemu-img create -q -f qcow2 -b "$home/golden.qcow2" -F qcow2 "$home/box.qcow2"
316
+ cp "$home/golden.vars.fd" "$home/box.vars.fd"
317
+ chmod 644 "$home/box.vars.fd"
318
+ fi
319
+ boot box
320
+ wait_for 600 guest exit
321
+ echo "Box up: ssh -p 2222 qb@127.0.0.1 · RDP 127.0.0.1:3389 · VNC 127.0.0.1:5900"
322
+ }
323
+
324
+ qbd() {
325
+ running || die "no Box running: run qbbox up"
326
+ # Intuit publishes no hash and replaces "Latest": pin from the first download, 2026-10-18 (Authenticode Intuit, Inc.).
327
+ need QuickBooksEnterprise24Trial.exe https://dlm2.download.intuit.com/akdlm/SBD/QuickBooks/2024/Latest/QuickBooksEnterprise24Trial.exe 0774a45c29718fa354e094b3ee3c63979b946fad6d20f4eb857155c49b6e9d15
328
+ local qbd=$media/qbd
329
+ if [ ! -d "$qbd" ]; then
330
+ # The trial is a 7-Zip SFX: stub, config, then the 7z archive. bsdtar reads the archive once cut out.
331
+ local offset tmp=$media/qbd.part
332
+ offset=$(python3 -c 'import sys; d = open(sys.argv[1], "rb").read(4 << 20); print(d.index(b"7z\xbc\xaf\x27\x1c", d.index(b";!@InstallEnd@!")))' "$media/QuickBooksEnterprise24Trial.exe")
333
+ rm -rf "$tmp"
334
+ mkdir -p "$tmp/qbd"
335
+ tail -c +$((offset + 1)) "$media/QuickBooksEnterprise24Trial.exe" >"$tmp/qbd.7z"
336
+ /usr/bin/bsdtar -xf "$tmp/qbd.7z" -C "$tmp/qbd" QBooks ThirdParty/CRT9 ThirdParty/CRT12 ThirdParty/CRT14_1
337
+ mv "$tmp/qbd" "$qbd"
338
+ rm -rf "$tmp"
339
+ fi
340
+ # Copied into the parent: a second run overwrites C:/Users/qb/qbd, never nests it.
341
+ scp "${ssh_opts[@]}" -P 2222 -q -r "$qbd" qb@127.0.0.1:C:/Users/qb/
342
+ scp "${ssh_opts[@]}" -P 2222 -q "$repo/guest/install-qbd.ps1" qb@127.0.0.1:C:/Users/qb/qbd/
343
+ guest 'powershell -NoProfile -ExecutionPolicy Bypass -File C:\Users\qb\qbd\install-qbd.ps1'
344
+ }
345
+
346
+ sdk() {
347
+ # Intuit publishes no hash: pin from the first download, 2026-10-18.
348
+ need QBSDK170.exe https://static.developer.intuit.com/resources/QBSDK170.exe c86f31152e048826426ea8c1df0745556b6422f3be113acaa9bf2d46f5860896
349
+ # 64-bit SDK: nothing unpacks it yet; pinned so the cache holds no unchecked download (owner, 2026-10-18).
350
+ need QBSDK170_x64.exe https://static.developer.intuit.com/resources/QBSDK170_x64.exe 3921156d7ceed068b9292fba5a6b817f8631c3687d248588c0c374d8ca5e80f4
351
+ if [ ! -e "$media/qbxmlops170.xml" ]; then
352
+ # macOS cannot open the InstallShield wrapper: Windows unpacks it, the SDK is never installed.
353
+ running || die "no Box running: run qbbox up"
354
+ # Emptied first: a failed run leaves its files here.
355
+ guest 'Remove-Item -Recurse -Force C:\Users\qb\sdk -ErrorAction SilentlyContinue; New-Item -ItemType Directory C:\Users\qb\sdk | Out-Null'
356
+ scp "${ssh_opts[@]}" -P 2222 -q "$media/QBSDK170.exe" "$repo/guest/unpack-sdk.ps1" qb@127.0.0.1:C:/Users/qb/sdk/
357
+ guest 'powershell -NoProfile -ExecutionPolicy Bypass -File C:\Users\qb\sdk\unpack-sdk.ps1'
358
+ scp "${ssh_opts[@]}" -P 2222 -q qb@127.0.0.1:C:/Users/qb/sdk/qbxmlops170.xml "$media/qbxmlops170.xml.part"
359
+ guest 'Remove-Item -Recurse -Force C:\Users\qb\sdk'
360
+ mv "$media/qbxmlops170.xml.part" "$media/qbxmlops170.xml"
361
+ fi
362
+ # Pinned from the first unpack, 2026-10-18.
363
+ need qbxmlops170.xml "" 3cfc19e4ac3f1b9e9793000dd9d9446628be68548249e006411bd4be97fc3e0d
364
+ echo "sdk: $media/qbxmlops170.xml"
365
+ }
366
+
367
+ # push_qb [--from <tarball>]: the npm tarball, else the globally installed @reallroboto/qb → guest C:\Users\qb\qb.
368
+ # Refused unless its package.json version (= its `qb --help` version) starts with the qbbox.qb key of package.json + ".".
369
+ # Staged in qb.new; refused unless guest `qb --help` exits 0.
370
+ push_qb() {
371
+ local from=""
372
+ case ${1-} in
373
+ "") ;;
374
+ --from) [ -n "${2-}" ] || die "--from needs a tarball"; from=$2 ;;
375
+ *) die "push-qb: unknown argument $1" ;;
376
+ esac
377
+ running || die "no Box running: run qbbox up"
378
+ local want src version
379
+ want=$(python3 -c 'import json, sys; print(json.load(open(sys.argv[1]))["qbbox"]["qb"])' "$repo/package.json")
380
+ if [ -n "$from" ]; then
381
+ [ -f "$from" ] || die "no tarball: $from"
382
+ tmp=$(mktemp -d)
383
+ trap 'rm -rf "$tmp"' EXIT
384
+ # npm pack puts every file under package/.
385
+ /usr/bin/tar -xzf "$from" -C "$tmp" || die "not an npm tarball: $from"
386
+ src=$tmp/package
387
+ else
388
+ command -v npm >/dev/null || die "missing npm: install Node, or pass --from <tarball>"
389
+ src="$(npm root -g)/@reallroboto/qb"
390
+ fi
391
+ [ -e "$src/bin/qb.js" ] || die "no qb package: npm install -g @reallroboto/qb, or pass --from <tarball>"
392
+ # npm install -g <folder> links it: copy the files, not the link.
393
+ src=$(/bin/realpath "$src")
394
+ # A missing path fails Remove-Item, even silenced: the exit code comes from Test-Path.
395
+ guest 'Remove-Item -Recurse -Force C:\Users\qb\qb.new -ErrorAction SilentlyContinue; exit [int](Test-Path C:\Users\qb\qb.new)' ||
396
+ die "push-qb: cannot clear C:\\Users\\qb\\qb.new in the Box"
397
+ version=$(python3 -c 'import json, sys; print(json.load(open(sys.argv[1]))["version"])' "$src/package.json") || version=""
398
+ [[ $version == "$want".* ]] || die "push-qb: qb ${version:-with no version} refused, qbbox accepts $want.x; guest qb unchanged"
399
+ # scp -r names the copy after the target, not the source folder.
400
+ scp "${ssh_opts[@]}" -P 2222 -q -r "$src" qb@127.0.0.1:C:/Users/qb/qb.new
401
+ # Smoke check: qb starts on the guest Node; output not parsed (text or JSON help).
402
+ if ! guest 'node C:\Users\qb\qb.new\bin\qb.js --help' >/dev/null; then
403
+ guest 'Remove-Item -Recurse -Force C:\Users\qb\qb.new' || true
404
+ die "push-qb: qb $version refused, its qb --help fails in the Box; guest qb unchanged"
405
+ fi
406
+ # Rename fails while qb still exists: a partly removed qb stops here, qb.new kept.
407
+ guest 'Remove-Item -Recurse -Force C:\Users\qb\qb -ErrorAction SilentlyContinue; Rename-Item C:\Users\qb\qb.new qb' ||
408
+ die "push-qb: cannot replace C:\\Users\\qb\\qb (a qb run holds a file?); C:\\Users\\qb\\qb.new kept, run push-qb again"
409
+ printf 'push-qb: qb %s in the Box; run: node C:\\Users\\qb\\qb\\bin\\qb.js\n' "$version"
410
+ }
411
+
412
+ destroy() {
413
+ if running; then
414
+ local pid
415
+ pid=$(cat "$home/qemu.pid")
416
+ qmp '{"execute":"quit"}' >/dev/null
417
+ wait_for 60 exited "$pid"
418
+ fi
419
+ rm -f "$home/box.qcow2" "$home/box.vars.fd"
420
+ echo "Box destroyed"
421
+ }
422
+
423
+ case ${1-} in
424
+ firmware | qemu | golden | up | qbd | sdk | destroy) "$1" ;;
425
+ push-qb) shift; push_qb "$@" ;;
426
+ *) sed -n '2,10s/^# \{0,1\}//p' "$0" >&2; exit 2 ;;
427
+ esac
@@ -0,0 +1,35 @@
1
+ SiliconWin: refresh the display at 60 fps
2
+
3
+ QEMU refreshes graphical consoles every 30 ms (about 33 fps), and the VNC
4
+ server backs off to one update every 3 s while the screen is idle, which makes
5
+ the pointer feel sluggish after a pause. Refresh every 16 ms instead, and never
6
+ back off beyond 100 ms. SiliconWin talks to the VNC server over a local Unix
7
+ socket, so the extra updates cost very little.
8
+
9
+ License: same as the files it modifies (include/ui/console.h: GPL-2.0-or-later,
10
+ ui/vnc.c: MIT).
11
+
12
+ --- a/include/ui/console.h 2026-10-03 04:51:59
13
+ +++ b/include/ui/console.h 2026-10-03 04:51:59
14
+ @@ -36,7 +36,7 @@
15
+ #define QEMU_CAPS_LOCK_LED (1 << 2)
16
+
17
+ /* in ms */
18
+ -#define GUI_REFRESH_INTERVAL_DEFAULT 30
19
+ +#define GUI_REFRESH_INTERVAL_DEFAULT 16 /* SiliconWin: 60 fps instead of ~33 */
20
+ #define GUI_REFRESH_INTERVAL_IDLE 3000
21
+
22
+ /* Color number is match to standard vga palette */
23
+ --- a/ui/vnc.c 2026-10-03 04:51:59
24
+ +++ b/ui/vnc.c 2026-10-03 04:51:59
25
+ @@ -59,8 +59,8 @@
26
+ #include "monitor/monitor.h"
27
+
28
+ #define VNC_REFRESH_INTERVAL_BASE GUI_REFRESH_INTERVAL_DEFAULT
29
+ -#define VNC_REFRESH_INTERVAL_INC 50
30
+ -#define VNC_REFRESH_INTERVAL_MAX GUI_REFRESH_INTERVAL_IDLE
31
+ +#define VNC_REFRESH_INTERVAL_INC 16 /* SiliconWin: stay responsive when idle */
32
+ +#define VNC_REFRESH_INTERVAL_MAX 100 /* SiliconWin: was GUI_REFRESH_INTERVAL_IDLE (3 s) */
33
+ static const struct timeval VNC_REFRESH_STATS = { 0, 500000 };
34
+ static const struct timeval VNC_REFRESH_LOSSY = { 2, 0 };
35
+
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.