feat(pkgcheck): vérification des mises à jour au démarrage sans mdp + notif
Le mode headless --check-updates (QT Core uniquement) synchro checkupdates sans root, classe les paquets critiques (noyau, glibc, systemd, graphics), envoie une notif urgente via notify-send quand c'est nécessaire, et installe soi-même son service systemd --user (paramètre actif par défaut) pour lancer la vérification à chaque ouverture de session. Ajout de tests d'unité et de doc. Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
9 files changed
+819
-2
No files matched your search
@@ -168,6 +168,18 @@ public:
|
||||
// when the update cannot run (no method available).
|
||||
bool applySelfUpdate(const QString& sudoPassword, QString* error);
|
||||
|
||||
// ---- Startup update check ----
|
||||
// Whether the app installs its login check: a systemd user unit that runs
|
||||
// `PacManager --check-updates` and pops a notification when updates are
|
||||
// pending — no window, no sudo password. On by default, since the point is
|
||||
// to warn the user without them opening the app.
|
||||
bool checkUpdatesAtStartup() const;
|
||||
void setCheckUpdatesAtStartup(bool enabled);
|
||||
// Refreshes the installed unit when the setting is on, in case the binary
|
||||
// moved since it was written. Idempotent; called once at window startup so
|
||||
// an update of the app keeps the login check pointing at the real file.
|
||||
void ensureStartupAutostart();
|
||||
|
||||
// ---- pacman's database lock ----
|
||||
bool databaseLocked() const;
|
||||
// What currently holds the lock, so the view can name the process it offers
|
||||
|
||||
@@ -211,4 +211,5 @@ private:
|
||||
// Menu
|
||||
QAction* m_credLaunchAction = nullptr;
|
||||
QAction* m_credEachTimeAction = nullptr;
|
||||
QAction* m_startupCheckAction = nullptr;
|
||||
};
|
||||
@@ -0,0 +1,118 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
// The headless pass that answers "does this machine have pending updates?" and,
|
||||
// when it does, raises a desktop notification.
|
||||
//
|
||||
// It exists because the graphical window is not running when the machine
|
||||
// starts: the app installs a systemd user unit (see the autostart helpers here)
|
||||
// that runs `PacManager --check-updates` at login, and that call lands here.
|
||||
//
|
||||
// Two guarantees drive the implementation:
|
||||
// - no password: the check goes through `checkupdates` (pacman-contrib), which
|
||||
// syncs into a throwaway database and therefore needs no root, instead of a
|
||||
// `pacman -Sy` the login unit could never authenticate;
|
||||
// - no display: everything here is Qt Core only, so the unit runs with no
|
||||
// DISPLAY, no Wayland socket and no widget.
|
||||
//
|
||||
// The pure parts (parsing, classification, notification text, unit contents)
|
||||
// are static so they are unit-tested without a package manager, a network or a
|
||||
// session bus.
|
||||
class StartupCheck : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
// Outcome of one check, so the caller (and the tests) can inspect what
|
||||
// happened without parsing console output.
|
||||
struct Result {
|
||||
int updateCount = 0;
|
||||
bool anyCritical = false; // kernel, glibc, init, graphics stack...
|
||||
bool rebootRequired = false; // a kernel or its firmware is pending
|
||||
QStringList packages;
|
||||
// Non-empty when the check failed, or when it could only run in a
|
||||
// degraded way (the pacman -Qu fallback, which reads a database only
|
||||
// root can refresh). Never a reason to skip the notification.
|
||||
QString error;
|
||||
};
|
||||
|
||||
explicit StartupCheck(QObject* parent = nullptr);
|
||||
|
||||
// Runs the whole headless pass (check, then notify when something is
|
||||
// pending) and returns the exit code for main(). Always 0: a background
|
||||
// check that fails must not fill the user's journal with failed units.
|
||||
int run();
|
||||
|
||||
// ---- Pure helpers (unit-tested) ----
|
||||
// Parses the checked tool's output. `checkupdates` prints
|
||||
// "name oldver -> newver" and `pacman -Qu` prints "name newver"; only the
|
||||
// package name is needed and it is the first whitespace-separated token of
|
||||
// every line, so one parser accepts both. Duplicates are dropped.
|
||||
static QStringList parseUpdates(const QString& output);
|
||||
|
||||
// A package whose update deserves an urgent notification rather than the
|
||||
// ordinary one: the kernel and its firmware, the C library and init, the
|
||||
// graphics stack, pacman itself — the updates that either need a reboot or
|
||||
// can break the session when they fall behind. Prefix-based on purpose: a
|
||||
// package nobody thought about simply gets the normal notification.
|
||||
static bool isCritical(const QString& package);
|
||||
|
||||
// A package whose update only takes effect after a reboot: the kernel and
|
||||
// the out-of-tree driver built against the running one.
|
||||
static bool isRebootRequired(const QString& package);
|
||||
|
||||
// The critical subset of a list, so the notification can name what matters.
|
||||
static QStringList criticalPackages(const QStringList& packages);
|
||||
|
||||
// Notification title and body for a set of pending updates.
|
||||
static QString notificationTitle(const Result& result);
|
||||
static QString notificationBody(const Result& result);
|
||||
|
||||
// ---- Check and notify (touch the machine) ----
|
||||
// Pending updates, using `checkupdates` when available and falling back to
|
||||
// the already-synced `pacman -Qu` otherwise. Never needs root; the fallback
|
||||
// reads a database only root can refresh, so it may miss updates — which is
|
||||
// what `error` records rather than hiding.
|
||||
static Result check();
|
||||
|
||||
// Sends the notification through notify-send, waiting briefly for the
|
||||
// notification daemon (the login unit can start before mako). Returns false
|
||||
// when nothing could be sent.
|
||||
static bool notify(const Result& result);
|
||||
|
||||
// ---- Autostart: a systemd user unit the app installs itself ----
|
||||
// The unit lives under `configDir` (XDG_CONFIG_HOME, i.e. ~/.config) and is
|
||||
// enabled by a symlink in default.target.wants, which is the per-user
|
||||
// equivalent of `systemctl --user enable` without shelling out to it.
|
||||
// Passing the directory lets the unit test drive install/remove inside a
|
||||
// temporary tree instead of the user's own ~/.config.
|
||||
static QString autostartUnitPath(const QString& configDir);
|
||||
static QString autostartWantsPath(const QString& configDir);
|
||||
|
||||
// Writes the unit and the enabling symlink. `program` is the binary to run
|
||||
// with --check-updates (the running executable, so it follows the install
|
||||
// wherever it is). Filesystem only: no systemd call, so tests stay hermetic.
|
||||
static bool installAutostart(const QString& configDir, const QString& program,
|
||||
QString* error = nullptr);
|
||||
static bool removeAutostart(const QString& configDir, QString* error = nullptr);
|
||||
static bool autostartEnabled(const QString& configDir);
|
||||
|
||||
// Asks the user's systemd manager to re-read its units, so a fresh install
|
||||
// takes effect without waiting for the next boot. Best effort; a system
|
||||
// without a running user manager (a test, a container) is not an error.
|
||||
static bool reloadUserManager();
|
||||
|
||||
private:
|
||||
// Runs a tool to completion, returning its stdout. stderr is kept out of it
|
||||
// on purpose: a pacman warning is not a package name, so folding the two
|
||||
// would feed the parser lines it must not see — `stderrText` receives them
|
||||
// for the error message instead. `exitCode` receives the status, or -1 when
|
||||
// the process could not be started or timed out.
|
||||
static QString runTool(const QString& program, const QStringList& args,
|
||||
int timeoutMs, int* exitCode, QString* stderrText = nullptr);
|
||||
|
||||
// Waits (bounded) for the session's notification daemon, then sends through
|
||||
// notify-send with the given urgency.
|
||||
static bool sendNotification(const QString& title, const QString& body, bool urgent);
|
||||
};
|
||||
Reference in new issue
Block a user