diff --git a/common/modules/pkgselectprocess/PackageSelectProcess.cpp b/common/modules/pkgselectprocess/PackageSelectProcess.cpp index 01279f6..875202d 100644 --- a/common/modules/pkgselectprocess/PackageSelectProcess.cpp +++ b/common/modules/pkgselectprocess/PackageSelectProcess.cpp @@ -199,12 +199,74 @@ Calamares::JobResult PackageSelectProcess::runSnapCommand(const QStringList& sna } emit progress(endProgress); - m_prettyStatus = tr("Snap packages installed successfully."); + m_prettyStatus = tr("Snap packages installed successfully!"); emit prettyStatusMessageChanged(m_prettyStatus); return Calamares::JobResult::ok(); } +void PackageSelectProcess::divert(bool enable) +{ + for (auto it = dpkgDiversions.constBegin(); it != dpkgDiversions.constEnd(); ++it) { + const QString& name = it.key(); + const QString& path = it.value(); + QString divertedPath = path + ".REAL"; + QString command; + + if (enable) { + qDebug() << tr("Adding diversion for %1...").arg(name); + command = QString("dpkg-divert --quiet --add --divert %1 --rename %2") + .arg(divertedPath, path); + } else { + qDebug() << tr("Removing diversion for %1...").arg(name); + QFile::remove(rootMountPoint + path); + command = QString("dpkg-divert --quiet --remove --rename %1").arg(path); + } + + // Set up the QProcess to run the command in chroot + QProcess process; + process.setProgram("/usr/sbin/chroot"); + process.setArguments({ rootMountPoint, "/bin/bash", "-c", command }); + process.setProcessChannelMode(QProcess::MergedChannels); + + // Run the process + process.start(); + if (!process.waitForFinished()) { + qWarning() << "Process error:" << process.errorString(); + continue; + } + + if (process.exitStatus() != QProcess::NormalExit || process.exitCode() != 0) { + qWarning() << "Error handling diversion for" << name << ":" << process.readAll(); + continue; + } + + if (!enable) { continue; } + + // Create the replacement script in chroot + QString scriptContent = QString( + "#!/bin/sh\n" + "echo \"%1: diverted (will be called later)\" >&1\n" + "exit 0\n" + ).arg(name); + + QString scriptPath = rootMountPoint + path; + QFile scriptFile(scriptPath); + + if (!scriptFile.open(QIODevice::WriteOnly | QIODevice::Text)) { + qWarning() << "Error creating script for" << name << ":" << scriptFile.errorString(); + continue; + } + + QTextStream out(&scriptFile); + out << scriptContent; + scriptFile.close(); + + // Make the script executable + QFile::setPermissions(scriptPath, QFile::permissions(scriptPath) | QFile::ExeOwner | QFile::ExeGroup | QFile::ExeOther); + } +} + Calamares::JobResult PackageSelectProcess::exec() { auto gs = Calamares::JobQueue::instance()->globalStorage(); @@ -221,7 +283,7 @@ Calamares::JobResult PackageSelectProcess::exec() const QVariantList presentSnaps = installationData.value("present_snaps").toList(); // Handle default value for rootMountPoint - QString rootMountPoint = "/"; + rootMountPoint = "/"; if (gs->contains("rootMountPoint")) { rootMountPoint = gs->value("rootMountPoint").toString(); } @@ -260,6 +322,14 @@ Calamares::JobResult PackageSelectProcess::exec() } } + // Add diversions for dracut, update-initramfs, and locale-gen + dpkgDiversions = { + {"dracut", "/usr/bin/dracut"}, + {"update-initramfs", "/usr/sbin/update-initramfs"}, + {"locale-gen", "/usr/sbin/locale-gen"} + }; + divert(true); + double installStart; double installEnd; if (downloadUpdates) { @@ -337,6 +407,9 @@ Calamares::JobResult PackageSelectProcess::exec() autoremoveEnd, true); + // Disable diversions + divert(false); + // Handle snap packages if (installationMode != "minimal") { QStringList snapPackages; diff --git a/common/modules/pkgselectprocess/PackageSelectProcess.h b/common/modules/pkgselectprocess/PackageSelectProcess.h index c3d14b5..d2fa378 100644 --- a/common/modules/pkgselectprocess/PackageSelectProcess.h +++ b/common/modules/pkgselectprocess/PackageSelectProcess.h @@ -1,7 +1,9 @@ #ifndef PACKAGESELECTPROCESS_H #define PACKAGESELECTPROCESS_H +#include #include +#include #include #include "CppJob.h" #include "utils/PluginFactory.h" @@ -44,6 +46,11 @@ private: double startProgress, double endProgress); + void divert(bool enable); + + QMap dpkgDiversions; + QString rootMountPoint; + QVariantMap m_configurationMap; QString m_prettyStatus; }; diff --git a/debian/changelog b/debian/changelog index d35f63f..98e0c40 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +calamares-settings-ubuntu (1:25.04.10) UNRELEASED; urgency=medium + + * [pkgselectprocess] Add dpkg diversions for dracut, update-initramfs, and + locale-gen. These will be called later in the process. + + -- Simon Quigley Sun, 24 Nov 2024 20:22:55 -0600 + calamares-settings-ubuntu (1:25.04.9) plucky; urgency=medium * Add a Dracut config file for Lubuntu.