|  |  |  |  |  |  | 
													
												
													
														|  |  | ); |  |  | ); | 
													
												
													
														|  |  | } |  |  | } | 
													
												
													
														|  |  | 
 |  |  | 
 | 
													
												
													
														|  |  |  |  |  | var __isElevated = null; | 
													
												
													
														|  |  | var isRunningElevated = ()=>{ |  |  | var isRunningElevated = ()=>{ | 
													
												
													
														|  |  | return nodeShellExec( "fsutil", ["dirty", "query", "C:"], { |  |  |  | 
													
												
													
														|  |  | inherit : true, shell: true |  |  |  | 
													
												
													
														|  |  | , env: process.env |  |  |  | 
													
												
													
														|  |  | , title : `check privileged execution mode using fsutil dirty query C:` |  |  |  | 
													
												
													
														|  |  | }).then((exitcode)=>{ |  |  |  | 
													
												
													
														|  |  | console.log('Elevated') |  |  |  | 
													
												
													
														|  |  | return true; |  |  |  | 
													
												
													
														|  |  | }).catch(()=>{ |  |  |  | 
													
												
													
														|  |  | console.log('Not Elevated'); |  |  |  | 
													
												
													
														|  |  | throw false; |  |  |  | 
													
												
													
														|  |  | }); |  |  |  | 
													
												
													
														|  |  |  |  |  | if(__isElevated === null) { | 
													
												
													
														|  |  |  |  |  | return nodeShellExec( "fsutil", ["dirty", "query", "C:"], { | 
													
												
													
														|  |  |  |  |  | inherit : true | 
													
												
													
														|  |  |  |  |  | // , shell: true | 
													
												
													
														|  |  |  |  |  | // , stdio: 'ignore' | 
													
												
													
														|  |  |  |  |  | , env: process.env | 
													
												
													
														|  |  |  |  |  | , title : `check privileged execution mode using "fsutil dirty query C:"` | 
													
												
													
														|  |  |  |  |  | }).then((exitcode)=>{ | 
													
												
													
														|  |  |  |  |  | console.log('Elevated') | 
													
												
													
														|  |  |  |  |  | __isElevated = true; | 
													
												
													
														|  |  |  |  |  | return true; | 
													
												
													
														|  |  |  |  |  | }).catch(()=>{ | 
													
												
													
														|  |  |  |  |  | __isElevated = false; | 
													
												
													
														|  |  |  |  |  | console.log('Not Elevated'); | 
													
												
													
														|  |  |  |  |  | throw false; | 
													
												
													
														|  |  |  |  |  | }); | 
													
												
													
														|  |  |  |  |  | } | 
													
												
													
														|  |  |  |  |  | else return Promise.resolve(__isElevated); | 
													
												
													
														|  |  | } |  |  | } | 
													
												
													
														|  |  | 
 |  |  | 
 | 
													
												
													
														|  |  | 
 |  |  | 
 | 
													
												
											
												
													
														|  |  |  |  |  |  | 
													
												
													
														|  |  | , 'chess-server' |  |  | , 'chess-server' | 
													
												
													
														|  |  | ] |  |  | ] | 
													
												
													
														|  |  | 
 |  |  | 
 | 
													
												
													
														|  |  |  |  |  | var productionRepos = [ | 
													
												
													
														|  |  |  |  |  | 'elixir-config-production' | 
													
												
													
														|  |  |  |  |  | ] | 
													
												
													
														|  |  | 
 |  |  | 
 | 
													
												
													
														|  |  | var env = Object.assign({}, process.env); // Shallow clone it. |  |  | var env = Object.assign({}, process.env); // Shallow clone it. | 
													
												
													
														|  |  | var __runcmd = function(label){ |  |  | var __runcmd = function(label){ | 
													
												
													
														|  |  | 
 |  |  | 
 | 
													
												
													
														|  |  | var op = { |  |  | var op = { | 
													
												
													
														|  |  | 'h' : ()=>{ console.log(cli + ' ' + ver + ' ' + help); return '-h' } |  |  | 'h' : ()=>{ console.log(cli + ' ' + ver + ' ' + help); return '-h' } | 
													
												
													
														|  |  |  |  |  | , 'undefined' : ()=>{ return op.h(); } | 
													
												
													
														|  |  | , 'upgrade' : ()=>{ |  |  | , 'upgrade' : ()=>{ | 
													
												
													
														|  |  | console.log('upgrade.......') |  |  | console.log('upgrade.......') | 
													
												
													
														|  |  | var tasks = [ |  |  | var tasks = [ | 
													
												
											
												
													
														|  |  |  |  |  |  | 
													
												
													
														|  |  | }) |  |  | }) | 
													
												
													
														|  |  | } |  |  | } | 
													
												
													
														|  |  | , 'runas' : ()=>{ |  |  | , 'runas' : ()=>{ | 
													
												
													
														|  |  | return isRunningElevated().then(() => op[ processedArgs.label || processedArgs._[0] || 'h']() ) |  |  |  | 
													
												
													
														|  |  |  |  |  | return isRunningElevated().then( | 
													
												
													
														|  |  |  |  |  | (isElevated) => { | 
													
												
													
														|  |  |  |  |  | if(isElevated)  { | 
													
												
													
														|  |  |  |  |  | try { | 
													
												
													
														|  |  |  |  |  | op[ processedArgs.label || processedArgs._[0] || 'h']() | 
													
												
													
														|  |  |  |  |  | } | 
													
												
													
														|  |  |  |  |  | catch(e){ | 
													
												
													
														|  |  |  |  |  | console.error('Error Invalid command : ' + e) | 
													
												
													
														|  |  |  |  |  | fs.writeFileSync('run.done', 'success') | 
													
												
													
														|  |  |  |  |  | } | 
													
												
													
														|  |  |  |  |  | finally { | 
													
												
													
														|  |  |  |  |  | } | 
													
												
													
														|  |  |  |  |  | } else throw false; | 
													
												
													
														|  |  |  |  |  | } | 
													
												
													
														|  |  |  |  |  | ) | 
													
												
													
														|  |  | .catch(()=>{ |  |  | .catch(()=>{ | 
													
												
													
														|  |  | console.log('Not Elevated'); |  |  |  | 
													
												
													
														|  |  | console.dir(processedArgs) |  |  |  | 
													
												
													
														|  |  |  |  |  | console.log('Not Elevated Requesting Elevated Privileges'); | 
													
												
													
														|  |  |  |  |  | // Wait for the runas to complete before we read it. | 
													
												
													
														|  |  |  |  |  | try { | 
													
												
													
														|  |  |  |  |  | fs.unlinkSync('run.done') | 
													
												
													
														|  |  |  |  |  | fs.unlinkSync('run.log') | 
													
												
													
														|  |  |  |  |  | } | 
													
												
													
														|  |  |  |  |  | catch(e) { } //Ignore | 
													
												
													
														|  |  |  |  |  |  | 
													
												
													
														|  |  | // PB : TODO -- Convert all the cli args back to string. |  |  | // PB : TODO -- Convert all the cli args back to string. | 
													
												
													
														|  |  | var namedArgs = []; |  |  | var namedArgs = []; | 
													
												
													
														|  |  | Object.keys(processedArgs).forEach((v)=>{ v!='_' ? namedArgs.push('--'+v+'='+processedArgs[v]) : null; }) |  |  | Object.keys(processedArgs).forEach((v)=>{ v!='_' ? namedArgs.push('--'+v+'='+processedArgs[v]) : null; }) | 
													
												
													
														|  |  | var cargs = `${processedArgs.debug ? '--inspect-brk' : ''} --inspect-brk elxr ${processedArgs._.join(' ')} ${namedArgs.join(' ') } --runas=true` |  |  | var cargs = `${processedArgs.debug ? '--inspect-brk' : ''} --inspect-brk elxr ${processedArgs._.join(' ')} ${namedArgs.join(' ') } --runas=true` | 
													
												
													
														|  |  | console.log('Requesting Elevated Privileges for : ' + `node ${cargs}`) |  |  | console.log('Requesting Elevated Privileges for : ' + `node ${cargs}`) | 
													
												
													
														|  |  | // fs.writeFileSync('runas.js', `javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute('node', '${cargs}', '', 'runas', 1);close();`) |  |  |  | 
													
												
													
														|  |  | nodeShellExec('MSHTA', [`javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute('node', '${cargs}', '', 'runas', 1);close();`] |  |  |  | 
													
												
													
														|  |  |  |  |  | process.env.NODE_ENV = process.env.NODE_ENV || 'development'; | 
													
												
													
														|  |  |  |  |  | var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._); args.push('--runas') | 
													
												
													
														|  |  |  |  |  | nodeShellExec('MSHTA', [`"${args.join('" "')}"`] | 
													
												
													
														|  |  | , { |  |  | , { | 
													
												
													
														|  |  | // inherit : true |  |  |  | 
													
												
													
														|  |  | // , shell: true |  |  |  | 
													
												
													
														|  |  | // cwd : process.env.pwd |  |  |  | 
													
												
													
														|  |  |  |  |  | inherit : true | 
													
												
													
														|  |  |  |  |  | , | 
													
												
													
														|  |  |  |  |  | shell: true | 
													
												
													
														|  |  | // , |  |  | // , | 
													
												
													
														|  |  | env: process.env |  |  |  | 
													
												
													
														|  |  |  |  |  | , env: process.env | 
													
												
													
														|  |  |  |  |  | , runas : true | 
													
												
													
														|  |  |  |  |  | , title : `runas` | 
													
												
													
														|  |  | } |  |  | } | 
													
												
													
														|  |  | ); |  |  |  | 
													
												
													
														|  |  |  |  |  | ).then(()=>{ | 
													
												
													
														|  |  |  |  |  | // runas returned. | 
													
												
													
														|  |  |  |  |  | var runaslog = JSON.parse('[ { "success" : true, "result" : "runas Log" }' + fs.readFileSync('run.log', { flags : 'a+'}) + ']'); | 
													
												
													
														|  |  |  |  |  | runaslog.forEach((logEntry)=>{ | 
													
												
													
														|  |  |  |  |  | logEntry.succes ? (console.log(['success :' + logEntry.result]), console.log((logEntry.messages || []).join(' '))) : console.error(['error :' + logEntry.result]), console.error((logEntry.messages || []).join(' ')) | 
													
												
													
														|  |  |  |  |  | }) | 
													
												
													
														|  |  |  |  |  | }) | 
													
												
													
														|  |  |  |  |  | .catch(err => console.error('Elevation failed : ' + err)); | 
													
												
													
														|  |  | }) |  |  | }) | 
													
												
													
														|  |  | } |  |  | } | 
													
												
													
														|  |  | , 'push' : ()=>{ |  |  | , 'push' : ()=>{ | 
													
												
											
												
													
														|  |  |  |  |  |  | 
													
												
													
														|  |  | var performPull = repo => { |  |  | var performPull = repo => { | 
													
												
													
														|  |  | if(existsSync(repo)) { |  |  | if(existsSync(repo)) { | 
													
												
													
														|  |  | console.log('pulling ' + repo) |  |  | console.log('pulling ' + repo) | 
													
												
													
														|  |  | nodeShellExec('git', ['pull'], { |  |  |  | 
													
												
													
														|  |  |  |  |  | return nodeShellExec('git', ['pull'], { | 
													
												
													
														|  |  | inherit : true, shell: true, |  |  | inherit : true, shell: true, | 
													
												
													
														|  |  | cwd : repo |  |  | cwd : repo | 
													
												
													
														|  |  | // , env: process.env |  |  | // , env: process.env | 
													
												
													
														|  |  |  |  |  | , runas : processedArgs.runas | 
													
												
													
														|  |  | , title : `git pull ${repo}` |  |  | , title : `git pull ${repo}` | 
													
												
													
														|  |  | }).catch((e)=>{ console.error(e) }) |  |  | }).catch((e)=>{ console.error(e) }) | 
													
												
													
														|  |  | } |  |  | } | 
													
												
													
														|  |  | else { |  |  | else { | 
													
												
													
														|  |  | console.log('cloning ' + repo) |  |  | console.log('cloning ' + repo) | 
													
												
													
														|  |  | nodeShellExec('git', ['clone', '//172.16.0.27/repos/' + repo + '.git'], |  |  |  | 
													
												
													
														|  |  |  |  |  | return nodeShellExec('git', ['clone', '//172.16.0.27/repos/' + repo + '.git'], | 
													
												
													
														|  |  | { |  |  | { | 
													
												
													
														|  |  | inherit : true, shell: true, |  |  | inherit : true, shell: true, | 
													
												
													
														|  |  | env: process.env |  |  | env: process.env | 
													
												
													
														|  |  |  |  |  | , runas : processedArgs.runas | 
													
												
													
														|  |  | , title : `git clone ${'//172.16.0.27/repos/' + repo + '.git'}` |  |  | , title : `git clone ${'//172.16.0.27/repos/' + repo + '.git'}` | 
													
												
													
														|  |  | }).catch((e)=>{ console.error(e) }) |  |  | }).catch((e)=>{ console.error(e) }) | 
													
												
													
														|  |  | } |  |  | } | 
													
												
											
												
													
														|  |  |  |  |  |  | 
													
												
													
														|  |  | 
 |  |  | 
 | 
													
												
													
														|  |  | if(!processedArgs.runas) gitRepos.forEach(performPull) |  |  | if(!processedArgs.runas) gitRepos.forEach(performPull) | 
													
												
													
														|  |  | return isRunningElevated().then( |  |  | return isRunningElevated().then( | 
													
												
													
														|  |  | ()=> elevatedRunasRepos.forEach(performPull)) |  |  |  | 
													
												
													
														|  |  | .catch( |  |  |  | 
													
												
													
														|  |  | () => op['runas']() |  |  |  | 
													
												
													
														|  |  |  |  |  | (isElevated) => { | 
													
												
													
														|  |  |  |  |  | if(isElevated) { | 
													
												
													
														|  |  |  |  |  | any(elevatedRunasRepos.map((repo)=>performPull(repo))).then(()=>{ | 
													
												
													
														|  |  |  |  |  | fs.writeFileSync('run.done', 'success') | 
													
												
													
														|  |  |  |  |  | }).catch(()=>{ | 
													
												
													
														|  |  |  |  |  | fs.writeFileSync('run.done', 'error') | 
													
												
													
														|  |  |  |  |  | }) | 
													
												
													
														|  |  |  |  |  | } | 
													
												
													
														|  |  |  |  |  | else throw false; | 
													
												
													
														|  |  |  |  |  | } | 
													
												
													
														|  |  |  |  |  | ).catch( | 
													
												
													
														|  |  |  |  |  | () => { | 
													
												
													
														|  |  |  |  |  | op['runas']() | 
													
												
													
														|  |  |  |  |  | } | 
													
												
													
														|  |  | ) |  |  | ) | 
													
												
													
														|  |  |  |  |  |  | 
													
												
													
														|  |  | } |  |  | } | 
													
												
													
														|  |  | , 'npmi' : ()=>{ |  |  | , 'npmi' : ()=>{ | 
													
												
													
														|  |  | var tasks = []; |  |  | var tasks = []; | 
													
												
											
												
													
														|  |  |  |  |  |  | 
													
												
													
														|  |  | console.log('Starting Elixir Server.'); |  |  | console.log('Starting Elixir Server.'); | 
													
												
													
														|  |  | var env = Object.assign({}, process.env); // Shallow clone it. |  |  | var env = Object.assign({}, process.env); // Shallow clone it. | 
													
												
													
														|  |  | // console.dir(env) |  |  | // console.dir(env) | 
													
												
													
														|  |  | env.NODE_ENV = label || 'development'; |  |  |  | 
													
												
													
														|  |  |  |  |  | env.NODE_ENV = process.env.NODE_ENV || 'development'; | 
													
												
													
														|  |  | env.DEBUG = 'loopback:connector:' + dbForLabel(label) |  |  | env.DEBUG = 'loopback:connector:' + dbForLabel(label) | 
													
												
													
														|  |  | var cmd = env.NODE_ENV === 'development' ? 'nodemon' : 'node'; |  |  | var cmd = env.NODE_ENV === 'development' ? 'nodemon' : 'node'; | 
													
												
													
														|  |  | // cmd = 'node' |  |  | // cmd = 'node' | 
													
												
											
												
													
														|  |  |  |  |  |  | 
													
												
													
														|  |  | ] |  |  | ] | 
													
												
													
														|  |  | ) |  |  | ) | 
													
												
													
														|  |  | } |  |  | } | 
													
												
													
														|  |  | any(tasks) |  |  |  | 
													
												
													
														|  |  |  |  |  | any(tasks).then(()=>{ | 
													
												
													
														|  |  |  |  |  | fs.writeFileSync('run.done', 'success') | 
													
												
													
														|  |  |  |  |  | }).catch(()=>{ | 
													
												
													
														|  |  |  |  |  | fs.writeFileSync('run.done', 'error') | 
													
												
													
														|  |  |  |  |  | }) | 
													
												
													
														|  |  | 
 |  |  | 
 | 
													
												
													
														|  |  | // Antibiotic stewardship program. |  |  | // Antibiotic stewardship program. | 
													
												
													
														|  |  | // 1st use is fine. |  |  | // 1st use is fine. | 
													
												
											
												
													
														|  |  |  |  |  |  | 
													
												
													
														|  |  | g[processedArgs._[1]](); |  |  | g[processedArgs._[1]](); | 
													
												
													
														|  |  | } |  |  | } | 
													
												
													
														|  |  | } |  |  | } | 
													
												
													
														|  |  | return op[label] ? op[label]() : op['start'](label); |  |  |  | 
													
												
													
														|  |  |  |  |  | return op[label] ? op[label]() : null; | 
													
												
													
														|  |  | } |  |  | } | 
													
												
													
														|  |  | 
 |  |  | 
 | 
													
												
													
														|  |  | // mysqldump --add-drop-table --no-data -u root -p db_name | grep 'DROP TABLE' ) > drop_all_tables.sql |  |  | // mysqldump --add-drop-table --no-data -u root -p db_name | grep 'DROP TABLE' ) > drop_all_tables.sql | 
													
												
											
												
													
														|  |  |  |  |  |  | 
													
												
													
														|  |  | var mysql = '../xampp/mysql/bin/mysql' |  |  | var mysql = '../xampp/mysql/bin/mysql' | 
													
												
													
														|  |  | var mysqldump = '../xampp/mysql/bin/mysqldump' |  |  | var mysqldump = '../xampp/mysql/bin/mysqldump' | 
													
												
													
														|  |  | 
 |  |  | 
 | 
													
												
													
														|  |  | __runcmd(processedArgs.label || processedArgs._[0] || 'h'); |  |  |  | 
													
												
													
														|  |  | // nodeShellExec('git', ['status']); |  |  |  | 
													
												
													
														|  |  |  |  |  | // --runas | 
													
												
													
														|  |  |  |  |  | if(processedArgs.runas) { | 
													
												
													
														|  |  |  |  |  | // Weve been asked to run in priviledged mode. Check if we already are privileged. | 
													
												
													
														|  |  |  |  |  | __runcmd('runas') | 
													
												
													
														|  |  |  |  |  | } | 
													
												
													
														|  |  |  |  |  | else __runcmd(processedArgs.label || processedArgs._[0] || 'h'); | 
													
												
													
														|  |  | 
 |  |  | 
 | 
													
												
													
														|  |  | function nodeShellExec() { |  |  | function nodeShellExec() { | 
													
												
													
														|  |  | 
 |  |  | 
 | 
													
												
													
														|  |  | var args = Array.from(arguments); |  |  | var args = Array.from(arguments); | 
													
												
													
														|  |  | args[2] ? null : args[2] = {} |  |  |  | 
													
												
													
														|  |  | args[2].title ? null : args[2].title = `${args[0]} ${args[1]}` |  |  |  | 
													
												
													
														|  |  |  |  |  | var opts = args[2] = args[2] || {} | 
													
												
													
														|  |  |  |  |  | opts.title ? null : opts.title = `${args[0]} ${args[1]  }` | 
													
												
													
														|  |  | const child = spawn(...arguments); |  |  | const child = spawn(...arguments); | 
													
												
													
														|  |  | 
 |  |  | 
 | 
													
												
													
														|  |  | var p = new Promise(function(resolve, reject){ |  |  | var p = new Promise(function(resolve, reject){ | 
													
												
													
														|  |  | if(!args[2].detached) { |  |  |  | 
													
												
													
														|  |  |  |  |  | if(!opts.detached) { | 
													
												
													
														|  |  | var messages = []; // PB : TODO -- Explore stream for Task level  aggregation to prevent interleaved messages from multiple tasks... |  |  | var messages = []; // PB : TODO -- Explore stream for Task level  aggregation to prevent interleaved messages from multiple tasks... | 
													
												
													
														|  |  |  |  |  |  | 
													
												
													
														|  |  |  |  |  | var succes = true; | 
													
												
													
														|  |  | // use child.stdout.setEncoding('utf8'); if you want text chunks |  |  | // use child.stdout.setEncoding('utf8'); if you want text chunks | 
													
												
													
														|  |  | child.stdout.setEncoding('utf8'); |  |  | child.stdout.setEncoding('utf8'); | 
													
												
													
														|  |  | child.stderr.setEncoding('utf8'); |  |  | child.stderr.setEncoding('utf8'); | 
													
												
													
														|  |  | child.stdout.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/}); |  |  | child.stdout.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/}); | 
													
												
													
														|  |  | child.on('error', (chunk) => { messages.push(chunk); /*console.error(chunk)*/ }); |  |  |  | 
													
												
													
														|  |  |  |  |  | child.on('error', (chunk) => { succes = false; messages.push(chunk); /*console.error(chunk)*/ }); | 
													
												
													
														|  |  | child.stderr.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/}); |  |  | child.stderr.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/}); | 
													
												
													
														|  |  | // child.stderr.pipe(process.stderr); |  |  | // child.stderr.pipe(process.stderr); | 
													
												
													
														|  |  |  |  |  |  | 
													
												
													
														|  |  | child.on('close', (code) => { |  |  | child.on('close', (code) => { | 
													
												
													
														|  |  |  |  |  |  | 
													
												
													
														|  |  | console.log([` ${args[2].title} exited with code ${code}`]) |  |  |  | 
													
												
													
														|  |  | // console.log([ messages.join('') ]) |  |  |  | 
													
												
													
														|  |  | process.stdout.write( messages.join('') ) |  |  |  | 
													
												
													
														|  |  | if(code !== 0 ) return reject(code) |  |  |  | 
													
												
													
														|  |  |  |  |  | if(code !== 0) succes = false; | 
													
												
													
														|  |  |  |  |  | if(opts.runas){ | 
													
												
													
														|  |  |  |  |  | fs.writeFileSync('run.log', ', ' + JSON.stringify({ result: ` ${opts.title} exited with code ${code}`, messages : messages }), {'flag':'a+'} ) | 
													
												
													
														|  |  |  |  |  | } | 
													
												
													
														|  |  |  |  |  | else { | 
													
												
													
														|  |  |  |  |  | succes ? console.log(['success : ' + ` ${opts.title} exited with code ${code}`]) : console.error([`error : ${opts.title} exited with code ${code}`]) | 
													
												
													
														|  |  |  |  |  | // console.log( messages.join('') ) | 
													
												
													
														|  |  |  |  |  | process.stdout.write( messages.join('') ) | 
													
												
													
														|  |  |  |  |  | } | 
													
												
													
														|  |  |  |  |  | if(code !== 0) return reject(code) | 
													
												
													
														|  |  | resolve(true) |  |  | resolve(true) | 
													
												
													
														|  |  | }); |  |  | }); | 
													
												
													
														|  |  | } |  |  | } |