Tolerate expanded-component pkg layout on newer macOS
release / gui-build (linux, bash) (push) Successful in 44s
release / gui-build (windows, cmd) (push) Successful in 1m16s
release / gui-build (macos, bash) (push) Successful in 1m22s

pkgutil --expand may yield the component as an already-expanded
directory rather than an archived file; handle both. List the expanded
contents in the error message if the layout is unexpected.
This commit is contained in:
2026-09-23 03:33:06 +00:00
parent aeb6958aab
commit 9e0ccb13bd
+14 -7
View File
@@ -446,20 +446,27 @@ def force_macos_user_install(pkg: Path) -> None:
raise RuntimeError("Unexpected distribution.xml: <domains> not found") raise RuntimeError("Unexpected distribution.xml: <domains> not found")
dist_xml.write_text(new_xml) dist_xml.write_text(new_xml)
# Edit postinstall inside the (still archived) component pkg. # Edit postinstall inside the component pkg. Depending on the macOS
components = [p for p in expanded.glob("*.pkg") if p.is_file()] # version, --expand leaves the component as an archived file (needs a
# nested expand/flatten round) or as an already-expanded directory.
components = list(expanded.glob("*.pkg"))
if len(components) != 1: if len(components) != 1:
raise RuntimeError(f"Unexpected pkg layout: components={components}") contents = sorted(p.name for p in expanded.iterdir())
raise RuntimeError(f"Unexpected pkg layout: components={components} in {contents}")
component = components[0] component = components[0]
comp_dir = expanded / (component.stem + "-component") if component.is_dir():
subprocess.run(["pkgutil", "--expand", str(component), str(comp_dir)], check=True) comp_dir = component
else:
comp_dir = expanded / (component.stem + "-component")
subprocess.run(["pkgutil", "--expand", str(component), str(comp_dir)], check=True)
postinstall = comp_dir / "Scripts" / "postinstall" postinstall = comp_dir / "Scripts" / "postinstall"
script = postinstall.read_text() script = postinstall.read_text()
if 'sudo -u "$USER" ' not in script: if 'sudo -u "$USER" ' not in script:
raise RuntimeError("Unexpected postinstall script: sudo prefix not found") raise RuntimeError("Unexpected postinstall script: sudo prefix not found")
postinstall.write_text(script.replace('sudo -u "$USER" ', "")) postinstall.write_text(script.replace('sudo -u "$USER" ', ""))
subprocess.run(["pkgutil", "--flatten", str(comp_dir), str(component)], check=True) if comp_dir is not component:
shutil.rmtree(comp_dir) subprocess.run(["pkgutil", "--flatten", str(comp_dir), str(component)], check=True)
shutil.rmtree(comp_dir)
subprocess.run(["pkgutil", "--flatten", str(expanded), str(pkg)], check=True) subprocess.run(["pkgutil", "--flatten", str(expanded), str(pkg)], check=True)
shutil.rmtree(expanded) shutil.rmtree(expanded)