@@ -404,8 +404,8 @@ var getPullTask = (repodef, branch, repoowner, errHandler, elevatedBatch, regula | |||
if (exists) { | |||
var branchprint = branch ? ' branch :' + branch : ''; | |||
console.log('pulling ' + instanceroot + '/' + repo + branchprint ) | |||
var task = ()=>{ | |||
console.log('pulling ' + instanceroot + '/' + repo + branchprint ) | |||
return nodeShellExec.apply(null, getPullCmd(repo, branch)).then(() => { | |||
return true; | |||
}) | |||
@@ -413,6 +413,7 @@ var getPullTask = (repodef, branch, repoowner, errHandler, elevatedBatch, regula | |||
initTask(task) | |||
if(repodef.requiresElevation) { | |||
if(elevatedBatch.length === 1) { initTask(elevatedBatch[0]) } // PB : TDOO -- Make sure first task also has run context. May need to be moved to win_verse | |||
elevatedBatch.push(shell_verse.getElevatedTask( task )); | |||
return elevatedBatch[elevatedBatch.length-1] | |||
} | |||
@@ -2374,7 +2375,7 @@ var elxr = { | |||
// shell_verse.getElevatedTask( t1 ) | |||
var eBatch = [] | |||
def.elevated.map((def) => getPullTask(def, null, null, null, eBatch)) | |||
return any(shell_verse.runElevatedBatch(eBatch)).then(() => { | |||
return shell_verse.runElevatedBatch(eBatch).then(() => { | |||
return true; | |||
}).catch((e) => { | |||
console.error(e) | |||
@@ -2431,7 +2432,11 @@ function elxrworker() { | |||
// --runas | |||
if (processedArgs.runas) { | |||
// Weve been asked to run in priviledged mode. Check if we already are privileged. | |||
return __runcmd('runas') | |||
// return __runcmd('runas') | |||
// we no longer have a runas function. This has been moved to shellverse.requestElevation... | |||
// Each task has knowledge of requiring elevation and will handle elevation requests as needed. Preferably the task will participate in a batch and queue itself. | |||
// | |||
return __runcmd(processedArgs.label || processedArgs._[0] || 'undefined'); | |||
} | |||
else return __runcmd(processedArgs.label || processedArgs._[0] || 'undefined'); | |||
} | |||
@@ -4001,7 +4006,7 @@ var maintask = () => { | |||
return prerequisites.git.verifyAndInstall().then(()=>{ | |||
var e = { message : 'verifyAndInstall', success : true} | |||
var inittasks = [] | |||
var commantask = () => { preworkerconfig(); return elxrworker(true) } | |||
var commontask = () => { preworkerconfig(); return elxrworker(true) } | |||
if(!detection_state.localInstanceDetected) { | |||
var t1 = ()=>{ return createInstance(selectedinstance) }; | |||
t1.statuslog = statuslog | |||
@@ -4013,10 +4018,10 @@ var maintask = () => { | |||
var specifictask = shell_verse.getNonElevatedTask(t2) | |||
} | |||
inittasks.push( specifictask().catch((err) => { | |||
e = err; | |||
console.error('Chosen cofiguraton failed or not found. Fix config and rerun or chose another.') | |||
console.error(err) | |||
}).then( commantask ) | |||
e = err; | |||
console.error('Chosen cofiguraton failed or not found. Fix config and rerun or chose another.') | |||
console.error(err) | |||
}).then( commontask ) | |||
// .finally(()=>{ | |||
// fs.writeFileSync('run.log', ', ' + JSON.stringify({ error: e.message }), { 'flag': 'a+' }) | |||
// if(!e.success) fs.writeFileSync('run.done', 'error'); | |||
@@ -4098,13 +4103,14 @@ function generateDependencies(){ | |||
// PB : TODO -- Convert all the cli args back to string. | |||
// __filename will sure we are launhed using the same entry point. | |||
var cargs = (processedArgs.debug ? '--inspect-brk=9228' : '') + ' ${__filename.replace(/\\/g, '\\\\')} ' + processedArgs._.join(' ') + ' ' + namedArgs.join(' '); | |||
// alert(cargs) | |||
var shell = new ActiveXObject('shell.application'); | |||
// alert('launching node privilged. ' + processedArgs['nodepath']) | |||
// shell.ShellExecute('where', 'node', '', '', 10); | |||
// shell.ShellExecute('cmd.exe', '/k where node', '', '', 10); | |||
// shell.ShellExecute('cmd.exe', '/k notepad.exe', '', 'runas', 1); | |||
// shell.ShellExecute('cmd.exe ', '/k node "' + cargs + '"', '', 'runas', 1); | |||
// shell.ShellExecute('cmd.exe ', '/k node ', '', 'runas', 1); | |||
// shell.ShellExecute('cmd.exe ', '/k node ' + cargs + '', '', 'runas', 1); | |||
shell.ShellExecute('node', cargs, '', 'runas', 1); | |||
// alert('/k node ' + cargs + '') | |||
// shell.ShellExecute(processedArgs['nodepath'], cargs, '', 'runas', 1); | |||
var fso = new ActiveXObject('Scripting.FileSystemObject'); | |||
@@ -1,3 +1,4 @@ | |||
const { any } = require('bbhverse'); | |||
const fs = require('fs') | |||
var cli = require('./cliverse') | |||
@@ -40,26 +41,28 @@ var shell_verse = { | |||
} | |||
, elevatedRunner( taskToRun ){ | |||
// PB : TODO -- Should be called only when we are in an elevated shell that was already requested from an unelevated shell with a batch of tasks. | |||
try { | |||
// PB : We do not need IPC in linux. Until a real sudo elevation is required eveything works in non elevated mode... | |||
var __runasresult = null; | |||
return taskToRun().then((r)=>{ | |||
// PB : TODO -- Every elevation should have its own messaging file. Async writes from multiple processes are a problem here... | |||
fs.writeFileSync('run.log', ', ' + JSON.stringify( { info : taskToRun.info, success: true }), { 'flag': 'a+' }) | |||
fs.writeFileSync('run.done', 'success') // PB : TODO -- This should be done conditionally if we are running inproc. | |||
// fs.writeFileSync('run.log', ', ' + JSON.stringify( { info : taskToRun.info, success: true }), { 'flag': 'a+' }) | |||
// fs.writeFileSync('run.done', 'success') // PB : TODO -- This should be done conditionally if we are running inproc. | |||
return __runasresult = r; | |||
}) | |||
.catch((e) => { | |||
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' }) | |||
fs.writeFileSync('run.done', 'failure') | |||
// fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' }) | |||
// fs.writeFileSync('run.done', 'failure') | |||
console.error(e) | |||
}) | |||
.finally(() => { | |||
if(__runasresult && !__runasresult.skipped) fs.unlinkSync('run.done') | |||
// if(__runasresult && !__runasresult.skipped) fs.unlinkSync('run.done') | |||
}) | |||
} | |||
catch (e) { | |||
console.error('Error Invalid command : ' + e) | |||
fs.writeFileSync('run.done', 'error') | |||
// fs.writeFileSync('run.done', 'error') | |||
} | |||
finally { | |||
} | |||
@@ -87,14 +90,14 @@ var shell_verse = { | |||
, runElevatedBatch( batchToRun ){ | |||
// In windows we don't need to run each task. We hand over to another shell which in elevated state rebuilds the whole batch and runs. | |||
// Irrespective of the batch we just call runElevated once. | |||
return batchToRun.map( t => runElevated ) | |||
return any(batchToRun.map( t => runElevated )) | |||
} | |||
, getNonElevatedTask : function( taskToRun ){ return ()=>{ return shell_verse.runNonElevated(taskToRun) } } | |||
, runNonElevated : ( taskToRun ) => { | |||
// Let shell_verse decide whether to Elevate Out of Proc or In Proc | |||
if(__isElevated) { | |||
return Promise.resolve( new Error('Cannot Run Task in Elevated Mode.') ) | |||
return Promise.resolve( 'Skipping regular task in elevated shell.' ) // Regular tasks unless marked as common tasks should not run in elevated shell... | |||
} | |||
else { | |||
// taskToRun by default is the launched command and args. |
@@ -1,3 +1,4 @@ | |||
const { any } = require('bbhverse'); | |||
const fs = require('fs') | |||
var cli = require('./cliverse') | |||
@@ -13,6 +14,7 @@ var shell_verse = { | |||
} | |||
, elevatedRunner( taskToRun ){ | |||
// PB : TODO -- Should be called only when we are in an elevated shell that was already requested from an unelevated shell with a batch of tasks. | |||
try { | |||
var __runasresult = null; | |||
return taskToRun().then((r)=>{ | |||
@@ -60,14 +62,19 @@ var shell_verse = { | |||
, runElevatedBatch( batchToRun ){ | |||
// In windows we don't need to run each task. We hand over to another shell which in elevated state rebuilds the whole batch and runs. | |||
// Irrespective of the batch we just call runElevated once. | |||
return [runElevated(batchToRun[0])] | |||
if (__isElevated) { | |||
return any(batchToRun); | |||
} | |||
else { | |||
return this.runElevated(batchToRun[0]) | |||
} | |||
} | |||
, getNonElevatedTask : function( taskToRun ){ return ()=>{ return shell_verse.runNonElevated(taskToRun) } } | |||
, runNonElevated : ( taskToRun ) => { | |||
// Let shell_verse decide whether to Elevate Out of Proc or In Proc | |||
if(__isElevated) { | |||
return Promise.resolve( new Error('Cannot Run Task in Elevated Mode.') ) | |||
return Promise.resolve( 'Skipping regular task in elevated shell.' ) // Regular tasks unless marked as common tasks should not run in elevated shell... | |||
} | |||
else { | |||
// taskToRun by default is the launched command and args. |