On main: cline checkpoint session=1789059923966_jj6g7 run=7
This commit is contained in:
commit
f508a970f5
11 files changed
+700
-112
No files matched your search
+135
-65
@@ -93,10 +93,33 @@ 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;
|
||||
}
|
||||
|
||||
// Pre-flight: which tools would a source rebuild need that are missing?
|
||||
// A prebuilt archive only needs a downloader + tar (curl/wget handled in
|
||||
// the script); the source path additionally needs cmake + a C++ compiler.
|
||||
QStringList UpdateManager::missingSelfUpdateTools() const {
|
||||
if (!m_repoPath.isEmpty()) return {};
|
||||
if (!m_prebuiltUrl.isEmpty()) return {};
|
||||
QStringList missing;
|
||||
auto have = [](const char* tool) {
|
||||
return QProcess::execute("/bin/sh", {"-c", QString("command -v %1 >/dev/null 2>&1").arg(tool)}) == 0;
|
||||
};
|
||||
if (!have("cmake")) missing << "cmake";
|
||||
if (!have("g++") && !have("c++") && !have("clang++")) missing << "g++";
|
||||
return missing;
|
||||
}
|
||||
|
||||
QString UpdateManager::installPrefix() const {
|
||||
// Infer the install prefix from the running binary location:
|
||||
// <prefix>/bin/PacManager -> <prefix>. Falls back to ~/.local.
|
||||
@@ -111,7 +134,9 @@ QString UpdateManager::installPrefix() const {
|
||||
bool UpdateManager::canSelfUpdate() const {
|
||||
if (!m_repoPath.isEmpty()) {
|
||||
QDir repo(m_repoPath);
|
||||
if (!repo.exists(QLatin1String(".git"))) return !m_tarballUrl.isEmpty();
|
||||
if (!repo.exists(QLatin1String(".git"))) {
|
||||
return !m_prebuiltUrl.isEmpty() || !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.
|
||||
@@ -123,8 +148,8 @@ bool UpdateManager::canSelfUpdate() const {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Installed mode: a tarball download + local build needs no git checkout.
|
||||
return !m_tarballUrl.isEmpty();
|
||||
// Installed mode: a prebuilt archive or tarball needs no git checkout.
|
||||
return !m_prebuiltUrl.isEmpty() || !m_tarballUrl.isEmpty();
|
||||
}
|
||||
|
||||
void UpdateManager::loadState() {
|
||||
@@ -204,18 +229,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");
|
||||
@@ -256,16 +296,16 @@ bool UpdateManager::isNewerVersion(const QString& remote, const QString& local)
|
||||
|
||||
// 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).
|
||||
// - Prebuilt archive attached: download + unpack straight to the prefix.
|
||||
// - Otherwise: tarball download + compile in /tmp + reinstall to the prefix
|
||||
// the running binary came from (sudo for system prefixes).
|
||||
// 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"
|
||||
"echo 'Mise a 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"
|
||||
@@ -274,83 +314,113 @@ void UpdateManager::performSelfUpdate(const QString& sudoPassword) {
|
||||
" 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.'");
|
||||
"echo 'Mise a jour terminee.'");
|
||||
|
||||
runShell(script, m_repoPath);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_prebuiltUrl.isEmpty()) {
|
||||
performPrebuiltUpdate(sudoPassword);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_tarballUrl.isEmpty() || m_latestVersion.isEmpty()) {
|
||||
emit selfUpdateFinished(false, QStringLiteral("Dépôt source introuvable."));
|
||||
return;
|
||||
}
|
||||
performTarballUpdate(sudoPassword);
|
||||
}
|
||||
|
||||
// Quote the password for the shell pipe; never log it.
|
||||
QString quoted;
|
||||
{
|
||||
QString p = sudoPassword;
|
||||
p.replace(QLatin1String("'"), QLatin1String("'\\''"));
|
||||
quoted = QStringLiteral("'") + p + QStringLiteral("'");
|
||||
// Shared install command: plain when the prefix is writable, sudo otherwise
|
||||
// (password piped when provided, interactive prompt otherwise).
|
||||
QString UpdateManager::installCommand(const QString& quotedPassword,
|
||||
const QString& action) const {
|
||||
if (!quotedPassword.isEmpty()) {
|
||||
// NOTE: single %s — QString::arg() only substitutes %1..%99.
|
||||
return QStringLiteral("printf '%s\\n' %1 | sudo -S %2 2>&1\n")
|
||||
.arg(quotedPassword, action);
|
||||
}
|
||||
const bool useSudoPipe = !sudoPassword.isEmpty();
|
||||
if (QFileInfo(installPrefix()).isWritable()
|
||||
|| QFileInfo(installPrefix() + "/bin").isWritable()) {
|
||||
return action + QStringLiteral(" 2>&1\n");
|
||||
}
|
||||
return QStringLiteral("sudo %1 2>&1\n").arg(action);
|
||||
}
|
||||
|
||||
// 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.
|
||||
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("'");
|
||||
}
|
||||
|
||||
// Prebuilt path: unpack bin/ + plugins/ straight into the install prefix.
|
||||
// Archive layout matches the release workflow (bin/, plugins/).
|
||||
void UpdateManager::performPrebuiltUpdate(const QString& sudoPassword) {
|
||||
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"
|
||||
"WORK=$(mktemp -d /tmp/pacmanager-update-XXXXXX)\n"
|
||||
"trap 'rm -rf \"$WORK\"' EXIT\n"
|
||||
"URL=%1\n"
|
||||
"PREFIX=%2\n"
|
||||
"ARCHIVE=\"$WORK/update.tar.gz\"\n"
|
||||
"if command -v curl >/dev/null; then curl -fsSL -o \"$ARCHIVE\" \"$URL\" 2>&1;\n"
|
||||
"elif command -v wget >/dev/null; then wget -O \"$ARCHIVE\" \"$URL\" 2>&1;\n"
|
||||
"else echo 'curl ou wget est requis'; exit 1; fi\n"
|
||||
"tar xzf \"$ARCHIVE\" -C \"$WORK\" 2>&1\n"
|
||||
"[ -x \"$WORK/bin/PacManager\" ] || { echo 'Archive invalide'; exit 1; }\n"
|
||||
"mkdir -p \"$PREFIX/bin\"\n"
|
||||
"cp \"$WORK/bin/PacManager\" \"$WORK/bin/version\" \"$PREFIX/bin/\" 2>&1 || %3\n"
|
||||
"if [ -d \"$WORK/plugins\" ]; then\n"
|
||||
" mkdir -p \"$PREFIX/bin/plugins\"\n"
|
||||
" cp \"$WORK/plugins/\"*.so \"$PREFIX/bin/plugins/\" 2>/dev/null || true\n"
|
||||
"fi\n"
|
||||
"echo 'Mise a jour terminee.'");
|
||||
QString fallback = installCommand(
|
||||
quotedPassword(sudoPassword),
|
||||
QStringLiteral("cp \"$WORK/bin/PacManager\" \"$WORK/bin/version\" \"$PREFIX/bin/\""));
|
||||
script = script.arg(quoteShell(m_prebuiltUrl))
|
||||
.arg(quoteShell(installPrefix()))
|
||||
.arg(fallback);
|
||||
runShell(script, QDir::homePath());
|
||||
}
|
||||
|
||||
// Source path: fetch the tarball, compile in /tmp, reinstall to the prefix.
|
||||
void UpdateManager::performTarballUpdate(const QString& sudoPassword) {
|
||||
QString script = QStringLiteral(
|
||||
"set -e\n"
|
||||
"echo 'Mise a jour de PacManager...'\n"
|
||||
"command -v cmake >/dev/null || { echo 'cmake requis (pacman -S cmake)'; exit 1; }\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"
|
||||
"PREFIX=%2\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"
|
||||
"fi\n"
|
||||
// NOTE: single %h here — QString::arg() leaves %h untouched (only
|
||||
// %1..%99 are placeholders), so find receives the correct -printf.
|
||||
"else echo 'curl ou wget est requis'; exit 1; fi\n"
|
||||
"tar xzf \"$ARCHIVE\" -C \"$WORK\" 2>&1\n"
|
||||
// NOTE: single %h — QString::arg() leaves %h untouched (only
|
||||
// %1..%99 are placeholders), so find gets 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"
|
||||
"[ -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("'");
|
||||
};
|
||||
|
||||
"%3\n"
|
||||
"echo 'Mise a jour terminee.'");
|
||||
QString install = installCommand(
|
||||
quotedPassword(sudoPassword),
|
||||
QStringLiteral("cmake --install \"$WORK/build\" --prefix \"$PREFIX\""));
|
||||
script = script.arg(quoteShell(m_tarballUrl))
|
||||
.arg(quoteShell(m_latestVersion))
|
||||
.arg(quoteShell(installPrefix()))
|
||||
.arg(installStep);
|
||||
|
||||
.arg(install);
|
||||
runShell(script, QDir::homePath());
|
||||
}
|
||||
Reference in new issue
Block a user