|
|
|
|
|
|
|
|
|| reconfirm[k]) |
|
|
|| reconfirm[k]) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var getBoundEachPrompt = function(target, mustPrompt, promptables, choices) { |
|
|
|
|
|
|
|
|
var getBoundEachPrompt = function(target, mustPrompt, promptables, choices, promptsfilter) { |
|
|
return function(prompts, k, i, a){ |
|
|
return function(prompts, k, i, a){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Confirm those that were not supplied as user choices in runtime args and proceed to reattempt. |
|
|
// Confirm those that were not supplied as user choices in runtime args and proceed to reattempt. |
|
|
// PB : TODO -- selectedinstance === __default check to prompt everything... |
|
|
// PB : TODO -- selectedinstance === __default check to prompt everything... |
|
|
if( shouldPrompt(k, mustPrompt, target) ) { |
|
|
if( shouldPrompt(k, mustPrompt, target) ) { |
|
|
|
|
|
delete reconfirm[k]; |
|
|
// console.log(k) |
|
|
// console.log(k) |
|
|
// console.dir(mustPrompt); //console.dir(target) |
|
|
// console.dir(mustPrompt); //console.dir(target) |
|
|
prompts.push(async ()=>{ |
|
|
prompts.push(async ()=>{ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var __interactive_prompts = function( target, choices ){ |
|
|
|
|
|
|
|
|
var __interactive_prompts = function( target, choices, promptsfilter ){ |
|
|
|
|
|
|
|
|
Object.defineProperty(target, 'node_env', { get : function(){ return this.instanceType } }); |
|
|
Object.defineProperty(target, 'node_env', { get : function(){ return this.instanceType } }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return __interpreter.call(target) |
|
|
return __interpreter.call(target) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
, instanceName : { label : `Enter Instance Name ( <= ${target.instanceName || 'chess'} ) : `, choices : [], defaultchoice : 'chess'} |
|
|
|
|
|
, instanceType : { label : `Enter Instance Type ( <= ${target.instanceType || 'development'} ) : `, choices : [], defaultchoice : 'development'} |
|
|
|
|
|
, reposerver : { label : `Enter Instance Name ( <= ${target.reposerver || 'https://git.bbh.org.in'} ) : `, choices : [], defaultchoice : 'https://git.bbh.org.in'} |
|
|
|
|
|
, username : { label : `Enter User Id for ${target.reposerver} ( <= ${target.username || 'chess'} ) : `, choices : [], defaultchoice : 'chess'} |
|
|
|
|
|
, password : { label : `Enter Password for ${target.username} @ ${target.reposerver} ( <= ${target.password || ''} ) : `, choices : [], defaultchoice : ''} |
|
|
|
|
|
|
|
|
, instanceName : { label : `Enter Instance Name ( <= ${target.instanceName || 'chess'} ) : ` |
|
|
|
|
|
, choices : choices['instanceName'], defaultchoice : 'chess'} |
|
|
|
|
|
, instanceType : { label : `Enter Instance Type ( <= ${target.instanceType || 'development'} ) : ` |
|
|
|
|
|
, choices : choices['instanceType'], defaultchoice : 'development'} |
|
|
|
|
|
, reposerver : { label : `Enter Instance Name ( <= ${target.reposerver || 'https://git.bbh.org.in'} ) : ` |
|
|
|
|
|
, choices : choices['reposerver'], defaultchoice : 'https://git.bbh.org.in'} |
|
|
|
|
|
, username : { label : `Enter User Id for ${target.reposerver} ( <= ${target.username || 'chess'} ) : ` |
|
|
|
|
|
, choices : choices['username'], defaultchoice : 'chess'} |
|
|
|
|
|
, password : { label : `Enter Password for ${target.username} @ ${target.reposerver} ( <= ${target.password || ''} ) : ` |
|
|
|
|
|
, choices : choices['password'], defaultchoice : '***'} |
|
|
|
|
|
, email : { label : `Enter Email for ${target.username} @ ${target.reposerver} ( <= ${target.email || ''} ) : ` |
|
|
|
|
|
, choices : choices['email'], defaultchoice : 'guest@bbh.org.in'} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return promptkeys |
|
|
return promptkeys |
|
|
} |
|
|
} |
|
|
var eachPrompt = getBoundEachPrompt( target, getPromptKeys() , interactionpoints, choices) |
|
|
|
|
|
return Object.keys(interactionpoints).reduce(eachPrompt, []) |
|
|
|
|
|
|
|
|
var eachPrompt = getBoundEachPrompt( target, getPromptKeys() , interactionpoints, choices, promptsfilter) |
|
|
|
|
|
return Object.keys(promptsfilter || interactionpoints).reduce(eachPrompt, []) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
] |
|
|
] |
|
|
var prompts = this.getuser(null, ()=>{ |
|
|
var prompts = this.getuser(null, ()=>{ |
|
|
console.log('preinstallsteps') |
|
|
|
|
|
var gitUser = 'guest'; |
|
|
|
|
|
var gitEmail = 'guest@bbh.org.in'; |
|
|
|
|
|
var prompts = []; |
|
|
|
|
|
prompts.push( ()=>{ return cli.prompt(choices['username'], 'git user name').then(gituser => gitUser = gituser) } ) |
|
|
|
|
|
prompts.push( ()=>{ return cli.prompt(choices['useremail'], 'git user email').then(gitemail => gitEmail = gitemail) } ) |
|
|
|
|
|
|
|
|
// console.log('preinstallsteps') |
|
|
|
|
|
// var gitUser = 'guest'; |
|
|
|
|
|
// var gitEmail = 'guest@bbh.org.in'; |
|
|
|
|
|
// var prompts = []; |
|
|
|
|
|
// prompts.push( ()=>{ return cli.prompt(choices['username'], 'git user name').then(gituser => gitUser = gituser) } ) |
|
|
|
|
|
// prompts.push( ()=>{ return cli.prompt(choices['useremail'], 'git user email').then(gitemail => gitEmail = gitemail) } ) |
|
|
|
|
|
|
|
|
console.log('prompting in preinstallsteps') |
|
|
|
|
|
return any(prompts).then(()=>{ |
|
|
|
|
|
var steps = [ |
|
|
|
|
|
['git', ['config', '--global', '--add', 'user.name', `${gitUser}`]] |
|
|
|
|
|
, ['git', ['config', '--global', '--add', 'user.email', `${gitEmail}`]] |
|
|
|
|
|
] |
|
|
|
|
|
return any(steps.map(getshelltask)).then(() => { |
|
|
|
|
|
|
|
|
// console.log('prompting in preinstallsteps') |
|
|
|
|
|
// return any(prompts).then(()=>{ |
|
|
|
|
|
// var steps = [ |
|
|
|
|
|
// ['git', ['config', '--global', '--add', 'user.name', `${gitUser}`]] |
|
|
|
|
|
// , ['git', ['config', '--global', '--add', 'user.email', `${gitEmail}`]] |
|
|
|
|
|
// ] |
|
|
|
|
|
// return any(steps.map(getshelltask)).then(() => { |
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
// }) |
|
|
|
|
|
// }); |
|
|
|
|
|
|
|
|
|
|
|
return Promise.resolve(true) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
return any([any(steps), prompts]) |
|
|
return any([any(steps), prompts]) |
|
|
|
|
|
|
|
|
// ignore err and proceed with data as guest. |
|
|
// ignore err and proceed with data as guest. |
|
|
console.dir(data) |
|
|
console.dir(data) |
|
|
if(data && data.length === 1 && !shouldPrompt('username', promptkeys, selectedinstance) ) { |
|
|
if(data && data.length === 1 && !shouldPrompt('username', promptkeys, selectedinstance) ) { |
|
|
return gitUser = data[0]; |
|
|
|
|
|
|
|
|
return username = data[0]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
data = data || ['guest'] |
|
|
data = data || ['guest'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('prompting in postinstallsteps') |
|
|
console.log('prompting in postinstallsteps') |
|
|
|
|
|
|
|
|
var gitUser = 'guest'; |
|
|
|
|
|
var gitEmail = 'guest@bbh.org.in'; |
|
|
|
|
|
var prompts = []; |
|
|
|
|
|
prompts.push( ()=>{ return cli.prompt(choices['username'], 'git user name').then(gituser => gitUser = gituser) } ) |
|
|
|
|
|
prompts.push( ()=>{ return cli.prompt(choices['useremail'], 'git user email').then(gitemail => gitEmail = gitemail) } ) |
|
|
|
|
|
|
|
|
|
|
|
return any(prompts).then(()=>{ |
|
|
|
|
|
var steps = [ |
|
|
|
|
|
['git', ['config', '--global', '--add', 'user.name', `${gitUser}`]] |
|
|
|
|
|
, ['git', ['config', '--global', '--add', 'user.email', `${gitEmail}`]] |
|
|
|
|
|
] |
|
|
|
|
|
return any(steps.map(getshelltask)).then(() => { |
|
|
|
|
|
|
|
|
var username = 'guest'; |
|
|
|
|
|
var email = 'guest@bbh.org.in'; |
|
|
|
|
|
var password = '***'; |
|
|
|
|
|
|
|
|
|
|
|
return any( getInteractionPoints(selectedinstance, promptkeys, { username, password, email}) ).then(()=>{ |
|
|
|
|
|
if(!data.find(e => e === selectedinstance.username)) { |
|
|
|
|
|
var steps = [ |
|
|
|
|
|
['git', ['config', '--global', '--add', 'user.name', `${username}`]] |
|
|
|
|
|
, ['git', ['config', '--global', '--add', 'user.email', `${email}`]] |
|
|
|
|
|
] |
|
|
|
|
|
return any(steps.map(getshelltask)).then(() => { |
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
return Promise.resolve(true) |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
else { |
|
|
else { |
|
|
var users = result.messages[0].trim().split('\n'); |
|
|
var users = result.messages[0].trim().split('\n'); |
|
|
if(users.length === 0 || |
|
|
if(users.length === 0 || |
|
|
users.length === 1 && users[0] === defaults) { |
|
|
|
|
|
|
|
|
users.length === 1 && users[0] === 'guest') { |
|
|
|
|
|
|
|
|
return __onResult(result) |
|
|
return __onResult(result) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
, username : ['guest', 'chessdemo', 'demo'] |
|
|
, username : ['guest', 'chessdemo', 'demo'] |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var getInteractionPoints = function(detectedinstanceoptions, promptkeys){ |
|
|
|
|
|
|
|
|
var getInteractionPoints = function(detectedinstanceoptions, promptkeys, promptsfilter){ |
|
|
|
|
|
|
|
|
var instances = [] |
|
|
var instances = [] |
|
|
var reposervers = []; |
|
|
var reposervers = []; |
|
|
|
|
|
|
|
|
choices['reposerver'] = Array.from( new Set(reposervers.concat(choices['reposerver'])) ) |
|
|
choices['reposerver'] = Array.from( new Set(reposervers.concat(choices['reposerver'])) ) |
|
|
choices['instanceType'] = Array.from( new Set(instanceTypes.concat(choices['instanceType'])) ) |
|
|
choices['instanceType'] = Array.from( new Set(instanceTypes.concat(choices['instanceType'])) ) |
|
|
|
|
|
|
|
|
return __interactive_prompts(selectedinstance, choices) |
|
|
|
|
|
|
|
|
return __interactive_prompts(selectedinstance, choices, promptsfilter) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var detection_state = { |
|
|
var detection_state = { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var acquirer = getHTTP_S(options) |
|
|
var acquirer = getHTTP_S(options) |
|
|
const req = acquirer.request(options, res => { |
|
|
const req = acquirer.request(options, res => { |
|
|
|
|
|
|
|
|
// console.dir(res) |
|
|
|
|
|
console.log(`statusCode: ${res.statusCode}`) |
|
|
|
|
|
res.setEncoding('utf8'); |
|
|
|
|
|
|
|
|
|
|
|
res.on('data', d => { |
|
|
|
|
|
// var jsonObject = JSON.parse(d); |
|
|
|
|
|
process.stdout.write(d) |
|
|
|
|
|
resolve(d) |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
if (res.statusCode < 200 || res.statusCode >= 300) { |
|
|
|
|
|
return reject(new Error('statusCode=' + res.statusCode)); |
|
|
|
|
|
} |
|
|
|
|
|
var body = []; |
|
|
|
|
|
res.on('data', function(chunk) { |
|
|
|
|
|
body.push(chunk); |
|
|
|
|
|
}); |
|
|
|
|
|
res.on('end', function() { |
|
|
|
|
|
try { |
|
|
|
|
|
body = JSON.parse(Buffer.concat(body).toString()); |
|
|
|
|
|
} catch(e) { |
|
|
|
|
|
reject(e); |
|
|
|
|
|
} |
|
|
|
|
|
resolve(body); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
req.on('error', error => { |
|
|
req.on('error', error => { |
|
|
console.error(error) |
|
|
console.error(error) |
|
|
|
|
|
|
|
|
delete _options.username |
|
|
delete _options.username |
|
|
delete _options.password |
|
|
delete _options.password |
|
|
HTTPAPI.post( _options, postoptions, function(tokenresp){ |
|
|
HTTPAPI.post( _options, postoptions, function(tokenresp){ |
|
|
tokenresp = JSON.parse(tokenresp) |
|
|
|
|
|
|
|
|
// tokenresp = JSON.parse(tokenresp) |
|
|
usertokens[options.username] = tokenresp.sha1 |
|
|
usertokens[options.username] = tokenresp.sha1 |
|
|
resolve(tokenresp) |
|
|
resolve(tokenresp) |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
// } |
|
|
// } |
|
|
// } |
|
|
// } |
|
|
|
|
|
|
|
|
var acquirer = getHTTP_S(options) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var acquirer = getHTTP_S(options) |
|
|
const req = acquirer.request(options, res => { |
|
|
const req = acquirer.request(options, res => { |
|
|
console.log(`statusCode: ${res.statusCode}`) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (res.statusCode < 200 || res.statusCode >= 300) { |
|
|
|
|
|
return reject(new Error('statusCode=' + res.statusCode)); |
|
|
|
|
|
} |
|
|
|
|
|
var body = []; |
|
|
res.setEncoding('utf8'); |
|
|
res.setEncoding('utf8'); |
|
|
res.on('data', d => { |
|
|
|
|
|
// var jsonObject = JSON.parse(d); |
|
|
|
|
|
process.stdout.write(d) |
|
|
|
|
|
resolve(d) |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
res.on('data', function(chunk) { |
|
|
|
|
|
body.push(chunk); |
|
|
|
|
|
}); |
|
|
|
|
|
res.on('end', function() { |
|
|
|
|
|
try { |
|
|
|
|
|
body = JSON.parse(Buffer.concat(body).toString()); |
|
|
|
|
|
} catch(e) { |
|
|
|
|
|
reject(e); |
|
|
|
|
|
} |
|
|
|
|
|
resolve(body); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
req.on('error', error => { |
|
|
req.on('error', error => { |
|
|
console.error(error) |
|
|
console.error(error) |
|
|
|
|
|
|
|
|
// http://try.gitea.io/api/v1/repos/{owner}/{repo}/forks |
|
|
// http://try.gitea.io/api/v1/repos/{owner}/{repo}/forks |
|
|
httpoptions.path = `/api/v1/repos/${cmdoptions.owner}/${cmdoptions.repo}/forks` |
|
|
httpoptions.path = `/api/v1/repos/${cmdoptions.owner}/${cmdoptions.repo}/forks` |
|
|
httpoptions.method = 'POST' |
|
|
httpoptions.method = 'POST' |
|
|
HTTPAPI.post(httpoptions, giteaoptions, resolve || function(){}, reject || function(){} ) |
|
|
|
|
|
|
|
|
return HTTPAPI.post(httpoptions, giteaoptions, resolve || function(){}, reject || function(){} ) |
|
|
} |
|
|
} |
|
|
, updateattributes( httpoptions, cmdoptions, giteaoptions, resolve, reject ){ |
|
|
, updateattributes( httpoptions, cmdoptions, giteaoptions, resolve, reject ){ |
|
|
httpoptions.path = `/api/v1/repos/${cmdoptions.owner}/${cmdoptions.repo}` |
|
|
httpoptions.path = `/api/v1/repos/${cmdoptions.owner}/${cmdoptions.repo}` |
|
|
httpoptions.method = 'PATCH' |
|
|
httpoptions.method = 'PATCH' |
|
|
HTTPAPI.post(httpoptions, giteaoptions, resolve || function(){}, reject || function(){} ) |
|
|
|
|
|
|
|
|
return HTTPAPI.post(httpoptions, giteaoptions, resolve || function(){}, reject || function(){} ) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// http://try.gitea.io/api/v1/org/{org}/repos |
|
|
// http://try.gitea.io/api/v1/org/{org}/repos |
|
|
console.dir(selectedinstance) |
|
|
console.dir(selectedinstance) |
|
|
var server = new URL(selectedinstance.reposerver); |
|
|
var server = new URL(selectedinstance.reposerver); |
|
|
// GITEA.repository.fork( { hostname : server.host, protocol : server.protocol |
|
|
|
|
|
// , username : selectedinstance.username, password : selectedinstance.password |
|
|
|
|
|
// } |
|
|
|
|
|
// // , { repo : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}`} |
|
|
|
|
|
// , { repo : `chess-config`, owner : 'chess' }, function( repository ){ |
|
|
|
|
|
// GITEA.repository.updateattributes( { |
|
|
|
|
|
// hostname : server.host, protocol : server.protocol |
|
|
|
|
|
// , username : selectedinstance.username, password : selectedinstance.password |
|
|
|
|
|
// } |
|
|
|
|
|
// , { repo : `chess-config`, owner : 'selectedinstance.username' } |
|
|
|
|
|
// , { name : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}${selectedinstance.nodeName ? '-' + selectedinstance.nodeName : ''}`} |
|
|
|
|
|
// ) |
|
|
|
|
|
// } |
|
|
|
|
|
// ) |
|
|
|
|
|
|
|
|
return GITEA.repository.fork( { hostname : server.host, protocol : server.protocol |
|
|
|
|
|
, username : selectedinstance.username, password : selectedinstance.password |
|
|
|
|
|
} |
|
|
|
|
|
// , { repo : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}`} |
|
|
|
|
|
, { repo : `chess-config`, owner : 'chess' }, {}, function( repository ){ |
|
|
|
|
|
return GITEA.repository.updateattributes( { |
|
|
|
|
|
hostname : server.host, protocol : server.protocol |
|
|
|
|
|
, username : selectedinstance.username, password : selectedinstance.password |
|
|
|
|
|
} |
|
|
|
|
|
, { repo : `chess-config`, owner : selectedinstance.username } |
|
|
|
|
|
, { name : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}${selectedinstance.nodeName ? '-' + selectedinstance.nodeName : ''}`} |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
GITEA.repository.updateattributes( { |
|
|
|
|
|
hostname : server.host, protocol : server.protocol |
|
|
|
|
|
, username : selectedinstance.username, password : selectedinstance.password |
|
|
|
|
|
} |
|
|
|
|
|
, { repo : `chess-config`, owner : selectedinstance.username } |
|
|
|
|
|
, { name : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}${selectedinstance.nodeName ? '-' + selectedinstance.nodeName : ''}`} |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return selectedinstance |
|
|
|
|
|
|
|
|
// GITEA.repository.updateattributes( { |
|
|
|
|
|
// hostname : server.host, protocol : server.protocol |
|
|
|
|
|
// , username : selectedinstance.username, password : selectedinstance.password |
|
|
|
|
|
// } |
|
|
|
|
|
// , { repo : `chess-config`, owner : selectedinstance.username } |
|
|
|
|
|
// , { name : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}${selectedinstance.nodeName ? '-' + selectedinstance.nodeName : ''}`} |
|
|
|
|
|
// ) |
|
|
|
|
|
|
|
|
|
|
|
// return selectedinstance |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
acquireElevationState().then(() => { |
|
|
acquireElevationState().then(() => { |