From 8cf2ffe2ad7161fbfc729a114fcd0418dd4891ce Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Sun, 25 Oct 2026 18:05:41 -0400 Subject: [PATCH] fix: say why Flatpak setup failed instead of blaming the mirrors (#1580) --- .../usr/local/bin/droiddeck-flatpak-setup | 12 +++-- tools/tests/test_flatpak_setup.py | 45 +++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 tools/tests/test_flatpak_setup.py diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-flatpak-setup b/tools/linuxfs/overlay/usr/local/bin/droiddeck-flatpak-setup index 24806fa2e..bd25b6089 100644 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-flatpak-setup +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-flatpak-setup @@ -3,6 +3,7 @@ set -u export LANG=C.UTF-8 step() { echo "== STEP $*"; } fail() { echo "== FAIL $*"; exit 1; } +[ "$(id -u)" = 0 ] || fail "needs root: install Flatpak from the launcher's Store, which runs this as root" PACKAGES="flatpak ostree appstream libxmlb libmalcontent libfyaml accountsservice composefs xdg-dbus-proxy" while read -r pkg probe; do @@ -48,10 +49,13 @@ if [ ! -f /etc/pacman.d/gnupg/pubring.gpg ] && [ ! -f /etc/pacman.d/gnupg/pubrin fi step "Reading the package lists" -pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy >/dev/null 2>&1 \ - || pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy 2>&1 | tail -3 \ - || fail "could not reach the Arch Linux ARM mirrors" -[ -f "$WORK/db/sync/extra.db" ] || fail "could not reach the Arch Linux ARM mirrors" +sync_log=$(pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy 2>&1) \ + || sync_log=$(pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy 2>&1) +if [ ! -f "$WORK/db/sync/extra.db" ]; then + printf '%s\n' "$sync_log" | tail -3 + reason=$(printf '%s\n' "$sync_log" | grep -m1 -i '^error' | cut -c1-160) + fail "could not reach the Arch Linux ARM mirrors${reason:+ ($reason)}" +fi step "Downloading Flatpak" out=$(pacman --config "$CONF" --dbpath "$WORK/db" --cachedir "$WORK/pkg" --noconfirm -Sw -dd $PACKAGES 2>&1) diff --git a/tools/tests/test_flatpak_setup.py b/tools/tests/test_flatpak_setup.py new file mode 100644 index 000000000..b5714b9a4 --- /dev/null +++ b/tools/tests/test_flatpak_setup.py @@ -0,0 +1,45 @@ +import os +from pathlib import Path +import subprocess +import tempfile +import unittest + + +SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-flatpak-setup" + + +class FlatpakSetupTest(unittest.TestCase): + def run_setup(self, uid, pacman): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + bin_dir = root / "bin" + bin_dir.mkdir() + stubs = {"id": "echo %d" % uid, "curl": "exit 7", "pacman": pacman, "pacman-key": "exit 0"} + for name, body in stubs.items(): + (bin_dir / name).write_text("#!/bin/sh\n%s\n" % body) + (bin_dir / name).chmod(0o755) + script = root / "setup" + script.write_text(SCRIPT.read_text().replace("WORK=/var/cache/droiddeck-flatpak", "WORK=%s/work" % root) + .replace("/etc/pacman.d/gnupg/pubring.gpg", str(root / "pubring.gpg")) + .replace(" /etc/pacman.conf >", " %s >" % (root / "pacman.conf"))) + (root / "pacman.conf").write_text("[options]\n[core]\nInclude = /etc/pacman.d/mirrorlist\n") + (root / "pubring.gpg").write_text("") + env = dict(os.environ, PATH="%s:%s" % (bin_dir, os.environ["PATH"])) + result = subprocess.run(["bash", str(script)], env=env, capture_output=True, text=True, timeout=30) + return result.returncode, result.stdout + + def test_a_manual_run_without_root_says_so(self): + code, out = self.run_setup(1000, "exit 0") + self.assertEqual(code, 1) + self.assertIn("== FAIL needs root", out) + self.assertNotIn("Reading the package lists", out) + + def test_an_unreachable_mirror_reports_pacmans_error(self): + code, out = self.run_setup(0, "echo \"error: failed retrieving file 'core.db' : Could not resolve host\" >&2; exit 1") + self.assertEqual(code, 1) + self.assertIn("== FAIL could not reach the Arch Linux ARM mirrors (error: failed retrieving file 'core.db' : " + "Could not resolve host)", out) + + +if __name__ == "__main__": + unittest.main()