feat(update): self-update from a cloned repo wherever the app is installed
Self-update assumed a conventional install prefix (silently reinstalling into ~/.local when the binary lived elsewhere) and needed a release tarball to do anything. Pick the strategy from what the machine actually has -- a local checkout, git+cmake+compiler for a clone, the prebuilt archive, or the release sources -- and always write the fresh binary next to the running one, building in a temp directory so sudo is only needed for the final copy. Bundles the UI work that depends on it (tray, shortcuts, log filter, CSV exports, cached package details), the structured log categories, and the new test targets (update-manager, AUR, plugins) wired into CTest. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
1 parent
6d5b4274c4
commit
54bff16369
9 files changed
+1123
-200
No files matched your search
+329
-120
@@ -1,4 +1,5 @@
|
||||
#include "update-manager.h"
|
||||
#include "app-logging.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
@@ -9,6 +10,7 @@
|
||||
#include <QDir>
|
||||
#include <QCoreApplication>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QHash>
|
||||
|
||||
// Repository base URL used to query the Gitea API for releases.
|
||||
// The app is hosted at https://gitea.nocode-var.tech/FWS/FWS-PacManage.
|
||||
@@ -93,38 +95,127 @@ QString UpdateManager::tarballUrl() const {
|
||||
return m_tarballUrl;
|
||||
}
|
||||
|
||||
QString UpdateManager::prebuiltUrl() const {
|
||||
return m_prebuiltUrl;
|
||||
}
|
||||
|
||||
bool UpdateManager::hasPrebuiltUpdate() const {
|
||||
return !m_prebuiltUrl.isEmpty();
|
||||
}
|
||||
|
||||
QString UpdateManager::releasePageUrl() const {
|
||||
return m_releasePageUrl;
|
||||
}
|
||||
|
||||
QString UpdateManager::installPrefix() const {
|
||||
// Infer the install prefix from the running binary location:
|
||||
// <prefix>/bin/PacManager -> <prefix>. Falls back to ~/.local.
|
||||
QDir dir(QCoreApplication::applicationDirPath());
|
||||
if (dir.dirName() == QLatin1String("bin")) {
|
||||
dir.cdUp();
|
||||
return dir.absolutePath();
|
||||
// Cached `command -v` lookup. The update dialog queries several tools on
|
||||
// every check; caching keeps that from spawning a shell per query.
|
||||
bool UpdateManager::toolAvailable(const char* tool) {
|
||||
static QHash<QString, bool> cache;
|
||||
const QString key = QString::fromLatin1(tool);
|
||||
const auto it = cache.constFind(key);
|
||||
if (it != cache.constEnd()) return it.value();
|
||||
const bool ok = QProcess::execute(
|
||||
"/bin/sh", {"-c", QString("command -v %1 >/dev/null 2>&1").arg(key)}) == 0;
|
||||
cache.insert(key, ok);
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool UpdateManager::compilerAvailable() {
|
||||
return toolAvailable("g++") || toolAvailable("c++") || toolAvailable("clang++");
|
||||
}
|
||||
|
||||
// Directory holding the running executable. Every install path writes the new
|
||||
// binary here, so the update follows the user's copy instead of assuming a
|
||||
// conventional prefix.
|
||||
QString UpdateManager::binDir() const {
|
||||
return QCoreApplication::applicationDirPath();
|
||||
}
|
||||
|
||||
// ~/.local/share/PacManager/src (honouring XDG_DATA_HOME): the same user data
|
||||
// directory as the drop-in plugins, so it is writable and independent of where
|
||||
// the binary itself lives.
|
||||
QString UpdateManager::sourceClonePath() const {
|
||||
QString base = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
|
||||
if (base.isEmpty()) base = QDir::homePath() + "/.local/share";
|
||||
return base + "/PacManager/src";
|
||||
}
|
||||
|
||||
// True when the checkout around the binary is usable and points at the FWS
|
||||
// repo (otherwise we would build someone else's code on the user's machine).
|
||||
static bool checkoutIsUsable(const QString& repoPath) {
|
||||
if (repoPath.isEmpty()) return false;
|
||||
QDir repo(repoPath);
|
||||
if (!repo.exists(QLatin1String(".git"))) return false;
|
||||
QFile config(repoPath + "/.git/config");
|
||||
if (!config.open(QIODevice::ReadOnly | QIODevice::Text)) return false;
|
||||
return QString::fromUtf8(config.readAll())
|
||||
.contains(QLatin1String("FWS/FWS-PacManage"));
|
||||
}
|
||||
|
||||
UpdateManager::UpdateMethod UpdateManager::updateMethod() const {
|
||||
UpdateCapabilities capabilities;
|
||||
capabilities.checkoutUsable = checkoutIsUsable(m_repoPath);
|
||||
capabilities.hasGit = toolAvailable("git");
|
||||
capabilities.hasCmake = toolAvailable("cmake");
|
||||
capabilities.hasCompiler = compilerAvailable();
|
||||
capabilities.hasPrebuilt = !m_prebuiltUrl.isEmpty();
|
||||
capabilities.hasTarball = !m_tarballUrl.isEmpty();
|
||||
return chooseUpdateMethod(capabilities);
|
||||
}
|
||||
|
||||
// Strategy, in order of preference:
|
||||
// 1. Checkout: a source checkout is the developer's tree, pull + rebuild it;
|
||||
// 2. Clone: rebuild from the real sources (git + cmake + compiler present),
|
||||
// so an installed app follows the repo whatever its location;
|
||||
// 3. Prebuilt: no toolchain, unpack the release's binary archive;
|
||||
// 4. Tarball: no git but a compiler, build the release sources.
|
||||
// Anything else cannot update locally and falls back to the releases page.
|
||||
UpdateManager::UpdateMethod UpdateManager::chooseUpdateMethod(
|
||||
const UpdateCapabilities& capabilities) {
|
||||
if (capabilities.checkoutUsable) return UpdateMethod::Checkout;
|
||||
if (capabilities.hasGit && capabilities.hasCmake && capabilities.hasCompiler) {
|
||||
return UpdateMethod::Clone;
|
||||
}
|
||||
return QDir::homePath() + "/.local";
|
||||
if (capabilities.hasPrebuilt) return UpdateMethod::Prebuilt;
|
||||
if (capabilities.hasTarball && capabilities.hasCmake
|
||||
&& capabilities.hasCompiler) {
|
||||
return UpdateMethod::Tarball;
|
||||
}
|
||||
return UpdateMethod::None;
|
||||
}
|
||||
|
||||
QString UpdateManager::methodDescription(UpdateMethod method, const QString& targetDir) {
|
||||
switch (method) {
|
||||
case UpdateMethod::Checkout:
|
||||
return QStringLiteral(
|
||||
"La mise à jour va récupérer le code (git pull), recompiler et "
|
||||
"réinstaller.\nRedémarrez PacManager ensuite pour utiliser la "
|
||||
"nouvelle version.");
|
||||
case UpdateMethod::Clone:
|
||||
return QStringLiteral(
|
||||
"La mise à jour va cloner (puis mettre à jour) le dépôt source "
|
||||
"et recompiler l'application dans %1.\nRedémarrez PacManager "
|
||||
"ensuite pour utiliser la nouvelle version.").arg(targetDir);
|
||||
case UpdateMethod::Prebuilt:
|
||||
return QStringLiteral(
|
||||
"La mise à jour va télécharger la version précompilée et "
|
||||
"l'installer dans %1 (sans compilation).\nRedémarrez PacManager "
|
||||
"ensuite pour utiliser la nouvelle version.").arg(targetDir);
|
||||
case UpdateMethod::Tarball:
|
||||
return QStringLiteral(
|
||||
"La mise à jour va télécharger les sources, les compiler et "
|
||||
"installer l'application dans %1.\nRedémarrez PacManager "
|
||||
"ensuite pour utiliser la nouvelle version.").arg(targetDir);
|
||||
case UpdateMethod::None:
|
||||
return QStringLiteral(
|
||||
"Le dépôt source n'est pas disponible sur ce système. "
|
||||
"Téléchargez la nouvelle version depuis la page des releases.");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
bool UpdateManager::canSelfUpdate() const {
|
||||
if (!m_repoPath.isEmpty()) {
|
||||
QDir repo(m_repoPath);
|
||||
if (!repo.exists(QLatin1String(".git"))) return !m_tarballUrl.isEmpty();
|
||||
|
||||
// The remote must point to the same FWS repo, otherwise we would build
|
||||
// someone else's code on the user's machine.
|
||||
QFile config(m_repoPath + "/.git/config");
|
||||
if (config.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
const QString content = QString::fromUtf8(config.readAll());
|
||||
if (content.contains(QLatin1String("FWS/FWS-PacManage"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Installed mode: a tarball download + local build needs no git checkout.
|
||||
return !m_tarballUrl.isEmpty();
|
||||
return updateMethod() != UpdateMethod::None;
|
||||
}
|
||||
|
||||
void UpdateManager::loadState() {
|
||||
@@ -173,6 +264,7 @@ void UpdateManager::checkForUpdates() {
|
||||
reply->deleteLater();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(pacmgrUpdate) << "release check failed:" << reply->errorString();
|
||||
emit checkFinished(false, QString(),
|
||||
QStringLiteral("Impossible de contacter le serveur : %1")
|
||||
.arg(reply->errorString()));
|
||||
@@ -204,18 +296,33 @@ void UpdateManager::checkForUpdates() {
|
||||
tag = tag.mid(1);
|
||||
}
|
||||
|
||||
// Prefer an attached source archive; fall back to the auto-generated
|
||||
// tarball Gitea always provides (releases here ship no assets).
|
||||
// Prefer the prebuilt binary archive (no compiler needed on the user
|
||||
// machine); fall back to an attached source archive, then to the
|
||||
// auto-generated tarball Gitea always provides.
|
||||
QString tarball = obj.value("tarball_url").toString().trimmed();
|
||||
QString prebuilt;
|
||||
const QJsonArray assets = obj.value("assets").toArray();
|
||||
for (const QJsonValue& v : assets) {
|
||||
const QString dl = v.toObject().value("browser_download_url").toString().trimmed();
|
||||
if (dl.endsWith(QLatin1String(".tar.gz")) || dl.endsWith(QLatin1String(".zip"))) {
|
||||
tarball = dl;
|
||||
const QJsonObject a = v.toObject();
|
||||
const QString name = a.value("name").toString();
|
||||
const QString dl = a.value("browser_download_url").toString().trimmed();
|
||||
if (name.startsWith(QLatin1String("PacManager-"))
|
||||
&& dl.endsWith(QLatin1String(".tar.gz"))) {
|
||||
prebuilt = dl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (prebuilt.isEmpty()) {
|
||||
for (const QJsonValue& v : assets) {
|
||||
const QString dl = v.toObject().value("browser_download_url").toString().trimmed();
|
||||
if (dl.endsWith(QLatin1String(".tar.gz")) || dl.endsWith(QLatin1String(".zip"))) {
|
||||
tarball = dl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_tarballUrl = tarball;
|
||||
m_prebuiltUrl = prebuilt;
|
||||
m_releasePageUrl = obj.value("html_url").toString().trimmed();
|
||||
if (m_releasePageUrl.isEmpty()) {
|
||||
m_releasePageUrl = QStringLiteral("https://gitea.nocode-var.tech/FWS/FWS-PacManage/releases");
|
||||
@@ -225,15 +332,20 @@ void UpdateManager::checkForUpdates() {
|
||||
|
||||
bool hasUpdate = isNewerVersion(tag, currentVersion());
|
||||
m_lastKnownRemoteVersion = tag;
|
||||
m_latestVersion = tag;
|
||||
qCInfo(pacmgrUpdate) << "remote version" << tag << "local" << currentVersion()
|
||||
<< "hasUpdate" << hasUpdate;
|
||||
emit checkFinished(hasUpdate, tag, QString());
|
||||
});
|
||||
}
|
||||
|
||||
bool UpdateManager::isNewerVersion(const QString& remote, const QString& local) {
|
||||
// Simple dotted numeric comparison ("1.10.2" > "1.9.1"). Non-numeric
|
||||
// components are treated as 0 so pre-release tags stay comparable.
|
||||
auto parts = [](const QString& v) {
|
||||
// components are treated as 0 so pre-release tags stay comparable, and a
|
||||
// leading "v"/"V" (git tag style) is stripped so callers do not have to
|
||||
// normalise before comparing.
|
||||
auto parts = [](const QString& value) {
|
||||
QString v = value.trimmed();
|
||||
if (v.startsWith('v') || v.startsWith('V')) v = v.mid(1);
|
||||
QVector<int> out;
|
||||
for (const QString& chunk : v.split('.')) {
|
||||
bool ok = false;
|
||||
@@ -254,103 +366,200 @@ bool UpdateManager::isNewerVersion(const QString& remote, const QString& local)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Rebuilds + reinstalls the app in the background.
|
||||
// - Source checkout present: git pull + rebuild in place.
|
||||
// - Installed without the repo: download the release tarball to /tmp,
|
||||
// build it there and `cmake --install` to the prefix the running binary
|
||||
// came from (sudo when that prefix is not user-writable).
|
||||
// The new binary takes effect at the next launch; the running process is
|
||||
// untouched. Exits non-zero on failure so the caller can report it.
|
||||
// Rebuilds + reinstalls the app in the background, using the strategy picked
|
||||
// by updateMethod(). The new binary takes effect at the next launch; the
|
||||
// running process is untouched. Exits non-zero on failure so the caller can
|
||||
// report it.
|
||||
void UpdateManager::performSelfUpdate(const QString& sudoPassword) {
|
||||
if (!m_repoPath.isEmpty()) {
|
||||
QString script = QStringLiteral(
|
||||
"set -e\n"
|
||||
"echo 'Mise à jour de PacManager...'\n"
|
||||
"git pull --ff-only origin main 2>&1 || git pull --ff-only 2>&1\n"
|
||||
"if [ -d build ]; then\n"
|
||||
" cmake --build build -j$(nproc) 2>&1\n"
|
||||
"else\n"
|
||||
" cmake -B build -DCMAKE_BUILD_TYPE=Release . 2>&1\n"
|
||||
" cmake --build build -j$(nproc) 2>&1\n"
|
||||
"fi\n"
|
||||
"cmake --install build 2>&1\n"
|
||||
"echo 'Mise à jour terminée. Redémarrez PacManager pour utiliser la nouvelle version.'");
|
||||
|
||||
runShell(script, m_repoPath);
|
||||
return;
|
||||
const UpdateMethod method = updateMethod();
|
||||
qCInfo(pacmgrUpdate) << "starting self-update, method"
|
||||
<< static_cast<int>(method) << "into" << binDir();
|
||||
switch (method) {
|
||||
case UpdateMethod::Checkout:
|
||||
performCheckoutUpdate();
|
||||
return;
|
||||
case UpdateMethod::Clone:
|
||||
performCloneUpdate(sudoPassword);
|
||||
return;
|
||||
case UpdateMethod::Prebuilt:
|
||||
performPrebuiltUpdate(sudoPassword);
|
||||
return;
|
||||
case UpdateMethod::Tarball:
|
||||
performTarballUpdate(sudoPassword);
|
||||
return;
|
||||
case UpdateMethod::None:
|
||||
emit selfUpdateFinished(
|
||||
false, QStringLiteral("Aucune méthode de mise à jour disponible."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_tarballUrl.isEmpty() || m_latestVersion.isEmpty()) {
|
||||
emit selfUpdateFinished(false, QStringLiteral("Dépôt source introuvable."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Quote the password for the shell pipe; never log it.
|
||||
QString quoted;
|
||||
{
|
||||
QString p = sudoPassword;
|
||||
p.replace(QLatin1String("'"), QLatin1String("'\\''"));
|
||||
quoted = QStringLiteral("'") + p + QStringLiteral("'");
|
||||
}
|
||||
const bool useSudoPipe = !sudoPassword.isEmpty();
|
||||
|
||||
// Installed mode: fetch the release tarball, compile in /tmp, reinstall
|
||||
// to the same prefix. `cmake --install` needs sudo only for system
|
||||
// prefixes; ~/.local stays a plain user install.
|
||||
// Checkout path (dev): pull the sources and rebuild in place, then install
|
||||
// with whatever prefix the build directory was configured with.
|
||||
void UpdateManager::performCheckoutUpdate() {
|
||||
QString script = QStringLiteral(
|
||||
"set -e\n"
|
||||
"echo 'Mise à jour de PacManager...'\n"
|
||||
"command -v cmake >/dev/null || { echo 'cmake est requis pour la mise à jour (pacman -S cmake)'; exit 1; }\n"
|
||||
"echo 'Mise a jour de PacManager...'\n"
|
||||
"export GIT_TERMINAL_PROMPT=0\n"
|
||||
"git pull --ff-only origin main 2>&1 || git pull --ff-only 2>&1\n"
|
||||
"if [ -d build ]; then\n"
|
||||
" cmake --build build -j$(nproc) 2>&1\n"
|
||||
"else\n"
|
||||
" cmake -B build -DCMAKE_BUILD_TYPE=Release . 2>&1\n"
|
||||
" cmake --build build -j$(nproc) 2>&1\n"
|
||||
"fi\n"
|
||||
"cmake --install build 2>&1\n"
|
||||
"echo 'Mise a jour terminee. Redemarrez PacManager pour utiliser la nouvelle version.'");
|
||||
runShell(script, m_repoPath);
|
||||
}
|
||||
|
||||
// Shared prologue for the installed (no checkout) paths: temp work directory
|
||||
// with a cleanup trap, plus the paths the install step needs, exported so the
|
||||
// sudo-wrapped `sh -c` copy can expand them.
|
||||
QString UpdateManager::installedScriptPrologue() const {
|
||||
return QStringLiteral(
|
||||
"set -e\n"
|
||||
"echo 'Mise a jour de PacManager...'\n"
|
||||
"WORK=$(mktemp -d /tmp/pacmanager-update-XXXXXX)\n"
|
||||
"trap 'rm -rf \"$WORK\"' EXIT\n"
|
||||
"TARBALL_URL=%1\n"
|
||||
"VERSION=%2\n"
|
||||
"PREFIX=%3\n"
|
||||
"ARCHIVE=\"$WORK/src.tar.gz\"\n"
|
||||
"if command -v curl >/dev/null; then curl -fsSL -o \"$ARCHIVE\" \"$TARBALL_URL\" 2>&1;\n"
|
||||
"elif command -v wget >/dev/null; then wget -O \"$ARCHIVE\" \"$TARBALL_URL\" 2>&1;\n"
|
||||
"else echo 'curl ou wget est requis pour télécharger la mise à jour'; exit 1; fi\n"
|
||||
"if ! tar xzf \"$ARCHIVE\" -C \"$WORK\" 2>/dev/null; then\n"
|
||||
" command -v unzip >/dev/null || { echo 'unzip est requis pour cette archive'; exit 1; }\n"
|
||||
" unzip -q \"$ARCHIVE\" -d \"$WORK\" 2>&1 || { echo 'Archive invalide'; exit 1; }\n"
|
||||
"BIN_DIR=%1\n"
|
||||
"STAGE=\"$WORK/stage\"\n"
|
||||
"export WORK BIN_DIR STAGE\n"
|
||||
"export GIT_TERMINAL_PROMPT=0\n")
|
||||
.arg(quotedBinDir());
|
||||
}
|
||||
|
||||
// Copies a staged install tree ($STAGE/bin, plugins under bin/plugins or
|
||||
// plugins/ depending on the source) into the running binary's directory.
|
||||
static QString stagedCopyAction() {
|
||||
return QStringLiteral(
|
||||
"set -e\n"
|
||||
"mkdir -p \"$BIN_DIR\"\n"
|
||||
"cp \"$STAGE/bin/PacManager\" \"$BIN_DIR/PacManager\"\n"
|
||||
"if [ -f \"$STAGE/bin/version\" ]; then cp \"$STAGE/bin/version\" \"$BIN_DIR/version\"; fi\n"
|
||||
"if [ -d \"$STAGE/bin/plugins\" ]; then SRC_PLUGINS=\"$STAGE/bin/plugins\";\n"
|
||||
"elif [ -d \"$STAGE/plugins\" ]; then SRC_PLUGINS=\"$STAGE/plugins\";\n"
|
||||
"else SRC_PLUGINS=\"\"; fi\n"
|
||||
"if [ -n \"$SRC_PLUGINS\" ]; then\n"
|
||||
" mkdir -p \"$BIN_DIR/plugins\"\n"
|
||||
" cp \"$SRC_PLUGINS/\"*.so \"$BIN_DIR/plugins/\" 2>/dev/null || true\n"
|
||||
"fi\n");
|
||||
}
|
||||
|
||||
// Install command: the action runs in a child `sh` (so it may be a compound
|
||||
// command and expands the exported paths), through sudo when a password was
|
||||
// provided or the target directory is not writable.
|
||||
QString UpdateManager::installCommand(const QString& quotedPassword,
|
||||
const QString& action) const {
|
||||
const QString quotedAction = quoteShell(action);
|
||||
if (!quotedPassword.isEmpty()) {
|
||||
// NOTE: single %s — QString::arg() only substitutes %1..%99.
|
||||
return QStringLiteral("printf '%s\\n' %1 | sudo -S sh -c %2 2>&1\n")
|
||||
.arg(quotedPassword, quotedAction);
|
||||
}
|
||||
if (QFileInfo(binDir()).isWritable()) {
|
||||
return QStringLiteral("sh -c %1 2>&1\n").arg(quotedAction);
|
||||
}
|
||||
return QStringLiteral("sudo sh -c %1 2>&1\n").arg(quotedAction);
|
||||
}
|
||||
|
||||
QString UpdateManager::quotedBinDir() const {
|
||||
return quoteShell(binDir());
|
||||
}
|
||||
|
||||
QString UpdateManager::quoteShell(const QString& s) {
|
||||
QString q = s;
|
||||
q.replace(QLatin1String("'"), QLatin1String("'\\''"));
|
||||
return QStringLiteral("'") + q + QStringLiteral("'");
|
||||
}
|
||||
|
||||
QString UpdateManager::quotedPassword(const QString& sudoPassword) {
|
||||
if (sudoPassword.isEmpty()) return {};
|
||||
QString p = sudoPassword;
|
||||
p.replace(QLatin1String("'"), QLatin1String("'\\''"));
|
||||
return QStringLiteral("'") + p + QStringLiteral("'");
|
||||
}
|
||||
|
||||
// Clone path: used for an installed app with no checkout around the binary.
|
||||
// The first update clones the repo into ~/.local/share/PacManager/src, later
|
||||
// ones fast-forward it, then the app is rebuilt and installed where the
|
||||
// running binary lives.
|
||||
void UpdateManager::performCloneUpdate(const QString& sudoPassword) {
|
||||
QString script = installedScriptPrologue();
|
||||
script += QStringLiteral(
|
||||
"SRC=%1\n"
|
||||
"export SRC\n"
|
||||
"command -v git >/dev/null 2>&1 || { echo 'git est requis pour la mise a jour'; exit 1; }\n"
|
||||
"command -v cmake >/dev/null 2>&1 || { echo 'cmake est requis pour la mise a jour'; exit 1; }\n"
|
||||
"if [ -d \"$SRC/.git\" ]; then\n"
|
||||
" echo 'Recuperation des sources...'\n"
|
||||
" git -C \"$SRC\" fetch --depth 1 origin main 2>&1\n"
|
||||
" git -C \"$SRC\" reset --hard FETCH_HEAD 2>&1\n"
|
||||
"else\n"
|
||||
" echo 'Clonage du depot...'\n"
|
||||
" rm -rf \"$SRC\"\n"
|
||||
" mkdir -p \"$(dirname \"$SRC\")\"\n"
|
||||
" git clone --depth 1 --branch main %2 \"$SRC\" 2>&1\n"
|
||||
"fi\n"
|
||||
// NOTE: single %h here — QString::arg() leaves %h untouched (only
|
||||
// %1..%99 are placeholders), so find receives the correct -printf.
|
||||
"SRC=$(find \"$WORK\" -maxdepth 2 -name CMakeLists.txt -printf '%h\\n' | head -n 1)\n"
|
||||
"[ -n \"$SRC\" ] || { echo 'Archive invalide: CMakeLists.txt introuvable'; exit 1; }\n"
|
||||
"cmake -S \"$SRC\" -B \"$SRC/build\" -DCMAKE_BUILD_TYPE=Release 2>&1\n"
|
||||
"cmake --build \"$SRC/build\" -j$(nproc) 2>&1\n"
|
||||
"cmake --install \"$SRC/build\" --prefix \"$STAGE\" 2>&1\n")
|
||||
.arg(quoteShell(sourceClonePath()), quoteShell(QString::fromLatin1(kRepoUrl)));
|
||||
script += installCommand(quotedPassword(sudoPassword), stagedCopyAction());
|
||||
script += QStringLiteral(
|
||||
"echo 'Mise a jour terminee. Redemarrez PacManager pour utiliser la nouvelle version.'");
|
||||
runShell(script, QDir::homePath());
|
||||
}
|
||||
|
||||
// Prebuilt path: download the release archive (bin/ + plugins/) and unpack it
|
||||
// straight into the running binary's directory. No compiler needed.
|
||||
void UpdateManager::performPrebuiltUpdate(const QString& sudoPassword) {
|
||||
QString script = installedScriptPrologue();
|
||||
script += QStringLiteral(
|
||||
"URL=%1\n"
|
||||
"ARCHIVE=\"$WORK/update.tar.gz\"\n"
|
||||
"if command -v curl >/dev/null 2>&1; then curl -fsSL -o \"$ARCHIVE\" \"$URL\" 2>&1\n"
|
||||
"elif command -v wget >/dev/null 2>&1; then wget -O \"$ARCHIVE\" \"$URL\" 2>&1\n"
|
||||
"else echo 'curl ou wget est requis'; exit 1; fi\n"
|
||||
"mkdir -p \"$WORK/unpacked\"\n"
|
||||
"tar xzf \"$ARCHIVE\" -C \"$WORK/unpacked\" 2>&1\n"
|
||||
"STAGE=\"$WORK/unpacked\"\n"
|
||||
"export STAGE\n"
|
||||
"[ -x \"$STAGE/bin/PacManager\" ] || { echo 'Archive invalide'; exit 1; }\n")
|
||||
.arg(quoteShell(m_prebuiltUrl));
|
||||
script += installCommand(quotedPassword(sudoPassword), stagedCopyAction());
|
||||
script += QStringLiteral(
|
||||
"echo 'Mise a jour terminee. Redemarrez PacManager pour utiliser la nouvelle version.'");
|
||||
runShell(script, QDir::homePath());
|
||||
}
|
||||
|
||||
// Source fallback: fetch the release tarball, build it in /tmp and install the
|
||||
// result where the running binary lives. Used only when git is unavailable.
|
||||
void UpdateManager::performTarballUpdate(const QString& sudoPassword) {
|
||||
QString script = installedScriptPrologue();
|
||||
script += QStringLiteral(
|
||||
"command -v cmake >/dev/null 2>&1 || { echo 'cmake est requis pour la mise a jour'; exit 1; }\n"
|
||||
"URL=%1\n"
|
||||
"ARCHIVE=\"$WORK/src.tar.gz\"\n"
|
||||
"if command -v curl >/dev/null 2>&1; then curl -fsSL -o \"$ARCHIVE\" \"$URL\" 2>&1\n"
|
||||
"elif command -v wget >/dev/null 2>&1; then wget -O \"$ARCHIVE\" \"$URL\" 2>&1\n"
|
||||
"else echo 'curl ou wget est requis'; exit 1; fi\n"
|
||||
"mkdir -p \"$WORK/src\"\n"
|
||||
"if tar xzf \"$ARCHIVE\" -C \"$WORK/src\" 2>/dev/null; then :\n"
|
||||
"else\n"
|
||||
" command -v unzip >/dev/null 2>&1 || { echo 'unzip est requis pour cette archive'; exit 1; }\n"
|
||||
" unzip -q \"$ARCHIVE\" -d \"$WORK/src\" 2>&1 || { echo 'Archive invalide'; exit 1; }\n"
|
||||
"fi\n"
|
||||
// NOTE: single %h — QString::arg() leaves %h untouched (only %1..%99
|
||||
// are placeholders), so find gets the correct -printf.
|
||||
"SRC=$(find \"$WORK/src\" -maxdepth 2 -name CMakeLists.txt -printf '%h\\n' | head -n 1)\n"
|
||||
"[ -n \"$SRC\" ] || { echo 'Archive invalide'; exit 1; }\n"
|
||||
"cmake -S \"$SRC\" -B \"$WORK/build\" -DCMAKE_BUILD_TYPE=Release 2>&1\n"
|
||||
"cmake --build \"$WORK/build\" -j$(nproc) 2>&1\n"
|
||||
"if [ -w \"$PREFIX\" ] || [ -w \"$PREFIX/bin\" ]; then\n"
|
||||
" cmake --install \"$WORK/build\" --prefix \"$PREFIX\" 2>&1\n"
|
||||
"else\n"
|
||||
"%4"
|
||||
"fi\n"
|
||||
"echo 'Mise à jour terminée. Redémarrez PacManager pour utiliser la nouvelle version.'");
|
||||
|
||||
// Install step: pipe the sudo password when provided, otherwise let sudo
|
||||
// prompt on its own terminal (graphical sudo may pop up its dialog).
|
||||
QString installStep;
|
||||
if (useSudoPipe) {
|
||||
// NOTE: single %s — QString::arg() only substitutes %1..%99, so
|
||||
// printf keeps its format specifier intact.
|
||||
installStep = QStringLiteral(
|
||||
" printf '%s\\n' %1 | sudo -S cmake --install \"$WORK/build\" --prefix \"$PREFIX\" 2>&1\n")
|
||||
.arg(quoted);
|
||||
} else {
|
||||
installStep = QStringLiteral(
|
||||
" sudo cmake --install \"$WORK/build\" --prefix \"$PREFIX\" 2>&1\n");
|
||||
}
|
||||
|
||||
auto quoteShell = [](const QString& s) {
|
||||
QString q = s;
|
||||
q.replace(QLatin1String("'"), QLatin1String("'\\''"));
|
||||
return QStringLiteral("'") + q + QStringLiteral("'");
|
||||
};
|
||||
|
||||
script = script.arg(quoteShell(m_tarballUrl))
|
||||
.arg(quoteShell(m_latestVersion))
|
||||
.arg(quoteShell(installPrefix()))
|
||||
.arg(installStep);
|
||||
|
||||
"cmake --install \"$WORK/build\" --prefix \"$STAGE\" 2>&1\n")
|
||||
.arg(quoteShell(m_tarballUrl));
|
||||
script += installCommand(quotedPassword(sudoPassword), stagedCopyAction());
|
||||
script += QStringLiteral(
|
||||
"echo 'Mise a jour terminee. Redemarrez PacManager pour utiliser la nouvelle version.'");
|
||||
runShell(script, QDir::homePath());
|
||||
}
|
||||
Reference in new issue
Block a user