| ); | ); | ||||
| } | } | ||||
| 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; | |||||
| }); | |||||
| } | |||||
| var cli = 'elxr'; | var cli = 'elxr'; | ||||
| }) | }) | ||||
| }) | }) | ||||
| } | } | ||||
| , 'runas' : ()=>{ | |||||
| return isRunningElevated().then( | |||||
| () => op[ processedArgs.label || processedArgs._[0] || 'h']() | |||||
| ) | |||||
| .catch(()=>{ | |||||
| console.log('Not Elevated'); | |||||
| console.log('Requesting Elevated Privileges') | |||||
| nodeShellExec('MSHTA', [`javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute('node', 'elxr ${processedArgs._[0]} ${processedArgs._[1]} ${processedArgs._[2]} --runas=true', '', 'runas', 1);close();`] | |||||
| , { | |||||
| // inherit : true | |||||
| // , shell: true | |||||
| env: process.env | |||||
| , title : `runas` | |||||
| } | |||||
| ); | |||||
| }) | |||||
| } | |||||
| , 'pull' : (label) => { | , 'pull' : (label) => { | ||||
| var env = Object.assign({}, process.env); // Shallow clone it. | var env = Object.assign({}, process.env); // Shallow clone it. | ||||
| // console.dir(env) | // console.dir(env) | ||||
| } | } | ||||
| } | } | ||||
| var isElevated; | |||||
| try { | |||||
| 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') | |||||
| var isElevated = true; | |||||
| console.dir(processedArgs._[1]) | |||||
| if(processedArgs._[1] === 'runas') elevatedRunasRepos.forEach(performPull); | |||||
| else gitRepos.forEach(performPull); | |||||
| }).catch(()=>{ | |||||
| console.log('Not Elevated'); | |||||
| gitRepos.forEach(performPull) | |||||
| console.log('Requesting Elevated Privileges') | |||||
| nodeShellExec('MSHTA', ["javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute('node', 'elxr pull runas', '', 'runas', 1);close();"] | |||||
| , { | |||||
| // inherit : true | |||||
| // , shell: true | |||||
| env: process.env | |||||
| , title : `runas` | |||||
| } | |||||
| ); | |||||
| }); | |||||
| // isElevated = true; | |||||
| } | |||||
| catch ( e ) { | |||||
| console.error(e) | |||||
| } | |||||
| if(!processedArgs.runas) gitRepos.forEach(performPull) | |||||
| return isRunningElevated().then( | |||||
| ()=> elevatedRunasRepos.forEach(performPull)) | |||||
| .catch( | |||||
| () => op['runas']() | |||||
| ) | |||||
| } | } | ||||
| , 'npmi' : ()=>{ | , 'npmi' : ()=>{ | ||||
| }) | }) | ||||
| } | } | ||||
| , 'use' : ()=>{ | , 'use' : ()=>{ | ||||
| try { | |||||
| var runconfig = require('./run.js') | |||||
| if(processedArgs._[1] && runconfig.use === processedArgs._[1]) { | |||||
| return; | |||||
| if(!processedArgs.runas){ | |||||
| try { | |||||
| var runconfig = require('./run.js') | |||||
| if(processedArgs._[1] && runconfig.use === processedArgs._[1]) { | |||||
| return; | |||||
| } | |||||
| else runconfig.use = processedArgs._[1]; | |||||
| fs.writeFileSync('./run.js', 'module.exports = ' + JSON.stringify(runconfig)) | |||||
| } | |||||
| catch(e) { | |||||
| runconfig = { use : processedArgs._[1] }; | |||||
| fs.writeFileSync('./run.js', 'module.exports = ' + JSON.stringify(runconfig)) | |||||
| } | } | ||||
| else runconfig.use = processedArgs._[1]; | |||||
| fs.writeFileSync('./run.js', 'module.exports = ' + JSON.stringify(runconfig)) | |||||
| op['runas']() | |||||
| } | } | ||||
| catch(e) { | |||||
| runconfig = { use : processedArgs._[1] }; | |||||
| fs.writeFileSync('./run.js', 'module.exports = ' + JSON.stringify(runconfig)) | |||||
| else { | |||||
| var runconfig = require('../run.js') | |||||
| console.log('runconfig.use : ' + runconfig.use) | |||||
| var tasks = [ | |||||
| ()=>{ | |||||
| var p = nodeShellExec('rm', ['config'], { | |||||
| inherit : true, shell: true | |||||
| , cwd : repo | |||||
| , env: process.env | |||||
| , title : `rm 'package-lock.json' for ${repo}` | |||||
| }).catch((e)=>{ console.error(e) }) | |||||
| return p; | |||||
| }, | |||||
| ()=>{ | |||||
| var p = nodeShellExec('rm', ['data'], { | |||||
| inherit : true, shell: true | |||||
| , cwd : repo | |||||
| , env: process.env | |||||
| , title : `rm 'package-lock.json' for ${repo}` | |||||
| }).catch((e)=>{ console.error(e) }) | |||||
| return p; | |||||
| }, | |||||
| ()=>{ | |||||
| var p = nodeShellExec('mklink', ['/D', 'data', runconfig.use + '-data'], { | |||||
| inherit : true, shell: true | |||||
| , env: process.env | |||||
| }).catch((e)=>{ console.error(e) }) | |||||
| return p; | |||||
| }, | |||||
| ()=>{ | |||||
| var p = nodeShellExec('mklink', ['/D', 'config', runconfig.use + '-config'], { | |||||
| inherit : true, shell: true | |||||
| , env: process.env | |||||
| }).catch((e)=>{ console.error(e) }) | |||||
| return p; | |||||
| } | |||||
| ] | |||||
| any(tasks) | |||||
| } | } | ||||
| var tasks = [ | |||||
| ()=>{ | |||||
| var p = nodeShellExec('mklink', ['/D', 'data', 'data-' + runconfig.use], { | |||||
| inherit : true, shell: true | |||||
| , env: process.env | |||||
| }).catch((e)=>{ console.error(e) }) | |||||
| return p; | |||||
| }, | |||||
| ()=>{ | |||||
| var p = nodeShellExec('mklink', ['/D', 'config', 'config-' + runconfig.use], { | |||||
| inherit : true, shell: true | |||||
| , env: process.env | |||||
| }).catch((e)=>{ console.error(e) }) | |||||
| return p; | |||||
| } | |||||
| ] | |||||
| any(tasks) | |||||
| // Antibiotic stewardship program. | // Antibiotic stewardship program. | ||||
| // 1st use is fine. | // 1st use is fine. |