From 975c949fdf403507f3bca325beb5330ae93d0776 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 19 Apr 2016 11:07:59 -0400 Subject: [PATCH] Allow to bypass elevation with an environment variable (#343) This is mostly used for debugging purposes, or by power users that know what they're doing. Signed-off-by: Juan Cruz Viotti --- lib/elevate.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/elevate.js b/lib/elevate.js index b921ece0..a565f886 100644 --- a/lib/elevate.js +++ b/lib/elevate.js @@ -29,19 +29,26 @@ exports.require = function(app, applicationName, callback) { } return Bluebird.try(function() { - if (platform === 'darwin') { - // Keep parent process hidden - app.dock.hide(); + // This environment variable is usually set + // for debugging purposes, or for power users + // that really know what they're doing. + if (!process.env.ETCHER_BYPASS_ELEVATION) { - return sudoPrompt.execAsync(process.argv.join(' '), { - name: applicationName - }); - } + if (platform === 'darwin') { - if (platform === 'win32') { - const elevator = Bluebird.promisifyAll(require('elevator')); - return elevator.executeAsync(process.argv, {}); + // Keep parent process hidden + app.dock.hide(); + + return sudoPrompt.execAsync(process.argv.join(' '), { + name: applicationName + }); + } + + if (platform === 'win32') { + const elevator = Bluebird.promisifyAll(require('elevator')); + return elevator.executeAsync(process.argv, {}); + } } throw new Error('Please run this application as root or administrator');