|
|
|
|
|
|
|
|
var cli = { |
|
|
var cli = { |
|
|
prompt : function(choices, label, defaultchoice){ |
|
|
prompt : function(choices, label, defaultchoice){ |
|
|
var options = []; |
|
|
var options = []; |
|
|
|
|
|
// console.dir(choices) |
|
|
choices.forEach = forEach |
|
|
choices.forEach = forEach |
|
|
choices.forEach(function(choice){ options.push( ((+choice) + 1) + ' ' + choices[choice] )}) |
|
|
|
|
|
return prompter.ask( label + ' \\n ' + options.join('\n') + '\n default ( <= ' + (defaultchoice || choices[0]) + ' ) : ' |
|
|
|
|
|
|
|
|
choices.forEach(function(choice, i, a){ |
|
|
|
|
|
// console.log(choice) |
|
|
|
|
|
// console.log('------------------------') |
|
|
|
|
|
// console.log( ((+i) + 1) + ' ' + choice ) |
|
|
|
|
|
options.push( ((+i) + 1) + ' ' + choice ) |
|
|
|
|
|
// console.log('------------------------') |
|
|
|
|
|
}) |
|
|
|
|
|
// console.log(options) |
|
|
|
|
|
return prompter.ask( label + '\n' + options.join('\n') + '\n default ( <= ' + (defaultchoice || choices[0]) + ' ) : ' |
|
|
).then( function(choice){ |
|
|
).then( function(choice){ |
|
|
if(!choice) return defaultchoice || choices[0]; |
|
|
if(!choice) return defaultchoice || choices[0]; |
|
|
if(choice && isNaN(+choice)) return choice; |
|
|
if(choice && isNaN(+choice)) return choice; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// __Promise = ovrrides |
|
|
// __Promise = ovrrides |
|
|
function forEach(eachFn){ |
|
|
|
|
|
for(var i=0; i<this.length; i++) eachFn(this[i]) |
|
|
|
|
|
|
|
|
// PB : TODO -- iterators are messed up in cscript without enumerables... |
|
|
|
|
|
function forEach(eachFn, o){ |
|
|
|
|
|
// console.dir(this) |
|
|
|
|
|
// console.log('------------------------------------') |
|
|
|
|
|
// console.log(''+ {}) |
|
|
|
|
|
// console.log('------------------------------------') |
|
|
|
|
|
if('' + this === '[object Object]') { |
|
|
|
|
|
// console.log('' + this) |
|
|
|
|
|
// console.dir(this) |
|
|
|
|
|
// var o = this |
|
|
|
|
|
// for(var i in o){ console.log(i + ' : ' + o[i])} |
|
|
|
|
|
for(var i in this){ |
|
|
|
|
|
if(i === 'forEach') continue; // Enumerable in cscript not supported ??? |
|
|
|
|
|
// console.log(i) |
|
|
|
|
|
eachFn(this[i], i, this) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
for(var i=0; i<this.length; i++) eachFn(this[i], i, this) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
function reduce(reducnFn, iv){ |
|
|
function reduce(reducnFn, iv){ |
|
|
var acc = iv |
|
|
var acc = iv |
|
|
|
|
|
|
|
|
var existsSync = function(filepath){ return fso.FileExists(filepath) } |
|
|
var existsSync = function(filepath){ return fso.FileExists(filepath) } |
|
|
var fs = { |
|
|
var fs = { |
|
|
writeFileSync : function(filepath, text) { |
|
|
writeFileSync : function(filepath, text) { |
|
|
|
|
|
// console.log('------------------writeFileSync----------------------') |
|
|
// console.log(filepath) |
|
|
// console.log(filepath) |
|
|
|
|
|
// console.log('------------------writeFileSync----------------------') |
|
|
|
|
|
|
|
|
var fh = fso.CreateTextFile(filepath, true); |
|
|
var fh = fso.CreateTextFile(filepath, true); |
|
|
fh.WriteLine(text); |
|
|
fh.WriteLine(text); |
|
|
fh.Close(); |
|
|
fh.Close(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function __main( selectedinstance ){ |
|
|
function __main( selectedinstance ){ |
|
|
var downloadsdir = selectedinstance.root + '/Downloads'; |
|
|
|
|
|
|
|
|
var downloadsdir = selectedinstance.root + '\\..\\Downloads'; |
|
|
|
|
|
|
|
|
var callsheltask = function(args) { |
|
|
var callsheltask = function(args) { |
|
|
// console.log('callsheltask : ' + args) |
|
|
// console.log('callsheltask : ' + args) |
|
|
return function() { return nodeShellExec.apply(null, args) } } |
|
|
return function() { return nodeShellExec.apply(null, args) } } |
|
|
|
|
|
|
|
|
|
|
|
var instanceName = 'elixir' |
|
|
|
|
|
var reposerver = 'https://git.bbh.org.in'; |
|
|
var gitUser = 'guest'; |
|
|
var gitUser = 'guest'; |
|
|
|
|
|
var gitpassword = 'guest'; |
|
|
var gitEmail = 'guest@bbh.org.in'; |
|
|
var gitEmail = 'guest@bbh.org.in'; |
|
|
|
|
|
var gitPreinstalled = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]'; |
|
|
var BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]'; |
|
|
function getVersion() { return BUILD_VERSION; } |
|
|
function getVersion() { return BUILD_VERSION; } |
|
|
|
|
|
|
|
|
var p = preq.exists().then(function(exists) { |
|
|
var p = preq.exists().then(function(exists) { |
|
|
if (exists && !preq.forceinstall) console.log( preq.shellcmd + ' exists'); |
|
|
if (exists && !preq.forceinstall) console.log( preq.shellcmd + ' exists'); |
|
|
else { |
|
|
else { |
|
|
console.log(exists) |
|
|
|
|
|
console.log(preq.shellcmd + ' is not installed'); |
|
|
|
|
|
|
|
|
console.log('----------------------------') |
|
|
|
|
|
console.log(exists) // PB : ??? Boolean true becomes -1 ??? |
|
|
|
|
|
console.log('----------------------------') |
|
|
|
|
|
if(!exists) console.log(preq.shellcmd + ' is not installed'); |
|
|
|
|
|
else console.log(preq.shellcmd + ' is installed but forceinstall was specifed so re-installing'); |
|
|
return preq.preinstallsteps().then(function(){ |
|
|
return preq.preinstallsteps().then(function(){ |
|
|
// console.log(' task.install : ' + preq.install) |
|
|
// console.log(' task.install : ' + preq.install) |
|
|
installtasks.push( function(){ return preq.install() } ); |
|
|
installtasks.push( function(){ return preq.install() } ); |
|
|
|
|
|
|
|
|
return getTaskCheckExists(self.shellcmd, { ignorefailures: true })().then(function(exists) { |
|
|
return getTaskCheckExists(self.shellcmd, { ignorefailures: true })().then(function(exists) { |
|
|
// console.log('-------------exists=======================') |
|
|
// console.log('-------------exists=======================') |
|
|
// console.dir(exists) |
|
|
// console.dir(exists) |
|
|
|
|
|
// console.log(self.shellcmd) |
|
|
|
|
|
// console.log(exists.messages.join(' ').indexOf(self.shellcmd)) |
|
|
// console.log(exists + ' ' + self.shellcmd + ' exists') |
|
|
// console.log(exists + ' ' + self.shellcmd + ' exists') |
|
|
if(exists && exists.messages.join(' ').indexOf(self.shellcmd) > -1 ) { |
|
|
|
|
|
|
|
|
if(exists && (exists.messages.join(' ').indexOf(self.shellcmd) > -1) ) { |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
else return false |
|
|
else return false |
|
|
|
|
|
|
|
|
// .catch( onEachError || function(e){ console.error(e) }) |
|
|
// .catch( onEachError || function(e){ console.error(e) }) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var createTasq = function(args, shellT, onEachError) { |
|
|
|
|
|
var tasq = shellT ? shellT(args) : ( function(){ |
|
|
|
|
|
return any([nodeShellExec.apply(null, args)]) |
|
|
|
|
|
// .catch( onEachError || function(e){ console.error(e) } ) |
|
|
|
|
|
}) |
|
|
|
|
|
tasq.toString = function(){ return JSON.stringify(args)} |
|
|
|
|
|
return tasq; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var execserial = function(tasklist, task, shellT, onEachError){ |
|
|
|
|
|
var exec = function(taskArgs){ |
|
|
|
|
|
console.log('executing ' + task) |
|
|
|
|
|
var thistask = task.concat(); |
|
|
|
|
|
thistask[1] = thistask[1].concat() |
|
|
|
|
|
thistask[1].push.apply(thistask[1], taskArgs) |
|
|
|
|
|
return createTasq(thistask, shellT) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
tasklist.map = map |
|
|
|
|
|
console.log('execlist ' + tasklist.map(exec)) |
|
|
|
|
|
return any(tasklist.map(exec)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function resetgitconfig(){ |
|
|
|
|
|
|
|
|
|
|
|
// https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage |
|
|
|
|
|
// Git Credential storage... |
|
|
|
|
|
// git config --global credential.helper 'store --file ~/.gitcredentials' |
|
|
|
|
|
// git credential-store --file ~/.gitcredentials store |
|
|
|
|
|
// // notepad C:/Program Files/Git/etc/gitconfig |
|
|
|
|
|
// git config --global --unset credential |
|
|
|
|
|
// git config --edit --system |
|
|
|
|
|
// git config --global credential.helper "store --file ~/gitcredentials" |
|
|
|
|
|
// git credential fill |
|
|
|
|
|
// git credential-store --file ~/git.store store |
|
|
|
|
|
|
|
|
|
|
|
// Find system git config |
|
|
|
|
|
// git config --global --edit |
|
|
|
|
|
// git config --list --show-origin |
|
|
|
|
|
// git config --list --show-origin --show-scope |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// https://stackoverflow.com/questions/35942754/how-can-i-save-username-and-password-in-git |
|
|
|
|
|
// Recipie |
|
|
|
|
|
// git config --global --unset credentials.helper |
|
|
|
|
|
// cd /path/to/my/repo |
|
|
|
|
|
// git config --unset credential.helper |
|
|
|
|
|
// git config --global credential.helper "store --file ~/.elxrcredentials" |
|
|
|
|
|
// git config credential.helper 'store --file ~/.elxrcredentials' |
|
|
|
|
|
//-- git config credential.*.username my_user_name |
|
|
|
|
|
//-- git config credential.https://gitlab.com.username my_user_name |
|
|
|
|
|
// git credential fill |
|
|
|
|
|
|
|
|
|
|
|
// git config --global credential.modalprompt false // doesnst work. |
|
|
|
|
|
// core askpass = ;;; https://stackoverflow.com/questions/37182847/how-do-i-disable-git-credential-manager-for-windows |
|
|
|
|
|
var options = { |
|
|
|
|
|
inherit: true, shell: true //, env: process.env |
|
|
|
|
|
, cwd: selectedinstance.root |
|
|
|
|
|
// , runas: processedArgs.runas |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var task = ['git', ['config'], options] |
|
|
|
|
|
|
|
|
|
|
|
var tasklist = [ |
|
|
|
|
|
// ['--global', '--unset credentials.helper'] |
|
|
|
|
|
// ['--unset', 'credentials.helper'] |
|
|
|
|
|
// , |
|
|
|
|
|
// ['credential.helper', `'store --file git_repo_credentials'`] |
|
|
|
|
|
['--global', 'credential.helper', '"store --file ~/.elxrcredentials"'] |
|
|
|
|
|
, ['--global', '--replace-all', 'user.name', gitUser] |
|
|
|
|
|
, ['--global', '--replace-all', 'user.email', gitEmail] |
|
|
|
|
|
|
|
|
|
|
|
// , ['--list'] |
|
|
|
|
|
// , ['credential', 'fill'] |
|
|
|
|
|
] |
|
|
|
|
|
console.log(tasklist) |
|
|
|
|
|
var onEachError = function(e) { console.error( e.messages.join('\n') + e.result + '\n' + util.inspect(e) + '\n') } |
|
|
|
|
|
var shellT = function(args) { |
|
|
|
|
|
return getgitshelltask(args, onEachError) |
|
|
|
|
|
// .catch(e => console.error( e.messages.join('\n') + e.result + '\n' + util.inspect(e) + '\n' + tasq.toString()) ) |
|
|
|
|
|
} |
|
|
|
|
|
return execserial(tasklist, task, shellT, onEachError ).then(function(){ |
|
|
|
|
|
// git credential-store --file ./.elxrcredentials store |
|
|
|
|
|
console.log('gathering git credentials') |
|
|
|
|
|
var userhome = '~' |
|
|
|
|
|
if(isWin()) userhome = '%userprofile%' |
|
|
|
|
|
var host = reposerver.replace('https://','').replace('http://','') |
|
|
|
|
|
var protocol = reposerver.replace('https://','') === host ? 'https' : 'http' |
|
|
|
|
|
fs.writeFileSync('ic.txt', 'host='+host+'\r\nprotocol='+protocol+'\r\nusername='+gitUser+'\r\npassword='+gitpassword) |
|
|
|
|
|
return nodeShellExec('git', ['credential-store', '--file', userhome + '/.elxrcredentials', 'store', '<', 'ic.txt'], options) |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var gitpostinstallsteps = function(){ |
|
|
|
|
|
|
|
|
|
|
|
// Load just in case someone was smart enough to fill in before install. |
|
|
|
|
|
var icf = fs.readFileSync( 'installchoices.js') |
|
|
|
|
|
icf = icf.replace('module.exports = ', 'icf = ') |
|
|
|
|
|
console.log(icf) |
|
|
|
|
|
try { |
|
|
|
|
|
icf = eval(icf) |
|
|
|
|
|
} |
|
|
|
|
|
catch(e) { |
|
|
|
|
|
console.error(e) |
|
|
|
|
|
} |
|
|
|
|
|
// console.log(icf.reposerver) |
|
|
|
|
|
instanceName = icf.instanceName |
|
|
|
|
|
reposerver = icf.reposerver; |
|
|
|
|
|
gitUser = icf.gitUser; |
|
|
|
|
|
gitEmail = icf.gitEmail |
|
|
|
|
|
// gitpassword = icf.??? ; we do not store password it should already be cached in the credential store. |
|
|
|
|
|
|
|
|
|
|
|
// PB : TODO -- Detect failure or cancellation before attenpting postinstall steps... |
|
|
|
|
|
var steps = []; |
|
|
|
|
|
steps.push( |
|
|
|
|
|
function(){ |
|
|
|
|
|
var choices = { 0 : 'elixir' } |
|
|
|
|
|
return cli.prompt(choices, 'instanceName', instanceName).then(function(choice){ instanceName = choice } ) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
steps.push( |
|
|
|
|
|
function(){ |
|
|
|
|
|
var choices = { 0 : 'https://git.bbh.org.in' } |
|
|
|
|
|
return cli.prompt(choices, 'reposerver', reposerver).then(function(choice){ reposerver = choice } ) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
steps.push( |
|
|
|
|
|
function(){ |
|
|
|
|
|
var choices = { 0 : 'guest', 1 : 'chessdemo' } |
|
|
|
|
|
return cli.prompt(choices, 'git user name', gitUser).then(function(choice){ gitUser = choice } ) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
steps.push( |
|
|
|
|
|
function(){ |
|
|
|
|
|
var choices = { } |
|
|
|
|
|
return cli.prompt(choices, 'git password', gitpassword).then(function(choice){ gitpassword = choice } ) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
steps.push( |
|
|
|
|
|
function(){ |
|
|
|
|
|
var choices = { 0 : 'guest@bbh.org.in', 1 : 'chessdemo@bbh.org.in' } |
|
|
|
|
|
return cli.prompt(choices, 'git user email', gitEmail).then(function(choice){ gitEmail = choice }) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return any(steps).then(function(){ |
|
|
|
|
|
// Save values to add credentials later in index.js... |
|
|
|
|
|
// console.log('module.exports = { instanceName : "'+ instanceName +'", reposerver: "'+reposerver+'", gitUser: "'+gitUser+'", gitEmail:"'+gitEmail+'" }') |
|
|
|
|
|
fs.writeFileSync( 'installchoices.js', 'module.exports = { instanceName : "'+ instanceName +'", reposerver: "'+reposerver+'", gitUser: "'+gitUser+'", gitEmail:"'+gitEmail+'" }' ) |
|
|
|
|
|
|
|
|
|
|
|
var steps = [ |
|
|
|
|
|
// ['git', ['config', '--global', '--add', 'user.name', gitUser]] |
|
|
|
|
|
// , ['git', ['config', '--global', '--add', 'user.email', gitEmail]] |
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
if(!steps.map) steps.map = map; |
|
|
|
|
|
return any(steps.map(callsheltask)).then(function(){ |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var prerequisites = [ |
|
|
var prerequisites = [ |
|
|
{ |
|
|
{ |
|
|
shellcmd: 'git', |
|
|
shellcmd: 'git', |
|
|
|
|
|
|
|
|
else throw e |
|
|
else throw e |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
, postinstallsteps: function(){ |
|
|
|
|
|
|
|
|
|
|
|
// PB : TODO -- Detect failure or cancellation before attenpting postinstall steps... |
|
|
|
|
|
var steps = []; |
|
|
|
|
|
steps.push( |
|
|
|
|
|
function(){ |
|
|
|
|
|
var choices = { 0 : 'guest', 1 : 'chessdemo' } |
|
|
|
|
|
return cli.prompt(choices, 'git user name', gitUser).then(function(choice){ gitUser = choice } ) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
steps.push( |
|
|
|
|
|
function(){ |
|
|
|
|
|
var choices = { 0 : 'guest@bbh.org.in', 1 : 'chessdemo@bbh.org.in' } |
|
|
|
|
|
return cli.prompt(choices, 'git user email', gitEmail).then(function(choice){ gitEmail = choice }) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return any(steps).then(function(){ |
|
|
|
|
|
var steps = [ |
|
|
|
|
|
['git', ['config', '--global', '--add', 'user.name', gitUser]] |
|
|
|
|
|
, ['git', ['config', '--global', '--add', 'user.email', gitEmail]] |
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
if(!steps.map) steps.map = map; |
|
|
|
|
|
return any(steps.map(callsheltask)).then(function(){ |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
, postinstallsteps: gitpostinstallsteps |
|
|
, install: function () { |
|
|
, install: function () { |
|
|
|
|
|
gitPreinstalled = false; |
|
|
var self = this; |
|
|
var self = this; |
|
|
console.log('Git Install called') |
|
|
console.log('Git Install called') |
|
|
|
|
|
|
|
|
var createTasq = function(args, shellT, onEachError) { |
|
|
|
|
|
var tasq = shellT ? shellT(args) : ( function(){ |
|
|
|
|
|
console.log('sdsfdsdf ' + args) |
|
|
|
|
|
return any([nodeShellExec.apply(null, args)]) |
|
|
|
|
|
// .catch( onEachError || function(e){ console.error(e) } ) |
|
|
|
|
|
}) |
|
|
|
|
|
tasq.toString = function(){ return JSON.stringify(args)} |
|
|
|
|
|
return tasq; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var execserial = function(tasklist, task, shellT, onEachError){ |
|
|
|
|
|
var exec = function(taskArgs){ |
|
|
|
|
|
console.log('execcing ' + task) |
|
|
|
|
|
var thistask = task.concat(); |
|
|
|
|
|
thistask[1] = thistask[1].concat() |
|
|
|
|
|
thistask[1].push.apply(thistask[1], taskArgs) |
|
|
|
|
|
return createTasq(thistask, shellT) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
tasklist.map = map |
|
|
|
|
|
console.log('execlist ' + tasklist.map(exec)) |
|
|
|
|
|
return any(tasklist.map(exec)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function resetgitconfig(){ |
|
|
|
|
|
|
|
|
|
|
|
// https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage |
|
|
|
|
|
// Git Credential storage... |
|
|
|
|
|
// git config --global credential.helper 'store --file ~/.gitcredentials' |
|
|
|
|
|
// git credential-store --file ~/.gitcredentials store |
|
|
|
|
|
// // notepad C:/Program Files/Git/etc/gitconfig |
|
|
|
|
|
// git config --global --unset credential |
|
|
|
|
|
// git config --edit --system |
|
|
|
|
|
// git config --global credential.helper "store --file ~/gitcredentials" |
|
|
|
|
|
// git credential fill |
|
|
|
|
|
// git credential-store --file ~/git.store store |
|
|
|
|
|
|
|
|
|
|
|
// Find system git config |
|
|
|
|
|
// git config --global --edit |
|
|
|
|
|
// git config --list --show-origin |
|
|
|
|
|
// git config --list --show-origin --show-scope |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// https://stackoverflow.com/questions/35942754/how-can-i-save-username-and-password-in-git |
|
|
|
|
|
// Recipie |
|
|
|
|
|
// git config --global --unset credentials.helper |
|
|
|
|
|
// cd /path/to/my/repo |
|
|
|
|
|
// git config --unset credential.helper |
|
|
|
|
|
// git config credential.helper 'store --file ~/.git_repo_credentials' |
|
|
|
|
|
// git config credential.*.username my_user_name |
|
|
|
|
|
// git config credential.https://gitlab.com.username my_user_name |
|
|
|
|
|
|
|
|
|
|
|
// git credential fill |
|
|
|
|
|
// git config --global credential.modalprompt false // doesnst work. |
|
|
|
|
|
// core askpass = ;;; https://stackoverflow.com/questions/37182847/how-do-i-disable-git-credential-manager-for-windows |
|
|
|
|
|
var options = { |
|
|
|
|
|
inherit: true, shell: true //, env: process.env |
|
|
|
|
|
, cwd: selectedinstance.root |
|
|
|
|
|
// , runas: processedArgs.runas |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var task = ['git', ['config'], options] |
|
|
|
|
|
|
|
|
|
|
|
var tasklist = [ |
|
|
|
|
|
// ['--global', '--unset credentials.helper'] |
|
|
|
|
|
// ['--unset', 'credentials.helper'] |
|
|
|
|
|
// , |
|
|
|
|
|
// ['credential.helper', `'store --file git_repo_credentials'`] |
|
|
|
|
|
['--global', 'credential.helper', "'store --file ~/.git_repo_credentials'"] |
|
|
|
|
|
, ['--global', '--replace-all', 'user.name', 'pb'] |
|
|
|
|
|
, ['--global', '--replace-all', 'user.email', 'pradeep@bbh.org.in'] |
|
|
|
|
|
|
|
|
|
|
|
// , ['--list'] |
|
|
|
|
|
// , ['credential', 'fill'] |
|
|
|
|
|
] |
|
|
|
|
|
var onEachError = function(e) { console.error( e.messages.join('\n') + e.result + '\n' + util.inspect(e) + '\n') } |
|
|
|
|
|
var shellT = function(args) { |
|
|
|
|
|
return getgitshelltask(args, onEachError) |
|
|
|
|
|
// .catch(e => console.error( e.messages.join('\n') + e.result + '\n' + util.inspect(e) + '\n' + tasq.toString()) ) |
|
|
|
|
|
} |
|
|
|
|
|
execserial(tasklist, task, shellT, onEachError ) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return any([ /*self.preinstallsteps,*/ |
|
|
return any([ /*self.preinstallsteps,*/ |
|
|
function(){ return self.installsteps() } |
|
|
function(){ return self.installsteps() } |
|
|
, function() { resetgitconfig() } |
|
|
|
|
|
|
|
|
, function() { return resetgitconfig() } |
|
|
, function(){ return self.postinstallsteps() } |
|
|
, function(){ return self.postinstallsteps() } |
|
|
]) |
|
|
]) |
|
|
} |
|
|
} |
|
|
, verifyAndInstall : function(){ |
|
|
|
|
|
var self = this; |
|
|
|
|
|
return self.exists().then( function(exits) { |
|
|
|
|
|
if(exists) return self.getUser(null, function(){ return self.postinstallsteps() } ) |
|
|
|
|
|
else return self.install(); |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// , verifyAndInstall : function(){ |
|
|
|
|
|
// var self = this; |
|
|
|
|
|
// return self.exists().then( function(exits) { |
|
|
|
|
|
// if(exists) return self.getUser(null, function(){ return self.postinstallsteps() } ) |
|
|
|
|
|
// else return self.install(); |
|
|
|
|
|
// }) |
|
|
|
|
|
// } |
|
|
, exists : exists |
|
|
, exists : exists |
|
|
, getUser : function(repo, onNoResult){ |
|
|
, getUser : function(repo, onNoResult){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
, postinstallsteps : function() { return sysAddPathVar('%USERPROFILE%\\AppData/Local\\Microsoft\\WindowsApps') } |
|
|
, postinstallsteps : function() { return sysAddPathVar('%USERPROFILE%\\AppData/Local\\Microsoft\\WindowsApps') } |
|
|
, exists : exists |
|
|
, exists : exists |
|
|
} |
|
|
} |
|
|
, { |
|
|
|
|
|
shellcmd: 'sqlexpress', |
|
|
|
|
|
url: 'https://go.microsoft.com/fwlink/?linkid=866658' |
|
|
|
|
|
, installer: 'SQL2019-SSEI-Expr.exe' |
|
|
|
|
|
|
|
|
, { |
|
|
|
|
|
// C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe |
|
|
|
|
|
// SQL Management studio 2018 |
|
|
|
|
|
shellcmd: 'Ssms.exe', |
|
|
|
|
|
url: 'https://aka.ms/ssmsfullsetup' |
|
|
|
|
|
, installer: 'SSMS-Setup-ENU.exe' |
|
|
, installcmd: ['cmd', ['/c', 'start', |
|
|
, installcmd: ['cmd', ['/c', 'start', |
|
|
'/WAIT', downloadsdir + '/' + 'SQL2019-SSEI-Expr.exe' |
|
|
|
|
|
, '' |
|
|
|
|
|
|
|
|
'/WAIT', downloadsdir + '/' + 'SSMS-Setup-ENU.exe' |
|
|
|
|
|
, '/IAcceptSQLServerLicenseTerms' |
|
|
//, 'SSMSInstallRoot=%systemdrive%\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio' |
|
|
//, 'SSMSInstallRoot=%systemdrive%\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio' |
|
|
]] |
|
|
]] |
|
|
, install : install |
|
|
, install : install |
|
|
, exists : exists |
|
|
|
|
|
|
|
|
, exists : function(){ |
|
|
|
|
|
var self = this; |
|
|
|
|
|
var installedpath = 'C:\\Program Files (x86)\\Microsoft SQL Server Management Studio 18\\Common7\\IDE\\Ssms.exe' |
|
|
|
|
|
console.log('checking existence of ' + installedpath) |
|
|
|
|
|
return Promise.resolve(existsSync(installedpath)) |
|
|
|
|
|
} |
|
|
, preinstallsteps: function() { |
|
|
, preinstallsteps: function() { |
|
|
var self = this; |
|
|
var self = this; |
|
|
console.log('Node preinstall steps') |
|
|
|
|
|
|
|
|
console.log('smss 2018 preinstall steps') |
|
|
|
|
|
|
|
|
var steps = []; |
|
|
var steps = []; |
|
|
steps.push( |
|
|
steps.push( |
|
|
function(){ |
|
|
function(){ |
|
|
if (!existsSync(downloadsdir + '/' + self.installer)) { |
|
|
if (!existsSync(downloadsdir + '/' + self.installer)) { |
|
|
|
|
|
console.log(self.url) |
|
|
return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', ['"' + self.url + '"', downloadsdir + '/' + self.installer] |
|
|
return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', ['"' + self.url + '"', downloadsdir + '/' + self.installer] |
|
|
, { waitmsg : 'downloading '+ self.shellcmd +' please wait' }) |
|
|
, { waitmsg : 'downloading '+ self.shellcmd +' please wait' }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
, { |
|
|
, { |
|
|
// "C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe" |
|
|
|
|
|
// SQL Management studio 2018 |
|
|
|
|
|
shellcmd: 'C:\\Program Files (x86)\\Microsoft SQL Server Management Studio 18\\Common7\\IDE\\Ssms.exe\\Ssms.exe', |
|
|
|
|
|
url: 'https://aka.ms/ssmsfullsetup' |
|
|
|
|
|
, installer: 'SSMS-Setup-ENU.exe' |
|
|
|
|
|
|
|
|
// C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Ssms.exe |
|
|
|
|
|
shellcmd: 'Ssms.exe', // SQL Mgmt Studo 2017 |
|
|
|
|
|
url: 'https://go.microsoft.com/fwlink/?linkid=2043154&clcid=0x409' |
|
|
|
|
|
, installer: 'SSMS-Setup-ENU-2017.exe' |
|
|
, installcmd: ['cmd', ['/c', 'start', |
|
|
, installcmd: ['cmd', ['/c', 'start', |
|
|
'/WAIT', downloadsdir + '/' + 'SSMS-Setup-ENU.exe' |
|
|
|
|
|
|
|
|
'/WAIT', downloadsdir + '/' + 'SSMS-Setup-ENU-2017.exe' |
|
|
, '/IAcceptSQLServerLicenseTerms' |
|
|
, '/IAcceptSQLServerLicenseTerms' |
|
|
//, 'SSMSInstallRoot=%systemdrive%\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio' |
|
|
//, 'SSMSInstallRoot=%systemdrive%\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio' |
|
|
]] |
|
|
]] |
|
|
, install : install |
|
|
, install : install |
|
|
, exists : exists |
|
|
|
|
|
|
|
|
, exists : function(){ |
|
|
|
|
|
return Promise.resolve(false) |
|
|
|
|
|
var self = this; |
|
|
|
|
|
// var installedpath = 'C:\\Program Files (x86)\\Microsoft SQL Server Management Studio 18\\Common7\\IDE\\Ssms.exe' |
|
|
|
|
|
var installedpath = 'C:\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio\\Ssms.exe' |
|
|
|
|
|
console.log('checking existence of ' + installedpath) |
|
|
|
|
|
return Promise.resolve(existsSync(installedpath)) |
|
|
|
|
|
} |
|
|
, preinstallsteps: function() { |
|
|
, preinstallsteps: function() { |
|
|
var self = this; |
|
|
var self = this; |
|
|
console.log('smss preinstall steps') |
|
|
console.log('smss preinstall steps') |
|
|
|
|
|
|
|
|
// return any([any(steps), any(prompts)]) |
|
|
// return any([any(steps), any(prompts)]) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
, { |
|
|
|
|
|
shellcmd: 'Ssms.exe', // SQL Mgmt Studo 2017 |
|
|
|
|
|
url: 'https://go.microsoft.com/fwlink/?linkid=2043154&clcid=0x409' |
|
|
|
|
|
, installer: 'SSMS-Setup-ENU-2017.exe' |
|
|
|
|
|
|
|
|
, { |
|
|
|
|
|
shellcmd: 'sqlservr.exe', |
|
|
|
|
|
url: 'https://go.microsoft.com/fwlink/?linkid=866658' |
|
|
|
|
|
, installer: 'SQL2019-SSEI-Expr.exe' |
|
|
, installcmd: ['cmd', ['/c', 'start', |
|
|
, installcmd: ['cmd', ['/c', 'start', |
|
|
'/WAIT', downloadsdir + '/' + 'SSMS-Setup-ENU.exe' |
|
|
|
|
|
, '/Quiet' |
|
|
|
|
|
|
|
|
'/WAIT', downloadsdir + '/' + 'SQL2019-SSEI-Expr.exe' |
|
|
|
|
|
, '' |
|
|
//, 'SSMSInstallRoot=%systemdrive%\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio' |
|
|
//, 'SSMSInstallRoot=%systemdrive%\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio' |
|
|
]] |
|
|
]] |
|
|
, install : install |
|
|
, install : install |
|
|
, exists : exists |
|
|
|
|
|
|
|
|
, exists : function(){ |
|
|
|
|
|
var self = this; |
|
|
|
|
|
var installedpath = 'C:\\Program Files\\Microsoft SQL Server\\MSSQL15.SQLEXPRESS\\MSSQL\\Binn\\sqlservr.exe' |
|
|
|
|
|
console.log('checking existence of ' + installedpath) |
|
|
|
|
|
return Promise.resolve(existsSync(installedpath)) |
|
|
|
|
|
} |
|
|
, preinstallsteps: function() { |
|
|
, preinstallsteps: function() { |
|
|
var self = this; |
|
|
var self = this; |
|
|
console.log('smss preinstall steps') |
|
|
|
|
|
|
|
|
console.log('sqlexpress preinstall steps') |
|
|
|
|
|
|
|
|
var steps = []; |
|
|
var steps = []; |
|
|
steps.push( |
|
|
steps.push( |
|
|
|
|
|
|
|
|
//, 'ACCEPT=YES', '/passive' |
|
|
//, 'ACCEPT=YES', '/passive' |
|
|
]] |
|
|
]] |
|
|
, install : install |
|
|
, install : install |
|
|
, exists : exists |
|
|
|
|
|
|
|
|
, exists : function(){ |
|
|
|
|
|
var self = this; |
|
|
|
|
|
var mysqldpath = 'C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqld.exe' |
|
|
|
|
|
console.log('checking existence of ' + mysqldpath) |
|
|
|
|
|
return Promise.resolve(existsSync(mysqldpath)) |
|
|
|
|
|
} |
|
|
, preinstallsteps: function() { |
|
|
, preinstallsteps: function() { |
|
|
var self = this; |
|
|
var self = this; |
|
|
console.log('mysql preinstall steps') |
|
|
console.log('mysql preinstall steps') |
|
|
|
|
|
|
|
|
// return any([any(steps), any(prompts)]) |
|
|
// return any([any(steps), any(prompts)]) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
, { |
|
|
|
|
|
|
|
|
, |
|
|
|
|
|
{ |
|
|
shellcmd: 'elxr' |
|
|
shellcmd: 'elxr' |
|
|
, forceinstall : true |
|
|
, forceinstall : true |
|
|
, installcmd: [ isWin() ? 'npm.cmd' : 'npm' , ['link'], { cwd : selectedinstance.root + '\\elxr' /* cwd should be the cloned dir*/}] |
|
|
, installcmd: [ isWin() ? 'npm.cmd' : 'npm' , ['link'], { cwd : selectedinstance.root + '\\elxr' /* cwd should be the cloned dir*/}] |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
, installsteps: function () { |
|
|
, installsteps: function () { |
|
|
var self = this; |
|
|
var self = this; |
|
|
console.log('Elxr Installsteps called') |
|
|
|
|
|
|
|
|
console.log('GIt config reconfirm called ' + gitPreinstalled) |
|
|
var installIfNotExists = function(){ |
|
|
var installIfNotExists = function(){ |
|
|
console.log('Elxr PreInstallsteps called') |
|
|
|
|
|
var steps = []; |
|
|
var steps = []; |
|
|
var chessRepo = 'https://git.bbh.org.in' |
|
|
|
|
|
steps.push( |
|
|
|
|
|
function(){ |
|
|
|
|
|
// console.log('cli prompt steps') |
|
|
|
|
|
var choices = { 0 : 'http://git.bbh', 1 : 'https://git.bbh.org.in' } |
|
|
|
|
|
return cli.prompt(choices, 'git repository : ', chessRepo).then(function(choice){ chessRepo = choice } ) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
return any(steps).then(function(){ |
|
|
|
|
|
var ifns = [ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
['git', ['clone', chessRepo + '/chess/elxr'] ] |
|
|
|
|
|
] |
|
|
|
|
|
if(existsSyncFolder( selectedinstance.root + '\\elxr')) { |
|
|
|
|
|
if(existsSyncFolder( selectedinstance.root + '\\elxr\\.git')) { |
|
|
|
|
|
// PB : TODO -- use a elxr guid signature to detect more reliably folders named the same that is not us. |
|
|
|
|
|
ifns = [ ['git', ['pull'], { cwd : selectedinstance.root + '\\elxr' } ] ] |
|
|
|
|
|
|
|
|
if(gitPreinstalled) { |
|
|
|
|
|
console.log('-------------------------------------') |
|
|
|
|
|
console.log('Git was already preinstalled - reconfirming installchoices') |
|
|
|
|
|
// Load from previous run and confirm. |
|
|
|
|
|
// var reposerver = 'https://git.bbh.org.in'; |
|
|
|
|
|
// var gitUser = 'guest'; |
|
|
|
|
|
// var gitEmail = 'guest@bbh.org.in'; |
|
|
|
|
|
var icf = fs.readFileSync( 'installchoices.js') |
|
|
|
|
|
icf = icf.replace('module.exports = ', 'icf = ') |
|
|
|
|
|
console.log(icf) |
|
|
|
|
|
try { |
|
|
|
|
|
icf = eval(icf) |
|
|
} |
|
|
} |
|
|
else { |
|
|
|
|
|
throw 'elxr subfolder not recognized as a git repository. Please cleanup and continue.' |
|
|
|
|
|
|
|
|
catch(e) { |
|
|
|
|
|
console.error(e) |
|
|
} |
|
|
} |
|
|
|
|
|
// console.log(icf.reposerver) |
|
|
|
|
|
instanceName = icf.instanceName |
|
|
|
|
|
reposerver = icf.reposerver; |
|
|
|
|
|
gitUser = icf.gitUser; |
|
|
|
|
|
gitEmail = icf.gitEmail |
|
|
|
|
|
|
|
|
|
|
|
console.log('-------------------------------------') |
|
|
|
|
|
console.dir(icf) |
|
|
|
|
|
// var p = gitpostinstallsteps() |
|
|
|
|
|
steps.push(gitpostinstallsteps) |
|
|
|
|
|
// steps.push( |
|
|
|
|
|
// function(){ |
|
|
|
|
|
// console.log('cli prompt steps') |
|
|
|
|
|
// var choices = { 0 : 'http://git.bbh', 1 : 'https://git.bbh.org.in' } |
|
|
|
|
|
// // console.dir(choices) |
|
|
|
|
|
// return cli.prompt(choices, 'git repository : ', reposerver).then(function(choice){ reposerver = choice } ) |
|
|
|
|
|
// } |
|
|
|
|
|
// ) |
|
|
} |
|
|
} |
|
|
else console.log(selectedinstance.root + '\\elxr' + ' NOT FOUND ') |
|
|
|
|
|
ifns.push(['npm', ['i'], { cwd : '.\\elxr' } ]) |
|
|
|
|
|
if(!ifns.map) ifns.map = map; |
|
|
|
|
|
return any(ifns.map(callsheltask))['catch'](function(e){ |
|
|
|
|
|
if(e.code === 1602) { |
|
|
|
|
|
console.warn("Installation was probably cancelled.") |
|
|
|
|
|
} |
|
|
|
|
|
else throw e |
|
|
|
|
|
|
|
|
else{ |
|
|
|
|
|
// var p = Promise.resolve(true) |
|
|
|
|
|
steps.push( |
|
|
|
|
|
function(){ |
|
|
|
|
|
var choices = { } |
|
|
|
|
|
return cli.prompt(choices, 'git password', gitpassword).then(function(choice){ gitpassword = choice } ) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// resetgitconfig requires the password to be loaded from credential store. Currently just prompt for it. |
|
|
|
|
|
return any(steps).then( function(){ |
|
|
|
|
|
return resetgitconfig().then(function(){ |
|
|
|
|
|
var ifns = [ |
|
|
|
|
|
['git', ['clone', reposerver + '/chess/elxr'] ] |
|
|
|
|
|
] |
|
|
|
|
|
if(existsSyncFolder( selectedinstance.root + '\\elxr')) { |
|
|
|
|
|
if(existsSyncFolder( selectedinstance.root + '\\elxr\\.git')) { |
|
|
|
|
|
// PB : TODO -- use a elxr guid signature to detect more reliably folders named the same that is not us. |
|
|
|
|
|
ifns = [ ['git', ['pull'], { cwd : selectedinstance.root + '\\elxr' } ] ] |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
throw 'elxr subfolder not recognized as a git repository. Please cleanup and continue.' |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else console.log(selectedinstance.root + '\\elxr' + ' NOT FOUND ') |
|
|
|
|
|
var pkgjson = selectedinstance.root + '\\elxr\\package.json' |
|
|
|
|
|
var pkgcontents = fs.readFileSync(pkgjson) |
|
|
|
|
|
// PB : TODO -- Remove hardcode use proper replacement url.. |
|
|
|
|
|
fs.writeFileSync( pkgjson, pkgcontents.replace(/http\:\/\/git\.bbh/g, reposerver)); |
|
|
|
|
|
|
|
|
|
|
|
ifns.push(['npm', ['i'], { cwd : '.\\elxr' } ]) |
|
|
|
|
|
if(!ifns.map) ifns.map = map; |
|
|
|
|
|
return any(ifns.map(callsheltask))['catch'](function(e){ |
|
|
|
|
|
if(e.code === 1602) { |
|
|
|
|
|
console.warn("Installation was probably cancelled.") |
|
|
|
|
|
} |
|
|
|
|
|
else throw e |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
} ) |
|
|
} |
|
|
} |
|
|
var ifns = [ self.installcmd ] |
|
|
var ifns = [ self.installcmd ] |
|
|
if(!ifns.map) ifns.map = map; |
|
|
if(!ifns.map) ifns.map = map; |
|
|
|
|
|
|
|
|
, install: function () { |
|
|
, install: function () { |
|
|
var self = this; |
|
|
var self = this; |
|
|
console.log('Elxr Install called') |
|
|
console.log('Elxr Install called') |
|
|
|
|
|
|
|
|
|
|
|
// PB : TODO -- detect external or internal and change elxr package.json dependencies to point to proper location. |
|
|
|
|
|
fs.writeFileSync(selectedinstance.root + '\\ei.bat', 'cmd /c node ' + selectedinstance.root + '\\elxr\\index.js i ' + instanceName) |
|
|
|
|
|
|
|
|
return any([ self.preinstallsteps, function(){ return self.installsteps() } |
|
|
return any([ self.preinstallsteps, function(){ return self.installsteps() } |
|
|
, nodeShellExec('start', ['""', '"C:\\Program Files\\Git\\bin\\sh.exe"', '-c', '"node ' + (selectedinstance.root + '\\elxr\\index.js').replace(/\\/g, '/') + ' i elixir"']) |
|
|
|
|
|
|
|
|
, nodeShellExec('start', ['/WAIT', '""', '"' + selectedinstance.root + '\\ei.bat' + '"']) |
|
|
|
|
|
// , nodeShellExec('start', ['/WAIT', '""', '"C:\\Program Files\\Git\\bin\\sh.exe"', '-c', '"node ' + (selectedinstance.root + '\\elxr\\index.js').replace(/\\/g, '/') + ' i elixir"']) |
|
|
// , nodeShellExec('node', [selectedinstance.root + 'elxr\\index.js']) |
|
|
// , nodeShellExec('node', [selectedinstance.root + 'elxr\\index.js']) |
|
|
]) |
|
|
]) |
|
|
// return any([ /*self.preinstallsteps,*/ function(){ return self.installsteps() } |
|
|
// return any([ /*self.preinstallsteps,*/ function(){ return self.installsteps() } |