| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 |
- #!/usr/bin/env python3
- """Assemble and deploy a completely unpacked (non-archive) Windows release tree
- covering 6400 V2.0, 6400 V1.1, MRDIMM V1.2, shared tools, board viewer, SDK, and docs.
- """
- from __future__ import annotations
- import argparse
- import base64
- from datetime import datetime, timezone
- import hashlib
- import json
- import os
- from pathlib import Path
- import shutil
- import subprocess
- import sys
- ROOT = Path(__file__).resolve().parents[1]
- BAUDS = (921600, 460800, 230400, 115200)
- def sha256_bytes(data: bytes) -> str:
- return hashlib.sha256(data).hexdigest()
- def sha256_file(path: Path) -> str:
- h = hashlib.sha256()
- with path.open("rb") as f:
- while chunk := f.read(1024 * 1024):
- h.update(chunk)
- return h.hexdigest()
- def copy_file(src: Path, dst: Path) -> None:
- dst.parent.mkdir(parents=True, exist_ok=True)
- shutil.copy2(src, dst)
- os.chmod(dst, 0o644)
- def write_text_crlf(dst: Path, text: str) -> None:
- dst.parent.mkdir(parents=True, exist_ok=True)
- dst.write_bytes(text.replace("\r\n", "\n").replace("\n", "\r\n").encode("utf-8"))
- def export_git_tree(repo: Path, ref: str, dst_dir: Path, *, exclude_prefixes: tuple[str, ...] = ()) -> int:
- count = 0
- raw = subprocess.check_output(["git", "-C", str(repo), "ls-tree", "-r", "-z", "--name-only", ref])
- for rel in raw.decode("utf-8").split("\0"):
- if not rel or any(rel == p or rel.startswith(p + "/") for p in exclude_prefixes):
- continue
- blob = subprocess.check_output(["git", "-C", str(repo), "show", f"{ref}:{rel}"])
- target = dst_dir / rel
- target.parent.mkdir(parents=True, exist_ok=True)
- target.write_bytes(blob)
- os.chmod(target, 0o644)
- count += 1
- return count
- def copy_working_tracked(repo: Path, dst_dir: Path, *, exclude_prefixes: tuple[str, ...] = ()) -> int:
- count = 0
- raw = subprocess.check_output(["git", "-C", str(repo), "ls-files", "-z"])
- for rel in raw.decode("utf-8").split("\0"):
- if not rel or any(rel == p or rel.startswith(p + "/") for p in exclude_prefixes):
- continue
- src = repo / rel
- if src.is_file():
- copy_file(src, dst_dir / rel)
- count += 1
- return count
- def copy_firmware_group(runs: dict[int, Path], dst_firmware: Path, stem: str) -> list[dict]:
- entries = []
- for baud in BAUDS:
- run_dir = runs[baud]
- receipt = json.loads((run_dir / "td-receipt.json").read_text(encoding="utf-8"))
- bit_rel = receipt["bitstream"]
- bit_src = Path(bit_rel) if Path(bit_rel).is_absolute() else (run_dir / bit_rel)
- bmk_src = bit_src.with_suffix(".bmk")
- if not bit_src.is_file():
- raise FileNotFoundError(f"missing bitstream: {bit_src}")
- if not bmk_src.is_file():
- raise FileNotFoundError(f"missing .bmk readback mask: {bmk_src}")
- if sha256_file(bit_src) != receipt.get("bitstream_sha256"):
- raise ValueError(f"bitstream SHA mismatch in {run_dir}")
- out_dir = dst_firmware / str(baud)
- out_dir.mkdir(parents=True, exist_ok=True)
- copy_file(bit_src, out_dir / f"{stem}_{baud}.bit")
- copy_file(bmk_src, out_dir / f"{stem}_{baud}.bmk")
- copy_file(bit_src, out_dir / "firmware.bit")
- copy_file(bmk_src, out_dir / "firmware.bmk")
- copy_file(run_dir / "td-receipt.json", out_dir / "td-receipt.json")
- entries.append({
- "baud": baud,
- "file": f"{stem}_{baud}.bit",
- "bit_sha256": receipt["bitstream_sha256"],
- "bmk_sha256": sha256_file(bmk_src),
- "metrics": receipt.get("metrics", {}),
- })
- return entries
- def main(argv: list[str] | None = None) -> int:
- parser = argparse.ArgumentParser(description=__doc__)
- parser.add_argument("--stage-dir", type=Path, default=Path("/data/prod2u/releases/v3.3.0-unpacked"))
- parser.add_argument("--destination", default=r"C:\Prod2U_Releases\v3.3.0-unpacked")
- parser.add_argument("--host", default="administrator@192.168.2.24")
- parser.add_argument("--v2-gui-dir", type=Path,
- default=Path("/data/prod2u/windows-exes/v330-b473cb32/windows-gui-20261124T094720Z-5ff363a4/artifacts/6400-v2"))
- parser.add_argument("--mrdimm-gui-dir", type=Path,
- default=Path("/data/prod2u/windows-exes/v330-b473cb32/windows-gui-20261124T094720Z-5ff363a4/artifacts/mrdimm-chamber"))
- parser.add_argument("--v11-exe", type=Path,
- default=Path("/data/prod2u/windows-exes/v330-6400-v11/Prod2U-6400-V11-PID-GUI-v3.3.0.exe"))
- parser.add_argument("--pwm-scope-exe", type=Path,
- default=Path("/data/prod2u/windows-exes/v330-extra/Prod2U-6400-V2-PWM-Scope-v3.3.0.exe"))
- parser.add_argument("--hth-repo", type=Path, default=Path("/workspace/hth-platform"))
- parser.add_argument("--v11-branch", default="6400-v1.1")
- parser.add_argument("--no-deploy", action="store_true")
- args = parser.parse_args(argv)
- stage = args.stage_dir.resolve()
- if stage.exists():
- shutil.rmtree(stage)
- stage.mkdir(parents=True, exist_ok=True)
- # ------------------------------------------------------------------
- # 1. 6400 V2.0 (mainline dev)
- # ------------------------------------------------------------------
- v2_dir = stage / "6400_V2.0"
- v2_runs = {b: Path(f"/data/prod2u/cpld-runs/v330-b473cb32-6400-v2-{b}") for b in BAUDS}
- v2_fw = copy_firmware_group(v2_runs, v2_dir / "Firmware", "prod2u_6400_v2")
- copy_file(args.v2_gui_dir / "Prod2U-6400-V2-GUI-v3.3.0.exe", v2_dir / "Prod2U-6400-V2-GUI-v3.3.0.exe")
- if args.pwm_scope_exe.is_file():
- copy_file(args.pwm_scope_exe, v2_dir / "Prod2U-6400-V2-PWM-Scope-v3.3.0.exe")
- for name in ("prod2u_6400_v2.adc", "prod2u_6400_v2.sdc"):
- copy_file(ROOT / "constraints" / name, v2_dir / "Constraints" / name)
- for f in sorted((ROOT / "generated" / "6400-v2").iterdir()):
- if f.is_file():
- copy_file(f, v2_dir / "Generated" / f.name)
- for s in ("6400_v2_hex_gui.py", "prod2u_gui.py", "pwm_scope.py", "get_all.py",
- "monitor_10min.py", "serial_hardware_check.py", "stream_receiver.py", "run_v3_protocol.py"):
- copy_file(ROOT / "tools" / s, v2_dir / "Scripts" / s)
- for v in ("hth_protocol.py", "prod2u_status.py"):
- copy_file(ROOT / "tools" / "_vendor" / v, v2_dir / "Scripts" / "_vendor" / v)
- write_text_crlf(v2_dir / "RUN_6400_V2_GUI.cmd", "@echo off\r\ncd /d \"%~dp0\"\r\nstart \"\" \"%~dp0Prod2U-6400-V2-GUI-v3.3.0.exe\"\r\n")
- write_text_crlf(
- v2_dir / "RUN_PWM_SCOPE_MAP.cmd",
- "@echo off\r\nchcp 65001 >nul\r\ncd /d \"%~dp0\"\r\n"
- "if exist \"%~dp0Prod2U-6400-V2-PWM-Scope-v3.3.0.exe\" (\r\n"
- " \"%~dp0Prod2U-6400-V2-PWM-Scope-v3.3.0.exe\" --dry-run\r\n"
- ") else (\r\n"
- " py -3.12 \"%~dp0..\\Shared_Tools\\Repo_Source\\tools\\pwm_scope.py\" --dry-run\r\n"
- ")\r\npause\r\n",
- )
- # ------------------------------------------------------------------
- # 2. 6400 V1.1 (standalone branch 6400-v1.1)
- # ------------------------------------------------------------------
- v11_dir = stage / "6400_V1.1"
- v11_runs = {b: Path(f"/data/prod2u/cpld-runs/v330-6400v11-f78f9ffa-{b}") for b in BAUDS}
- v11_fw = copy_firmware_group(v11_runs, v11_dir / "Firmware", "prod2u_6400_v1_1")
- copy_file(args.v11_exe, v11_dir / "Prod2U-6400-V11-PID-GUI-v3.3.0.exe")
- v11_source_dir = v11_dir / "Source"
- export_git_tree(
- ROOT,
- args.v11_branch,
- v11_source_dir,
- exclude_prefixes=(
- "tools/board-viewer/node_modules",
- "reference/original/board",
- "reauth-backup",
- "evidence/input_reauth_r3",
- ),
- )
- for name in ("prod2u_6400_front_back.adc", "prod2u_6400_front_back.sdc"):
- copy_file(v11_source_dir / "constraints" / name, v11_dir / "Constraints" / name)
- for f in sorted((v11_source_dir / "generated" / "6400").iterdir()):
- if f.is_file():
- copy_file(f, v11_dir / "Generated" / f.name)
- for s in ("v11_nomcu_gui.py", "v11_adaptive_pid.py", "v11_bmc_net.py"):
- copy_file(v11_source_dir / "tools" / s, v11_dir / "Scripts" / s)
- copy_file(v11_source_dir / "VERSION", v11_dir / "Scripts" / "VERSION")
- write_text_crlf(v11_dir / "RUN_6400_V11_PID_GUI.cmd", "@echo off\r\ncd /d \"%~dp0\"\r\nstart \"\" \"%~dp0Prod2U-6400-V11-PID-GUI-v3.3.0.exe\"\r\n")
- write_text_crlf(
- v11_dir / "PROBE_BMC_192.168.2.168.cmd",
- "@echo off\r\nchcp 65001 >nul\r\ncd /d \"%~dp0\"\r\n"
- "\"%~dp0Prod2U-6400-V11-PID-GUI-v3.3.0.exe\" --probe-bmc 192.168.2.168\r\npause\r\n",
- )
- # ------------------------------------------------------------------
- # 3. MRDIMM V1.2 (mainline dev)
- # ------------------------------------------------------------------
- mr_dir = stage / "MRDIMM_V1.2"
- mr_runs = {b: Path(f"/data/prod2u/cpld-runs/v330-b473cb32-mrdimm-{b}") for b in BAUDS}
- mr_fw = copy_firmware_group(mr_runs, mr_dir / "Firmware", "prod2u_mrdimm")
- copy_file(args.mrdimm_gui_dir / "Prod2U-MRDIMM-GUI-v3.3.0.exe", mr_dir / "Prod2U-MRDIMM-GUI-v3.3.0.exe")
- for name in ("prod2u_mrdimm.adc", "prod2u_mrdimm.sdc", "prod2u_mrdimm_chamber.adc", "prod2u_mrdimm_chamber.sdc"):
- copy_file(ROOT / "constraints" / name, mr_dir / "Constraints" / name)
- for f in sorted((ROOT / "generated" / "mrdimm").iterdir()):
- if f.is_file():
- copy_file(f, mr_dir / "Generated" / f.name)
- for s in ("mrdimm_hex_gui.py", "prod2u_gui.py", "stream_receiver.py",
- "test_single_channel_motion.py", "serial_hardware_check.py", "run_v3_protocol.py"):
- copy_file(ROOT / "tools" / s, mr_dir / "Scripts" / s)
- for v in ("hth_protocol.py", "prod2u_status.py"):
- copy_file(ROOT / "tools" / "_vendor" / v, mr_dir / "Scripts" / "_vendor" / v)
- write_text_crlf(mr_dir / "RUN_MRDIMM_GUI.cmd", "@echo off\r\ncd /d \"%~dp0\"\r\nstart \"\" \"%~dp0Prod2U-MRDIMM-GUI-v3.3.0.exe\"\r\n")
- # ------------------------------------------------------------------
- # 4. Shared Tools: Full unpacked Repo_Source + Board Viewer + Thermal Web + hth-platform
- # ------------------------------------------------------------------
- shared = stage / "Shared_Tools"
- repo_dst = shared / "Repo_Source"
- copy_working_tracked(
- ROOT,
- repo_dst,
- exclude_prefixes=(
- "tools/board-viewer/node_modules",
- "tools/board-viewer/rust-server/target",
- "reference/original/board/EF2L45BG256B_MINI_V2.0",
- ),
- )
- # Include regenerated/untracked board-viewer runtime assets & schematics needed for offline Windows viewing
- bv_src = ROOT / "tools" / "board-viewer"
- bv_dst = repo_dst / "tools" / "board-viewer"
- for bundle in ("generated", "generated-v1_1", "generated-v2_0", "generated-v2_0_fan"):
- bdir = bv_src / bundle
- if bdir.is_dir():
- for f in sorted(bdir.iterdir()):
- if f.is_file():
- copy_file(f, bv_dst / bundle / f.name)
- for extra in ("v2_0_components_cache.json", "v2_0_fan_components_cache.json",
- "v2_0_schematic_bom.json", "v2_0_silkscreen_texts.json"):
- if (bv_src / extra).is_file():
- copy_file(bv_src / extra, bv_dst / extra)
- if (ROOT / "reference" / "original" / "schematics").is_dir():
- for f in sorted((ROOT / "reference" / "original" / "schematics").iterdir()):
- if f.is_file():
- copy_file(f, repo_dst / "reference" / "original" / "schematics" / f.name)
- for brd_rel in (
- "reference/original/board/FCB_FPGA_MCU_V1.2_20260717/FCB_FPGA+MCU_V1.2_20260717.brd",
- "reference/original/board/FCB_FPGA_MCU_V1.1_20260625/FCB_FPGA+MCU_V1.1_20260625.brd",
- "reference/original/board/FCB_FPGA_MCU_V2.0_20260914/FCB_FPGA+MCU_V2.0_20260914.brd",
- "reference/original/board/FCB_FAN_V2.0_20260914/FCB_FAN_V2.0_20260914.brd",
- ):
- brd_src = ROOT / brd_rel
- if brd_src.is_file():
- copy_file(brd_src, repo_dst / brd_rel)
- copy_working_tracked(args.hth_repo, shared / "hth-platform")
- write_text_crlf(
- shared / "OPEN_BOARD_VIEWER.cmd",
- "@echo off\r\nchcp 65001 >nul\r\ncall \"%~dp0Repo_Source\\tools\\board-viewer\\OPEN_BOARD_VIEWER.cmd\"\r\n",
- )
- write_text_crlf(
- shared / "START_THERMAL_WEB.cmd",
- "@echo off\r\nchcp 65001 >nul\r\ncd /d \"%~dp0Repo_Source\"\r\n"
- "start \"\" \"http://127.0.0.1:8766\"\r\n"
- "py -3.12 tools\\thermal_test_server.py --host 127.0.0.1 --port 8766\r\npause\r\n",
- )
- # ------------------------------------------------------------------
- # 5. Docs & Top-level README
- # ------------------------------------------------------------------
- docs_dir = stage / "Docs"
- copy_file(ROOT / "docs" / "CPLD_通讯协议v2.0.md", stage / "CPLD_通讯协议v2.0.md")
- for rel in (
- "docs/CPLD_通讯协议v2.0.md",
- "docs/releases/v3.3.0.md",
- "docs/evidence/6400-v2-electrical-alignment.md",
- "docs/pwm-scope.md",
- "docs/TD_USAGE.zh-CN.md",
- ):
- src = ROOT / rel
- if src.is_file():
- copy_file(src, docs_dir / src.name)
- v11_doc = v11_source_dir / "docs" / "releases" / "6400-v1.1-v3.3.0.md"
- if v11_doc.is_file():
- copy_file(v11_doc, docs_dir / "6400-v1.1-v3.3.0.md")
- dev_commit = subprocess.check_output(["git", "-C", str(ROOT), "rev-parse", "--short=8", "HEAD"], text=True).strip()
- v11_commit = subprocess.check_output(["git", "-C", str(ROOT), "rev-parse", "--short=8", args.v11_branch], text=True).strip()
- readme = f"""# Prod2U CPLD v3.3.0 全板卡非压缩包发布目录
- > 部署时间 (UTC): {datetime.now(timezone.utc).isoformat()}
- > 主线 `dev` (`6400-v2` + `mrdimm`): `{dev_commit}`
- > 独立分支 `6400-v1.1` (绝不合入 `dev`): `{v11_commit}`
- > 说明:本目录为**完全非压缩包**形式,所有 EXE、脚本、固件 `.bit`/`.bmk`、约束 `.adc`/`.sdc`、RTL 源码、电路板选脚查看器、SDK 与协议文档均可直接打开或双击运行,无需解压。
- ---
- ## 目录导航
- 1. **`6400_V2.0\\`** — **6400 V2.0 高温罩**(`dev` 主线)
- - `Prod2U-6400-V2-GUI-v3.3.0.exe`(可双击 `RUN_6400_V2_GUI.cmd`):实时串口控制 + 24 PTC / 4 进风 / 4 出风 / 3 SSR / 急停 `EPB1(F8)` / 开罩 `SB1(C11)` / 合罩 `SB2(A11)` / 4000Hz 80% 蜂鸣器 `H6` + 腔体温度曲线 & 70℃ 温度测试
- - `Prod2U-6400-V2-PWM-Scope-v3.3.0.exe`(可双击 `RUN_PWM_SCOPE_MAP.cmd`):20Hz PWM 示波器串口验收 & 35 路通道 / CT7428 映射工具(接板实测示例:`Prod2U-6400-V2-PWM-Scope-v3.3.0.exe --port COM3`)
- - `Firmware\\{{921600,460800,230400,115200}}\\prod2u_6400_v2_<baud>.bit` + `.bmk` + `td-receipt.json`(TD 2026.1 SP2 实测 `1,664` LUT / `1,009` Packed Slice @ 921600)
- - `Constraints\\prod2u_6400_v2.adc` / `.sdc`,`Generated\\` 协议契约,`Scripts\\` Python 源码
- 2. **`6400_V1.1\\`** — **6400 V1.1 无 MCU 方案**(独立分支 `6400-v1.1`)
- - `Prod2U-6400-V11-PID-GUI-v3.3.0.exe`(可双击 `RUN_6400_V11_PID_GUI.cmd`):Windows 自适应 PID(RLS + Smith 预测 + 三区间增益调度 + 均温微调)+ **BMC NET 直采 24 路 DIMM 温度(IPMI v2.0 RMCP+ UDP:623)**
- - `PROBE_BMC_192.168.2.168.cmd`:一键测试通过 BMC 网口直采 24 路 DIMM 温度
- - `Firmware\\{{921600,460800,230400,115200}}\\prod2u_6400_v1_1_<baud>.bit` + `.bmk` + `td-receipt.json`(TD 2026.1 SP2 实测 `1,284` LUT / `774` Packed Slice @ 921600)
- - `Constraints\\prod2u_6400_front_back.adc` / `.sdc`,`Scripts\\` (`v11_nomcu_gui.py`, `v11_adaptive_pid.py`, `v11_bmc_net.py`),`Source\\` 完整 `6400-v1.1` 分支源码
- 3. **`MRDIMM_V1.2\\`** — **MRDIMM V1.2(8000 / FCB V1.2)**(`dev` 主线)
- - `Prod2U-MRDIMM-GUI-v3.3.0.exe`(可双击 `RUN_MRDIMM_GUI.cmd`):12 轴有限段步进电机 + 4 FAN + 4 逻辑 PTC(24 物理) + 高温罩开关 `L3` + 4000Hz 80% 蜂鸣器 `H6` + CT/BMC 遥测
- - `Firmware\\{{921600,460800,230400,115200}}\\prod2u_mrdimm_<baud>.bit` + `.bmk` + `td-receipt.json`(TD 2026.1 SP2 实测 `2,021` LUT / `1,190` Packed Slice @ 921600)
- - `Constraints\\` + `Generated\\` + `Scripts\\`
- 4. **`Shared_Tools\\`** — **通用工具(非压缩包可直接运行)**
- - `OPEN_BOARD_VIEWER.cmd`:双击启动本地电路板选脚查看器(同步含 V1.1 / V1.2 / V2.0 / V2.0_FAN 与原理图 PDF)
- - `START_THERMAL_WEB.cmd`:双击在本地 `http://127.0.0.1:8766` 启动高温罩温度测试 Web 前后端(远程常驻服务位于 `http://192.168.2.25:8766/`)
- - `hth-platform\\`:完整 `hth_platform` Python SDK 与示例
- - `Repo_Source\\`:主线 `dev` 完整非压缩源码仓库
- 5. **`Docs\\` 与根目录 `CPLD_通讯协议v2.0.md`**
- - 完整覆盖三板最新通讯协议、引脚对齐与 TD 发布记录。
- """
- (stage / "00_README_目录说明.md").write_text(readme, encoding="utf-8")
- manifest_summary = {
- "version": "3.3.0",
- "dev_commit": dev_commit,
- "v11_commit": v11_commit,
- "firmware": {"6400-v2": v2_fw, "6400-v1.1": v11_fw, "mrdimm": mr_fw},
- }
- (stage / "RELEASE-INDEX.json").write_text(json.dumps(manifest_summary, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
- inventory = [
- {"path": p.relative_to(stage).as_posix(), "sha256": sha256_file(p), "size_bytes": p.stat().st_size}
- for p in sorted(stage.rglob("*"))
- if p.is_file() and p.name != "DELIVERY-SHA256.json"
- ]
- dest = args.destination.rstrip("/\\")
- long_paths = [
- f"{dest}\\{item['path'].replace('/', chr(92))}"
- for item in inventory
- if len(f"{dest}\\{item['path'].replace('/', chr(92))}") >= 235
- ]
- if long_paths:
- raise ValueError(f"Windows path length >=235 chars ({len(long_paths)} files), e.g. {long_paths[0]}")
- (stage / "DELIVERY-SHA256.json").write_bytes((json.dumps(inventory, indent=2, ensure_ascii=False) + "\n").encode("utf-8"))
- print(f"Staged {len(inventory)} unpacked files in {stage}")
- if args.no_deploy:
- return 0
- def ps(text: str) -> str:
- return "powershell -NoProfile -NonInteractive -EncodedCommand " + base64.b64encode(text.encode("utf-16le")).decode()
- def ps_q(text: str) -> str:
- return "'" + text.replace("'", "''") + "'"
- # Create or cleanly replace target unpacked directory, stream via tar over SSH (leaves zero archives on Windows)
- prep = f"""
- $ErrorActionPreference = 'Stop'
- $p = {ps_q(dest)}
- if (Test-Path $p) {{ Remove-Item -Recurse -Force $p }}
- New-Item -ItemType Directory -Path $p -Force | Out-Null
- """
- subprocess.run(["ssh", "-o", "ConnectTimeout=10", args.host, ps(prep)], check=True)
- tar_proc = subprocess.Popen(
- ["tar", "-cf", "-", "-C", str(stage), "."],
- stdout=subprocess.PIPE,
- )
- extract_code = (
- "import sys, tarfile\n"
- f"tarfile.open(fileobj=sys.stdin.buffer, mode='r|*').extractall({dest!r}, filter='data')\n"
- )
- b64_extract = base64.b64encode(extract_code.encode("utf-8")).decode("ascii")
- subprocess.run(
- ["ssh", "-o", "ConnectTimeout=10", args.host,
- f'py -3.12 -c "import base64; exec(base64.b64decode(\'{b64_extract}\'))"'],
- stdin=tar_proc.stdout,
- check=True,
- )
- tar_proc.stdout.close()
- if tar_proc.wait() != 0:
- raise RuntimeError("tar stream creation failed")
- verify = f"""
- $ErrorActionPreference = 'Stop'
- $ProgressPreference = 'SilentlyContinue'
- [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
- $root = {ps_q(dest)}
- $items = Get-Content -LiteralPath (Join-Path $root 'DELIVERY-SHA256.json') -Raw -Encoding UTF8 | ConvertFrom-Json
- $verified = 0
- foreach ($item in $items) {{
- $path = Join-Path $root $item.path
- if (-not (Test-Path -LiteralPath $path)) {{ throw ('Missing file: ' + $item.path) }}
- $actual = (Get-FileHash -LiteralPath $path -Algorithm SHA256).Hash.ToLowerInvariant()
- $size = (Get-Item -LiteralPath $path).Length
- if ($actual -ne $item.sha256 -or $size -ne $item.size_bytes) {{
- throw ('SHA or size mismatch: ' + $item.path + ' actual=' + $actual + ' expected=' + $item.sha256)
- }}
- $verified++
- }}
- $receipt = @{{
- status = 'PASS'
- scope = 'unpacked directory transfer and per-file SHA256 verification'
- host = $env:COMPUTERNAME
- destination = $root
- verified_files = $verified
- hardware_validation = 'NOT_RUN_BY_DELIVERY'
- utc = [DateTime]::UtcNow.ToString('o')
- }}
- $receipt | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $root 'DELIVERY-RECEIPT.json') -Encoding UTF8
- Write-Output ('DELIVERY_UNPACKED_SHA256_PASS ' + $verified)
- """
- res = subprocess.run(
- ["ssh", "-o", "ConnectTimeout=10", args.host, ps(verify)],
- capture_output=True, text=True, check=True,
- )
- print(res.stdout.strip())
- receipt_local = stage.parent / (stage.name + "-delivery-receipt.json")
- scp_src = args.host + ":" + dest.replace("\\", "/") + "/DELIVERY-RECEIPT.json"
- subprocess.run(["scp", scp_src, str(receipt_local)], check=True)
- print(f"Receipt saved to {receipt_local}")
- return 0
- if __name__ == "__main__":
- raise SystemExit(main())
|