mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-11 19:11:08 +00:00
fix: say why Flatpak setup failed instead of blaming the mirrors (#1580)
This commit is contained in:
1 parent
4e00b40333
commit
8cf2ffe2ad
2 files changed
+53
-4
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
Reference in new issue
Block a user