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
@@ -1,7 +1,10 @@
|
||||
#include "app-core.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QStandardPaths>
|
||||
#include <QTimer>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -14,6 +17,7 @@
|
||||
#include "app-logging.h"
|
||||
#include "log-manager.h"
|
||||
#include "plugin-shop.h"
|
||||
#include "startup-check.h"
|
||||
#include "workers.h"
|
||||
|
||||
namespace {
|
||||
@@ -1242,6 +1246,84 @@ bool AppCore::applySelfUpdate(const QString& sudoPassword, QString* error) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Startup update check
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
|
||||
// Directory the systemd user unit is written under. GenericConfigLocation is
|
||||
// ~/.config, honouring XDG_CONFIG_HOME, which is exactly where systemd looks.
|
||||
QString userConfigDir() {
|
||||
QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
|
||||
if (dir.isEmpty()) dir = QDir::homePath() + "/.config";
|
||||
return dir;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool AppCore::checkUpdatesAtStartup() const {
|
||||
return m_settings.value("updates/checkAtStartup", true).toBool();
|
||||
}
|
||||
|
||||
void AppCore::setCheckUpdatesAtStartup(bool enabled) {
|
||||
m_settings.setValue("updates/checkAtStartup", enabled);
|
||||
|
||||
const QString configDir = userConfigDir();
|
||||
QString error;
|
||||
|
||||
if (enabled) {
|
||||
// The unit runs the executable that is doing the installing, so the
|
||||
// check follows an app installed anywhere (~/.local/bin, /usr/bin...).
|
||||
const QString program =
|
||||
UpdateManager::restartProgram(QCoreApplication::applicationDirPath());
|
||||
if (program.isEmpty() ||
|
||||
!StartupCheck::installAutostart(configDir, program, &error)) {
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("config"),
|
||||
QStringLiteral("autostart des mises à jour impossible : %1")
|
||||
.arg(error.isEmpty() ? QStringLiteral("binaire introuvable") : error));
|
||||
emit statusMessage(QStringLiteral("Impossible d'installer la vérification au démarrage."));
|
||||
return;
|
||||
}
|
||||
StartupCheck::reloadUserManager();
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("config"),
|
||||
QStringLiteral("vérification des mises à jour au démarrage activée"));
|
||||
emit statusMessage(QStringLiteral(
|
||||
"Vérification des mises à jour au démarrage activée (notification à l'ouverture de session)."));
|
||||
} else {
|
||||
StartupCheck::removeAutostart(configDir, &error);
|
||||
StartupCheck::reloadUserManager();
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("config"),
|
||||
QStringLiteral("vérification des mises à jour au démarrage désactivée"));
|
||||
emit statusMessage(QStringLiteral("Vérification des mises à jour au démarrage désactivée."));
|
||||
}
|
||||
}
|
||||
|
||||
void AppCore::ensureStartupAutostart() {
|
||||
if (!checkUpdatesAtStartup()) return;
|
||||
|
||||
const QString program =
|
||||
UpdateManager::restartProgram(QCoreApplication::applicationDirPath());
|
||||
if (program.isEmpty()) return;
|
||||
|
||||
const QString configDir = userConfigDir();
|
||||
const bool wasEnabled = StartupCheck::autostartEnabled(configDir);
|
||||
|
||||
// Rewriting the unit on every launch keeps the executable path current (the
|
||||
// app may have moved), but only a fresh install needs systemd to be told.
|
||||
QString error;
|
||||
if (!StartupCheck::installAutostart(configDir, program, &error)) {
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("config"),
|
||||
QStringLiteral("autostart des mises à jour non installé : %1").arg(error));
|
||||
return;
|
||||
}
|
||||
if (!wasEnabled) StartupCheck::reloadUserManager();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// pacman's database lock
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user