diff ui/installwrapper.cpp @ 646:a9a57dc1eb2f

Start installer process as sudo if possible.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 25 Jun 2014 10:55:03 +0200
parents cef732072774
children 51830f4912c2
line wrap: on
line diff
--- a/ui/installwrapper.cpp	Tue Jun 24 18:10:10 2014 +0200
+++ b/ui/installwrapper.cpp	Wed Jun 25 10:55:03 2014 +0200
@@ -150,20 +150,46 @@
     }
 #else /* WIN32 */
     QProcess installerProcess;
-    installerProcess.setProgram(cinstProcInfo.absoluteFilePath());
     QStringList parameters;
 
     choicesFile.setAutoRemove(false);
     parameters << "list=" + mCertListFile << "choices=" + choicesFile.fileName();
-    installerProcess.setArguments(parameters);
-
 
-    qDebug() << "Starting process " << cinstFileName <<" params: " << parameters;
-    installerProcess.start();
-    if (!installerProcess.waitForStarted() ||
-        installerProcess.state() == QProcess::NotRunning) {
-        emit error (tr("Failed to start installer process."));
-        return;
+    bool sudo_started = false;
+    bool use_sudo = is_admin();
+    if (use_sudo) {
+        QStringList sudoPrograms;
+        sudoPrograms << "gksudo" << "kdesudo" << "sudo";
+        QStringList sudoParams;
+        sudoParams <<cinstProcInfo.absoluteFilePath() << parameters;
+        installerProcess.setArguments(sudoParams);
+
+        foreach (const QString &sProg, sudoPrograms) {
+            installerProcess.setProgram(sProg);
+            qDebug() << "Starting process " << sProg <<" params: " << sudoParams;
+            installerProcess.start();
+            if (!installerProcess.waitForStarted() ||
+                installerProcess.state() == QProcess::NotRunning) {
+                continue;
+            } else {
+                sudo_started = true;
+                break;
+            }
+        }
+    }
+
+    /* Fallback to start without sudo */
+    if (!use_sudo || !sudo_started) {
+        installerProcess.setProgram(cinstProcInfo.absoluteFilePath());
+        installerProcess.setArguments(parameters);
+
+        qDebug() << "Starting process " << cinstFileName <<" params: " << parameters;
+        installerProcess.start();
+        if (!installerProcess.waitForStarted() ||
+            installerProcess.state() == QProcess::NotRunning) {
+            emit error (tr("Failed to start installer process."));
+            return;
+        }
     }
 
     installerProcess.waitForFinished();

http://wald.intevation.org/projects/trustbridge/