diff --git a/src/helper.cpp b/src/helper.cpp --- a/src/helper.cpp +++ b/src/helper.cpp @@ -65,31 +65,85 @@ return reply; } int ret = 0; - QProcess process; - process.start("update-alternatives", QStringList() << "--set" << "default.plymouth" << dir.path() + QChar('/') + themeFile.first()); - if (!process.waitForStarted()) { + QProcess checkProcess; + QByteArray data; + qDebug() << "Running update-alternatives --list default.plymouth now"; + checkProcess.start("update-alternatives --list default.plymouth"); + if (!checkProcess.waitForStarted()) { reply = ActionReply::BackendError; reply.setErrorDescription(i18n("Cannot start update-alternatives.")); return reply; } - if (!process.waitForFinished()) { + if (!checkProcess.waitForFinished()) { reply = ActionReply::BackendError; reply.setErrorDescription(i18n("update-alternatives failed to run.")); return reply; } - ret = process.exitCode(); - + else { + data = checkProcess.readAllStandardOutput(); + } + ret = checkProcess.exitCode(); + if (ret != 0) { reply = ActionReply(ActionReply::HelperErrorReply()); reply.setErrorCode(static_cast(ret)); reply.setErrorDescription(i18n("update-alternatives returned with error condition %1.", ret)); return reply; } + QString installFile = dir.path() + QChar('/') + themeFile.first(); + if (!data.contains(installFile.toUtf8())) { + qDebug() << "Plymouth file not found in update-alternatives. So install it"; + QProcess installProcess; + installProcess.start("update-alternatives", QStringList() << "--install" << "/usr/share/plymouth/themes/default.plymouth" << "default.plymouth" << installFile << "100"); + + if (!installProcess.waitForStarted()) { + reply = ActionReply::BackendError; + reply.setErrorDescription(i18n("Cannot start update-alternatives.")); + return reply; + } + if (!installProcess.waitForFinished()) { + reply = ActionReply::BackendError; + reply.setErrorDescription(i18n("update-alternatives failed to run.")); + return reply; + } + ret = installProcess.exitCode(); + + if (ret != 0) { + reply = ActionReply(ActionReply::HelperErrorReply()); + reply.setErrorCode(static_cast(ret)); + reply.setErrorDescription(i18n("update-alternatives returned with error condition %1.", ret)); + return reply; + } + } + else { + qDebug() << "Running update-alternatives --set now"; + QProcess process; + process.start("update-alternatives", QStringList() << "--set" << "default.plymouth" << installFile); + if (!process.waitForStarted()) { + reply = ActionReply::BackendError; + reply.setErrorDescription(i18n("Cannot start update-alternatives.")); + return reply; + } + if (!process.waitForFinished()) { + reply = ActionReply::BackendError; + reply.setErrorDescription(i18n("update-alternatives failed to run.")); + return reply; + } + ret = process.exitCode(); + + if (ret != 0) { + reply = ActionReply(ActionReply::HelperErrorReply()); + reply.setErrorCode(static_cast(ret)); + reply.setErrorDescription(i18n("update-alternatives returned with error condition %1.", ret)); + return reply; + } + } } int ret = 0; QProcess process; + qDebug() << "Running update-initramfs -u now"; process.start("/usr/sbin/update-initramfs", QStringList() << "-u"); if (!process.waitForStarted()) { reply = ActionReply::BackendError;