]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Dolphin Service Menu Installer: Launch certain scripts in Konsole
authorAlexander Lohnau <alexander.lohnau@gmx.de>
Sun, 3 May 2020 18:07:53 +0000 (20:07 +0200)
committerAlexander Lohnau <alexander.lohnau@gmx.de>
Sun, 3 May 2020 18:22:11 +0000 (20:22 +0200)
Summary:
In general the issue with installers/uninstallers for the dolphin plugin is
that a lot of the scripts are intended to be run manually in a terminal.
For instance if a script uses `sudo make install` the user can't type in the password.

With this patch scripts that are executed without arg variants are
executed in konsole (if available).

Test Plan:
Tests still pass. Try to install the "Jetbrains Dolphin Plugin" tar.gz file from the kde store.
If you have the required dependencies etc. the konsole window should close.
If the install script fails (type in wrong admin password a couple of times) you
should have a shell opened.

Reviewers: #dolphin, ngraham, nicolasfella, elvisangelaccio, meven

Reviewed By: #dolphin, elvisangelaccio

Subscribers: kfm-devel

Tags: #dolphin

Differential Revision: https://phabricator.kde.org/D29089

src/settings/services/servicemenuinstaller/CMakeLists.txt
src/settings/services/servicemenuinstaller/servicemenuinstaller.cpp

index 9888999368267e519553bc125e1d4c3adec2e440..deb08421bf8cb636b5fb10eb14c7fc2e88f6bcdc 100644 (file)
@@ -6,5 +6,6 @@ target_link_libraries(servicemenuinstaller PRIVATE
     Qt5::Core
     Qt5::Gui
     KF5::I18n
+    KF5::CoreAddons
 )
 install(TARGETS servicemenuinstaller ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
index 06f34c6b932be4a252ba5454fa35bb467082c3f7..60621921affdd80a44264cfbbf2425a32a21a32e 100644 (file)
@@ -30,6 +30,7 @@
 #include <QGuiApplication>
 
 #include <KLocalizedString>
+#include <KShell>
 
 // @param msg Error that gets logged to CLI
 Q_NORETURN void fail(const QString &str)
@@ -59,6 +60,11 @@ struct UncompressCommand
     QStringList args2;
 };
 
+enum ScriptExecution{
+    Process,
+    Konsole
+};
+
 void runUncompress(const QString &inputPath, const QString &outputPath)
 {
     QVector<QPair<QStringList, UncompressCommand>> mimeTypeToCommand;
@@ -126,12 +132,24 @@ QString findRecursive(const QString &dir, const QString &basename)
     return QString();
 }
 
-bool runScriptOnce(const QString &path, const QStringList &args)
+bool runScriptOnce(const QString &path, const QStringList &args, ScriptExecution execution)
 {
     QProcess process;
     process.setWorkingDirectory(QFileInfo(path).absolutePath());
 
-    process.start(path, args, QIODevice::NotOpen);
+    const static bool konsoleAvailable = !QStandardPaths::findExecutable("konsole").isEmpty();
+    if (konsoleAvailable && execution == ScriptExecution::Konsole) {
+        QString bashCommand = KShell::quoteArg(path) + ' ';
+        if (!args.isEmpty()) {
+            bashCommand.append(args.join(' '));
+        }
+        bashCommand.append("|| $SHELL");
+        // If the install script fails a shell opens and the user can fix the problem
+        // without an error konsole closes
+        process.start("konsole", QStringList() << "-e" << "bash" << "-c" << bashCommand, QIODevice::NotOpen);
+    } else {
+        process.start(path, args, QIODevice::NotOpen);
+    }
     if (!process.waitForStarted()) {
         fail(i18n("Failed to run installer script %1", path));
     }
@@ -163,11 +181,11 @@ bool runScriptVariants(const QString &path, bool hasArgVariants, const QStringLi
     qInfo() << "[servicemenuinstaller]: Trying to run installer/uninstaller" << path;
     if (hasArgVariants) {
         for (const auto &arg : argVariants) {
-            if (runScriptOnce(path, {arg})) {
+            if (runScriptOnce(path, {arg}, ScriptExecution::Process)) {
                 return true;
             }
         }
-    } else if (runScriptOnce(path, {})) {
+    } else if (runScriptOnce(path, {}, ScriptExecution::Konsole)) {
         return true;
     }
 
@@ -247,7 +265,11 @@ bool cmdInstall(const QString &archive, QString &errorText)
         }
 
         if (!installerPath.isEmpty()) {
-            return runScriptVariants(installerPath, true, {"--local", "--local-install", "--install"}, errorText);
+            // Try to run script without variants first
+            if (!runScriptVariants(installerPath, false, {}, errorText)) {
+                return runScriptVariants(installerPath, true, {"--local", "--local-install", "--install"}, errorText);
+            }
+            return true;
         }
 
         fail(i18n("Failed to find an installation script in %1", dir));