From 27bff61560364473c53eb20a1f0463b43bd27ecf Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Wed, 18 Nov 2026 20:35:10 +0100 Subject: [PATCH] refactor: one reader of the installer pin The launcher builders read install.py's SHA-256 through pins.installer_sha256 and the value install.sh pins through pins.PIN, which now sits beside the pattern pin_installer writes with. build_port kept a third copy of that pattern. --- scripts/installer_build/launcherindex.py | 3 ++- scripts/installer_build/pins.py | 11 +++++------ scripts/installer_build/port.py | 9 ++++----- scripts/sitegen/bootstrap.py | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/scripts/installer_build/launcherindex.py b/scripts/installer_build/launcherindex.py index 54235d10e..ef6459516 100644 --- a/scripts/installer_build/launcherindex.py +++ b/scripts/installer_build/launcherindex.py @@ -8,6 +8,7 @@ import json from pathlib import Path from core.paths import REPO_ROOT +from installer_build.pins import installer_sha256 from installer_build.port import ( BATOCERA_ZIP, MUOS_APP, @@ -53,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 = hashlib.sha256((root / "install.py").read_bytes()).hexdigest() + actual = installer_sha256(root) if actual != pinned_installer_sha256(root): raise ValueError("install.py is not the installer install.sh pins: re-pin the " "bootstraps before writing the launcher list") diff --git a/scripts/installer_build/pins.py b/scripts/installer_build/pins.py index 7edf2cb84..36079915e 100644 --- a/scripts/installer_build/pins.py +++ b/scripts/installer_build/pins.py @@ -17,6 +17,11 @@ 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 the name the site serves each bootstrap under. +PIN: dict[str, re.Pattern[str]] = { + SH_NAME: re.compile(r'^DEFAULT_INSTALL_SHA256="([0-9a-f]{64})"', re.M), + PS1_NAME: re.compile(r'^\s*\$defaultInstallSha256 = "([0-9a-f]{64})"', re.M), +} COMMAND = "python scripts/pin_installer.py" @@ -50,9 +55,3 @@ def write_pins(root: Path = ROOT) -> list[str]: path.write_bytes(new.encode("utf-8")) written.append(name) return written - - -PIN: dict[str, re.Pattern[str]] = { - SH_NAME: re.compile(r'^DEFAULT_INSTALL_SHA256="([0-9a-f]{64})"', re.M), - PS1_NAME: re.compile(r'^\s*\$defaultInstallSha256 = "([0-9a-f]{64})"', re.M), -} diff --git a/scripts/installer_build/port.py b/scripts/installer_build/port.py index eeb973e21..158219da6 100644 --- a/scripts/installer_build/port.py +++ b/scripts/installer_build/port.py @@ -2,12 +2,12 @@ from __future__ import annotations -import hashlib -import re import zipfile from pathlib import Path from core.paths import REPO_ROOT +from installer_build.pins import PIN, installer_sha256 +from model.guides import SH_NAME PORT_DIR = "retrobios" @@ -20,12 +20,11 @@ TOOLS_ZIP = "RetroBIOS-tools.zip" ARCHIVES = (PORT_ZIP, BATOCERA_ZIP, MUOS_APP, TOOLS_ZIP) # Which release pack serves each platform, read by tui.txt offline. PACKS_TABLE = "packs.txt" -_PIN = re.compile(r'^DEFAULT_INSTALL_SHA256="([0-9a-f]{64})"$', re.MULTILINE) def pinned_installer_sha256(root: Path = REPO_ROOT) -> str: """The SHA-256 install.sh accepts for install.py.""" - found = _PIN.search((root / "install.sh").read_text(encoding="utf-8")) + found = PIN[SH_NAME].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) @@ -137,7 +136,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) - actual = hashlib.sha256((root / "install.py").read_bytes()).hexdigest() + actual = installer_sha256(root) if actual != pinned: raise ValueError( f"install.py is {actual[:12]}, install.sh pins {pinned[:12]}: " diff --git a/scripts/sitegen/bootstrap.py b/scripts/sitegen/bootstrap.py index a868e189b..8e8289412 100644 --- a/scripts/sitegen/bootstrap.py +++ b/scripts/sitegen/bootstrap.py @@ -33,7 +33,7 @@ SOURCES: dict[str, tuple[str, re.Pattern[str]]] = { SH_NAME: ("install.sh", re.compile(r'^(DEFAULT_INSTALL_URL=")[^"]*(")', re.M)), PS1_NAME: ("install.ps1", re.compile(r'^(\s*\$defaultInstallUrl = ")[^"]*(")', re.M)), } -# The line each bootstrap says a refused installer with, and the pin. +# The line each bootstrap says a refused installer with. ADVICE: dict[str, re.Pattern[str]] = { SH_NAME: re.compile(r'^(MISMATCH_ADVICE=")[^"]*(")', re.M), PS1_NAME: re.compile(r'^(\s*\$mismatchAdvice = ")[^"]*(")', re.M),