fix: refuse a second installer pin line

pinned_sha256 in installer_build.pins reads the one pin of a bootstrap and refuses any other count. stale_pins, build_port, the launcher index, the PyPI build and the site bootstraps all read it: three of them took the first line, while sh runs with the last.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:02:28 +01:00
1 parent b9441c545d
commit 87329ca7ee
9 files changed
+50 -43

No files matched your search

+2 -3
View File
@@ -8,14 +8,13 @@ import json
from pathlib import Path
from core.paths import REPO_ROOT
from installer_build.pins import installer_sha256
from installer_build.pins import installer_sha256, pinned_sha256
from installer_build.port import (
BATOCERA_ZIP,
MUOS_APP,
TOOLS_ZIP,
packs_table,
archive_members,
pinned_installer_sha256,
)
@@ -55,7 +54,7 @@ def _member_bytes(entry: dict, root: Path) -> bytes:
def build_index(root: Path = REPO_ROOT) -> dict:
"""Every launcher a card can carry, from the archives' members."""
actual = installer_sha256(root)
if actual != pinned_installer_sha256(root):
if actual != pinned_sha256("install.sh", root):
raise ValueError("install.py is not the installer install.sh pins: re-pin the "
"bootstraps before writing the launcher list")
places = {place.key: place for place in _install.APP_PLACES.values()}
+16 -17
View File
@@ -10,15 +10,11 @@ from core.paths import REPO_ROOT
INSTALLER = "install.py"
# Each bootstrap and its one pin line, the value between the two groups.
# Each bootstrap and its one pin line: the text before the value, the
# value, the text after it.
PINS: dict[str, re.Pattern[str]] = {
"install.sh": re.compile(r'^(DEFAULT_INSTALL_SHA256=")[0-9a-f]{64}(")', re.M),
"install.ps1": re.compile(r'^(\s*\$defaultInstallSha256 = ")[0-9a-f]{64}(")', re.M),
}
# The value of that pin line, by bootstrap.
PIN: dict[str, re.Pattern[str]] = {
"install.sh": re.compile(r'^DEFAULT_INSTALL_SHA256="([0-9a-f]{64})"', re.M),
"install.ps1": re.compile(r'^\s*\$defaultInstallSha256 = "([0-9a-f]{64})"', re.M),
"install.sh": re.compile(r'^(DEFAULT_INSTALL_SHA256=")([0-9a-f]{64})(")', re.M),
"install.ps1": re.compile(r'^(\s*\$defaultInstallSha256 = ")([0-9a-f]{64})(")', re.M),
}
COMMAND = "python scripts/pin_installer.py"
@@ -27,17 +23,20 @@ def installer_sha256(root: Path = REPO_ROOT) -> str:
return file_digest(root / INSTALLER, "sha256")
def pinned_sha256(name: str, root: Path = REPO_ROOT) -> str:
"""The SHA-256 the bootstrap *name* accepts for install.py. Exactly one
pin line: sh and PowerShell keep the last assignment, so a second line
would be the value the bootstrap runs with."""
found = PINS[name].findall((root / name).read_bytes().decode("utf-8"))
if len(found) != 1:
raise ValueError(f"{name}: {len(found)} installer pin lines, expected 1")
return found[0][1]
def stale_pins(root: Path = REPO_ROOT) -> list[str]:
"""The bootstraps whose pin is not the SHA-256 of install.py."""
digest = installer_sha256(root)
stale = []
for name, pin in PINS.items():
found = pin.search((root / name).read_bytes().decode("utf-8"))
if found is None:
raise ValueError(f"{name}: no installer pin line")
if found.group(0) != f"{found.group(1)}{digest}{found.group(2)}":
stale.append(name)
return stale
return [name for name in PINS if pinned_sha256(name, root) != digest]
def write_pins(root: Path = REPO_ROOT) -> list[str]:
@@ -47,7 +46,7 @@ def write_pins(root: Path = REPO_ROOT) -> list[str]:
for name in stale_pins(root):
path = root / name
text = path.read_bytes().decode("utf-8")
new, count = PINS[name].subn(rf"\g<1>{digest}\g<2>", text)
new, count = PINS[name].subn(rf"\g<1>{digest}\g<3>", text)
if count != 1:
raise ValueError(f"{name}: {count} installer pin lines, expected 1")
path.write_bytes(new.encode("utf-8"))
+2 -10
View File
@@ -6,7 +6,7 @@ import zipfile
from pathlib import Path
from core.paths import REPO_ROOT
from installer_build.pins import PIN, installer_sha256
from installer_build.pins import installer_sha256, pinned_sha256
PORT_DIR = "retrobios"
@@ -21,14 +21,6 @@ ARCHIVES = (PORT_ZIP, BATOCERA_ZIP, MUOS_APP, TOOLS_ZIP)
PACKS_TABLE = "packs.txt"
def pinned_installer_sha256(root: Path = REPO_ROOT) -> str:
"""The SHA-256 install.sh accepts for install.py."""
found = PIN["install.sh"].search((root / "install.sh").read_text(encoding="utf-8"))
if found is None:
raise ValueError("install.sh pins no installer SHA-256")
return found.group(1)
def _engine(folder: str, root: Path, mapping: bool = True) -> list[tuple[str, Path | None]]:
"""What every launcher runs: the installer, the interface launcher, the
event reader, the licenses, and the gptokeyb mapping where one is read."""
@@ -134,7 +126,7 @@ def packs_table(root: Path) -> bytes:
def build_archive(name: str, output: Path, root: Path = REPO_ROOT) -> Path:
"""Write the launcher archive *name* to *output* and return it."""
pinned = pinned_installer_sha256(root)
pinned = pinned_sha256("install.sh", root)
actual = installer_sha256(root)
if actual != pinned:
raise ValueError(
+2 -3
View File
@@ -11,7 +11,7 @@ import tempfile
from pathlib import Path
from core.paths import REPO_ROOT
from installer_build.pins import PIN
from installer_build.pins import pinned_sha256
PACKAGE_DIR = REPO_ROOT / "packaging" / "pypi"
@@ -58,8 +58,7 @@ def installer_bytes() -> bytes:
"""install.py, refused unless it is the one install.sh pins: the package
then runs the installer the one-line command runs, under the same id."""
data = (REPO_ROOT / "install.py").read_bytes()
pins = PIN["install.sh"].findall((REPO_ROOT / "install.sh").read_text(encoding="utf-8"))
if pins != [hashlib.sha256(data).hexdigest()]:
if pinned_sha256("install.sh", REPO_ROOT) != hashlib.sha256(data).hexdigest():
raise ValueError("install.py is not the installer install.sh pins: recompute the pin")
return data
+4 -6
View File
@@ -20,7 +20,7 @@ from pathlib import Path
from core.artifacts import write_if_changed
from model.guides import PS1_NAME, SH_NAME
from installer_build.pins import PIN, installer_sha256
from installer_build.pins import installer_sha256, pinned_sha256
from sitegen.config import build_commit
REPO_RAW = "https://raw.githubusercontent.com/Abdess/retrobios"
@@ -57,12 +57,10 @@ def served_text(name: str, root: Path, commit: str) -> str:
pair served."""
source, line = SOURCES[name]
text = (root / source).read_text(encoding="utf-8")
pinned = PIN[source].findall(text)
if len(pinned) != 1:
raise ValueError(f"{source}: {len(pinned)} installer pins, expected one")
pinned = pinned_sha256(source, root)
actual = installer_sha256(root)
if pinned[0] != actual:
raise ValueError(f"{source} pins {pinned[0][:12]}, install.py is {actual[:12]}: "
if pinned != actual:
raise ValueError(f"{source} pins {pinned[:12]}, install.py is {actual[:12]}: "
"re-pin the bootstrap before the site serves it")
served, count = line.subn(
lambda m: f"{m.group(1)}{installer_url(commit)}{m.group(2)}", text