From dd861241652faaf5fcaf8f82de1d20f7de01a8fe Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sun, 18 Oct 2026 08:29:50 +0200 Subject: [PATCH] fix: name platform and folder in the sudo advice --- install.ps1 | 2 +- install.py | 18 +++++++++++++++--- install.sh | 2 +- tests/test_install.py | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/install.ps1 b/install.ps1 index b08adde8..ac2fdecf 100644 --- a/install.ps1 +++ b/install.ps1 @@ -8,7 +8,7 @@ param( $ErrorActionPreference = "Stop" $defaultInstallUrl = "https://raw.githubusercontent.com/Abdess/retrobios/main/install.py" -$defaultInstallSha256 = "39f3864183bd67c30c5705fccf39961aac0ad2d40238398ab2a67ef329eff359" +$defaultInstallSha256 = "b6a90d5cecf61b6bcb2a48ef440a57c56d0792ca0986c2c5dd9ba952dda3a221" $maximumInstallerBytes = 2MB $installerExit = 0 $installer = if ($PSScriptRoot) { Join-Path $PSScriptRoot "install.py" } else { $null } diff --git a/install.py b/install.py index cc8f99fc..df7c6a76 100644 --- a/install.py +++ b/install.py @@ -2296,7 +2296,7 @@ def _write_refused(exc: OSError) -> bool: return isinstance(exc, PermissionError) or exc.errno == errno.EROFS -def _write_advice(path: Path, assumed: bool) -> str: +def _write_advice(path: Path, assumed: bool, plat: str = "") -> str: """What to do about a folder this run could not write. sudo fixes a root-owned BIOS folder on the console itself. On another @@ -2307,6 +2307,13 @@ def _write_advice(path: Path, assumed: bool) -> str: return (f" {path} is where the platform keeps its BIOS on its own system, " "and it was not found here. If this machine prepares its card or " "share, run the same command with --dest pointing at that folder.") + if plat: + # sudo resets HOME to root's on Debian, Ubuntu, Arch and SteamOS: + # the same command detected nothing there, fell back to a folder + # under /root and reported success. + return (" This user cannot write there. Run it again with sudo, naming the " + f"folder so root does not look in its own home: --platform {plat} " + f"--dest '{path.absolute()}'. Or choose another folder with --dest.") return (" This user cannot write there: run the same command with sudo, " "or choose another folder with --dest.") @@ -2329,6 +2336,7 @@ def _report_outcome( declined: int = 0, assumed: set[Path] | None = None, omitted_entries: list[dict] | None = None, + platform_of: dict[Path, str] | None = None, ) -> None: """Close the run on what happened, and leave with a status that says so. @@ -2353,7 +2361,10 @@ def _report_outcome( sys.exit(130) refused = any(reason == NOT_WRITABLE for _dest, reason in failures or []) - advice = [_write_advice(path, path in (assumed or set())) for path in paths] if refused else [] + advice = [ + _write_advice(path, path in (assumed or set()), (platform_of or {}).get(path, "")) + for path in paths + ] if refused else [] if errors and not downloaded: print(f"\nNothing was installed. {_plural(errors, 'file')} failed.") @@ -3325,7 +3336,7 @@ def _install(args: argparse.Namespace, real_stdout: TextIO) -> None: sys.stdout.flush() print(f"\nCannot create {bios_path}.", file=sys.stderr) print(f" {exc.strerror}.", file=sys.stderr) - print(_write_advice(bios_path, bios_path in assumed_dests), + print(_write_advice(bios_path, bios_path in assumed_dests, plat_name), file=sys.stderr) # The documented code for a folder that cannot be written, # as when it exists read-only; 1 once an earlier platform @@ -3392,6 +3403,7 @@ def _install(args: argparse.Namespace, real_stdout: TextIO) -> None: declined=total_declined, assumed=assumed_dests, omitted_entries=omitted_seen, + platform_of={path: plat for plat, path in platforms}, ) diff --git a/install.sh b/install.sh index 9f774e88..c5c50a03 100755 --- a/install.sh +++ b/install.sh @@ -18,7 +18,7 @@ esac TEMP_INSTALLER="" TEMP_DIRECTORY="" DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/install.py" -DEFAULT_INSTALL_SHA256="39f3864183bd67c30c5705fccf39961aac0ad2d40238398ab2a67ef329eff359" +DEFAULT_INSTALL_SHA256="b6a90d5cecf61b6bcb2a48ef440a57c56d0792ca0986c2c5dd9ba952dda3a221" MAX_INSTALLER_BYTES=2097152 cleanup() { diff --git a/tests/test_install.py b/tests/test_install.py index f13e38c5..5f535520 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -2158,5 +2158,20 @@ class AnUnwritableFolderIsCodeTwo(unittest.TestCase): self.assertEqual(proc.returncode, 2, proc.stdout + proc.stderr) + +class SudoAdviceNamesTheFolder(unittest.TestCase): + """"Run the same command with sudo" re-ran detection under root's HOME, + found nothing, installed under /root and reported success.""" + + def test_the_advice_carries_platform_and_folder(self): + advice = install._write_advice(Path("/media/card/Emulation/bios"), False, "emudeck") + self.assertIn("--platform emudeck", advice) + self.assertIn("--dest '/media/card/Emulation/bios'", advice) + + def test_the_closing_report_passes_the_platform(self): + source = (REPO_ROOT / "install.py").read_text(encoding="utf-8") + self.assertIn("platform_of={path: plat for plat, path in platforms}", source) + + if __name__ == "__main__": unittest.main()