Installers for all platforms and related fixes #1

Merged
LeoVasanko merged 38 commits from installer into main 2026-09-23 17:41:21 +00:00
Showing only changes of commit 3711d3dd3c - Show all commits
+17 -6
View File
@@ -426,11 +426,14 @@ def force_macos_user_install(pkg: Path) -> None:
Also drops the `sudo -u "$USER"` prefix from Velopack's postinstall Also drops the `sudo -u "$USER"` prefix from Velopack's postinstall
script: under a per-user install the script already runs as the script: under a per-user install the script already runs as the
installing user, and sudo would fail for lack of a tty. installing user, and sudo would fail for lack of a tty.
NB: only ever use `pkgutil --expand` (which keeps component Payloads
archived) — `--expand-full` flattens payloads to loose files that
`--flatten` cannot repack, producing a pkg that "installs" nothing.
""" """
expanded = pkg.with_name(pkg.stem + "-expanded") expanded = pkg.with_name(pkg.stem + "-expanded")
shutil.rmtree(expanded, ignore_errors=True) shutil.rmtree(expanded, ignore_errors=True)
# --expand-full also expands the component pkg, exposing its Scripts dir subprocess.run(["pkgutil", "--expand", str(pkg), str(expanded)], check=True)
subprocess.run(["pkgutil", "--expand-full", str(pkg), str(expanded)], check=True)
dist_xml = expanded / "Distribution" dist_xml = expanded / "Distribution"
xml = dist_xml.read_text() xml = dist_xml.read_text()
@@ -443,12 +446,20 @@ 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)
postinstalls = list(expanded.glob("*.pkg/Scripts/postinstall")) # Edit postinstall inside the (still archived) component pkg.
if len(postinstalls) != 1: components = [p for p in expanded.glob("*.pkg") if p.is_file()]
raise RuntimeError(f"Unexpected pkg layout: postinstalls={postinstalls}") if len(components) != 1:
postinstall = postinstalls[0] raise RuntimeError(f"Unexpected pkg layout: components={components}")
component = components[0]
comp_dir = expanded / (component.stem + "-component")
subprocess.run(["pkgutil", "--expand", str(component), str(comp_dir)], check=True)
postinstall = comp_dir / "Scripts" / "postinstall"
script = postinstall.read_text() script = postinstall.read_text()
if 'sudo -u "$USER" ' not in script:
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)
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)