From 55b438e8c18b2394c8e4fe3e37f2a6662b68ffc4 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Sat, 6 Mar 2010 20:17:00 -0800 Subject: [PATCH] Use sudo to update jake packages if sudo-install was the task. Closes #525. --- common.jake | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/common.jake b/common.jake index 613730d0f..4266c22d3 100644 --- a/common.jake +++ b/common.jake @@ -3,6 +3,13 @@ var FILE = require("file"); var OS = require("os"); var UTIL = require("util"); +var requiresSudo = false; + +SYSTEM.args.slice(1).forEach(function(arg){ + if (arg === "sudo-install") + requiresSudo = true; +}); + function ensurePackageUpToDate(packageName, requiredVersion, options) { options = options || {}; @@ -37,7 +44,18 @@ function ensurePackageUpToDate(packageName, requiredVersion, options) print("Jake aborted."); OS.exit(1); } - OS.system(["tusk", "install", "--force", packageName]); + + if (requiresSudo) + { + if (OS.system(["sudo", "tusk", "install", "--force", packageName])) + { + // Attempt a hackish work-around for sudo compiled with the --with-secure-path option + if (OS.system("sudo bash -c 'source " + getShellConfigFile() + "; tusk install --force "+packageName)) + OS.exit(1); //rake abort if ($? != 0) + } + } + else + OS.system(["tusk", "install", "--force", packageName]); } if (options.message)