From 0e933b77c3e4f780236e137124eae31d867a80ad Mon Sep 17 00:00:00 2001 From: Joran Dirk Greef Date: Mon, 10 Dec 2018 18:37:25 +0200 Subject: [PATCH] Add a fallback to `which pkexec` on Linux Fixes: https://github.com/jorangreef/sudo-prompt/issues/77 --- index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 6226e37..7bd73c7 100644 --- a/index.js +++ b/index.js @@ -124,9 +124,7 @@ function LinuxBinary(instance, end) { // However, gksudo cannot run multiple commands concurrently. var paths = ['/usr/bin/kdesudo', '/usr/bin/pkexec']; function test() { - if (index === paths.length) { - return end(new Error('Unable to find pkexec or kdesudo.')); - } + if (index === paths.length) return which(); var path = paths[index++]; Node.fs.stat(path, function(error) { @@ -140,6 +138,17 @@ function LinuxBinary(instance, end) { } ); } + function which() { + // Operating system paths are not always predictable. + // Fallback to a best-effort search for pkexec. + Node.child.exec('which pkexec', + function(error, stdout, stderr) { + if (error) return end(new Error('Unable to find pkexec or kdesudo.')); + var path = stdout.toString('utf-8').trim(); // Remove trailing newline. + end(undefined, path); + } + ); + } test(); }