#!/usr/bin/env python3 """Build a dependency-free self-extracting .run installer (no makeself). Produces dist/rigdoctor--installer.run: a POSIX shell stub with an appended tar.gz of the wheel + install.sh. Running it extracts to a temp dir and runs install.sh. """ from __future__ import annotations import io import os import subprocess import sys import tarfile import tomllib from pathlib import Path ROOT = Path(__file__).resolve().parent.parent MARKER = "__RIGDOCTOR_ARCHIVE__" STUB = f"""#!/bin/sh # RigDoctor self-extracting installer. Extracts the embedded archive and runs install.sh. set -eu SKIP=$(awk '/^{MARKER}$/ {{ print NR + 1; exit 0 }}' "$0") TMP=$(mktemp -d) tail -n +"$SKIP" "$0" | tar -xz -C "$TMP" sh "$TMP/install.sh" "$@" RET=$? rm -rf "$TMP" exit $RET {MARKER} """ def main() -> int: version = tomllib.loads((ROOT / "pyproject.toml").read_text())["project"]["version"] dist = ROOT / "dist" dist.mkdir(exist_ok=True) wheel = dist / f"rigdoctor-{version}-py3-none-any.whl" if not wheel.exists(): subprocess.run([sys.executable, "-m", "build", "--wheel"], cwd=ROOT, check=True) if not wheel.exists(): print(f"wheel not found: {wheel}", file=sys.stderr) return 1 buf = io.BytesIO() with tarfile.open(fileobj=buf, mode="w:gz") as tar: tar.add(wheel, arcname=wheel.name) tar.add(ROOT / "install.sh", arcname="install.sh") out = dist / f"rigdoctor-{version}-installer.run" with open(out, "wb") as f: f.write(STUB.encode()) f.write(buf.getvalue()) os.chmod(out, 0o755) print(f"Built {out}") return 0 if __name__ == "__main__": raise SystemExit(main())