if (exists) { | if (exists) { | ||||
var branchprint = branch ? ' branch :' + branch : ''; | var branchprint = branch ? ' branch :' + branch : ''; | ||||
console.log('pulling ' + instanceroot + '/' + repo + branchprint ) | |||||
var task = ()=>{ | var task = ()=>{ | ||||
console.log('pulling ' + instanceroot + '/' + repo + branchprint ) | |||||
return nodeShellExec.apply(null, getPullCmd(repo, branch)).then(() => { | return nodeShellExec.apply(null, getPullCmd(repo, branch)).then(() => { | ||||
return true; | return true; | ||||
}) | }) | ||||
initTask(task) | initTask(task) | ||||
if(repodef.requiresElevation) { | 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 )); | elevatedBatch.push(shell_verse.getElevatedTask( task )); | ||||
return elevatedBatch[elevatedBatch.length-1] | return elevatedBatch[elevatedBatch.length-1] | ||||
} | } | ||||
// shell_verse.getElevatedTask( t1 ) | // shell_verse.getElevatedTask( t1 ) | ||||
var eBatch = [] | var eBatch = [] | ||||
def.elevated.map((def) => getPullTask(def, null, null, null, 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; | return true; | ||||
}).catch((e) => { | }).catch((e) => { | ||||
console.error(e) | console.error(e) | ||||
// --runas | // --runas | ||||
if (processedArgs.runas) { | if (processedArgs.runas) { | ||||
// Weve been asked to run in priviledged mode. Check if we already are privileged. | // 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'); | else return __runcmd(processedArgs.label || processedArgs._[0] || 'undefined'); | ||||
} | } | ||||
return prerequisites.git.verifyAndInstall().then(()=>{ | return prerequisites.git.verifyAndInstall().then(()=>{ | ||||
var e = { message : 'verifyAndInstall', success : true} | var e = { message : 'verifyAndInstall', success : true} | ||||
var inittasks = [] | var inittasks = [] | ||||
var commantask = () => { preworkerconfig(); return elxrworker(true) } | |||||
var commontask = () => { preworkerconfig(); return elxrworker(true) } | |||||
if(!detection_state.localInstanceDetected) { | if(!detection_state.localInstanceDetected) { | ||||
var t1 = ()=>{ return createInstance(selectedinstance) }; | var t1 = ()=>{ return createInstance(selectedinstance) }; | ||||
t1.statuslog = statuslog | t1.statuslog = statuslog | ||||
var specifictask = shell_verse.getNonElevatedTask(t2) | var specifictask = shell_verse.getNonElevatedTask(t2) | ||||
} | } | ||||
inittasks.push( specifictask().catch((err) => { | 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(()=>{ | // .finally(()=>{ | ||||
// fs.writeFileSync('run.log', ', ' + JSON.stringify({ error: e.message }), { 'flag': 'a+' }) | // fs.writeFileSync('run.log', ', ' + JSON.stringify({ error: e.message }), { 'flag': 'a+' }) | ||||
// if(!e.success) fs.writeFileSync('run.done', 'error'); | // if(!e.success) fs.writeFileSync('run.done', 'error'); | ||||
// PB : TODO -- Convert all the cli args back to string. | // PB : TODO -- Convert all the cli args back to string. | ||||
// __filename will sure we are launhed using the same entry point. | // __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(' '); | var cargs = (processedArgs.debug ? '--inspect-brk=9228' : '') + ' ${__filename.replace(/\\/g, '\\\\')} ' + processedArgs._.join(' ') + ' ' + namedArgs.join(' '); | ||||
// alert(cargs) | |||||
var shell = new ActiveXObject('shell.application'); | var shell = new ActiveXObject('shell.application'); | ||||
// alert('launching node privilged. ' + processedArgs['nodepath']) | // 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 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); | shell.ShellExecute('node', cargs, '', 'runas', 1); | ||||
// alert('/k node ' + cargs + '') | |||||
// shell.ShellExecute(processedArgs['nodepath'], cargs, '', 'runas', 1); | // shell.ShellExecute(processedArgs['nodepath'], cargs, '', 'runas', 1); | ||||
var fso = new ActiveXObject('Scripting.FileSystemObject'); | var fso = new ActiveXObject('Scripting.FileSystemObject'); | ||||
const { any } = require('bbhverse'); | |||||
const fs = require('fs') | const fs = require('fs') | ||||
var cli = require('./cliverse') | var cli = require('./cliverse') | ||||
} | } | ||||
, elevatedRunner( taskToRun ){ | , 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 { | 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; | var __runasresult = null; | ||||
return taskToRun().then((r)=>{ | return taskToRun().then((r)=>{ | ||||
// PB : TODO -- Every elevation should have its own messaging file. Async writes from multiple processes are a problem here... | // 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; | return __runasresult = r; | ||||
}) | }) | ||||
.catch((e) => { | .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) | console.error(e) | ||||
}) | }) | ||||
.finally(() => { | .finally(() => { | ||||
if(__runasresult && !__runasresult.skipped) fs.unlinkSync('run.done') | |||||
// if(__runasresult && !__runasresult.skipped) fs.unlinkSync('run.done') | |||||
}) | }) | ||||
} | } | ||||
catch (e) { | catch (e) { | ||||
console.error('Error Invalid command : ' + e) | console.error('Error Invalid command : ' + e) | ||||
fs.writeFileSync('run.done', 'error') | |||||
// fs.writeFileSync('run.done', 'error') | |||||
} | } | ||||
finally { | finally { | ||||
} | } | ||||
, runElevatedBatch( batchToRun ){ | , 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. | // 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. | // 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) } } | , getNonElevatedTask : function( taskToRun ){ return ()=>{ return shell_verse.runNonElevated(taskToRun) } } | ||||
, runNonElevated : ( taskToRun ) => { | , runNonElevated : ( taskToRun ) => { | ||||
// Let shell_verse decide whether to Elevate Out of Proc or In Proc | // Let shell_verse decide whether to Elevate Out of Proc or In Proc | ||||
if(__isElevated) { | 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 { | else { | ||||
// taskToRun by default is the launched command and args. | // taskToRun by default is the launched command and args. |
const { any } = require('bbhverse'); | |||||
const fs = require('fs') | const fs = require('fs') | ||||
var cli = require('./cliverse') | var cli = require('./cliverse') | ||||
} | } | ||||
, elevatedRunner( taskToRun ){ | , 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 { | try { | ||||
var __runasresult = null; | var __runasresult = null; | ||||
return taskToRun().then((r)=>{ | return taskToRun().then((r)=>{ | ||||
, runElevatedBatch( batchToRun ){ | , 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. | // 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. | // 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) } } | , getNonElevatedTask : function( taskToRun ){ return ()=>{ return shell_verse.runNonElevated(taskToRun) } } | ||||
, runNonElevated : ( taskToRun ) => { | , runNonElevated : ( taskToRun ) => { | ||||
// Let shell_verse decide whether to Elevate Out of Proc or In Proc | // Let shell_verse decide whether to Elevate Out of Proc or In Proc | ||||
if(__isElevated) { | 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 { | else { | ||||
// taskToRun by default is the launched command and args. | // taskToRun by default is the launched command and args. |