|
|
|
|
|
|
|
|
var promise = new Promise((resolve, reject)=>{ |
|
|
var promise = new Promise((resolve, reject)=>{ |
|
|
existslink('config', function(err, data){ |
|
|
existslink('config', function(err, data){ |
|
|
if(data) { |
|
|
if(data) { |
|
|
var p = nodeShellExec('rmdir', ['config'], { inherit: true, shell: true, env: process.env } |
|
|
var p = nodeShellExec('rmdir', ['config'], { inherit: true, shell: true, env: process.env }) |
|
|
).catch((err) => { console.log('Ignoring benign error : ' + err); return true; }) |
|
|
.then(()=>{resolve(true)}) |
|
|
return resolve(p); |
|
|
.catch((err) => { console.log('Ignoring benign error : ' + err); return resolve(true); }) |
|
|
} |
|
|
} |
|
|
else resolve(false) |
|
|
else resolve(false) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
var promise = new Promise((resolve, reject)=>{ |
|
|
var promise = new Promise((resolve, reject)=>{ |
|
|
existslink('data', function(err, data){ |
|
|
existslink('data', function(err, data){ |
|
|
if(data) { |
|
|
if(data) { |
|
|
var p = nodeShellExec('rmdir', ['data'], { inherit: true, shell: true, env: process.env } |
|
|
var p = nodeShellExec('rmdir', ['data'], { inherit: true, shell: true, env: process.env }) |
|
|
).catch((err) => { console.log('Ignoring benign error : ' + err); return true; }) |
|
|
.then(()=>{resolve(true)}) |
|
|
return resolve(p); |
|
|
.catch((err) => { console.log('Ignoring benign error : ' + err); return resolve(true); }) |
|
|
} |
|
|
} |
|
|
else resolve(false) |
|
|
else resolve(false) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
tasks = tasks.concat( |
|
|
tasks = tasks.concat( |
|
|
[ |
|
|
[ |
|
|
() => { |
|
|
() => { |
|
|
var p = nodeShellExec('mklink', ['/J', 'data', runconfig.use + '-data'], { |
|
|
var p = nodeShellExec('mklink', ['/J', 'data', runconfig.use + '-data' + '-' + process.env.NODE_ENV], { |
|
|
inherit: true, shell: true |
|
|
inherit: true, shell: true |
|
|
, cwd : instanceroot |
|
|
, cwd : instanceroot |
|
|
, env: process.env |
|
|
, env: process.env |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var __acquireData = function (selected, owner, clusternodename, datarepo, errHandler) { |
|
|
var __acquireData = function (selected, owner, clusternodename, datarepo, errHandler) { |
|
|
|
|
|
|
|
|
datarepo = datarepo || selected.instanceName + '-config-' + selected.node_env; |
|
|
datarepo = datarepo || selected.instanceName + '-data-' + selected.node_env; |
|
|
|
|
|
|
|
|
var errorHandler = (e) => { |
|
|
var errorHandler = (e) => { |
|
|
if(e.messages.join(' ').match(new RegExp (`fatal: unable to access '${selectedinstance.reposerver}/${owner}/${datarepo}.git/': Failed to connect to .*? port .*? after .*? ms: Timed out`))){ |
|
|
if(e.messages.join(' ').match(new RegExp (`fatal: unable to access '${selectedinstance.reposerver}/${owner}/${datarepo}.git/': Failed to connect to .*? port .*? after .*? ms: Timed out`))){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(e.messages.join(' ').match(new RegExp (`fatal: repository '${selectedinstance.reposerver}/${owner}/${datarepo}.git/' not found`))){ |
|
|
if(e.messages.join(' ').match(new RegExp (`fatal: repository '${selectedinstance.reposerver}/${owner}/${datarepo}.git/' not found`))){ |
|
|
var choices = { |
|
|
var choices = { |
|
|
t : `install a new temporary local instance with this name ( will not persist ). |
|
|
t : `install a temporary local data folder. |
|
|
Use your own username for additional options. You can request for a username at chess@bbh.org.in )` |
|
|
For more options. Request and use a personal username at chess@bbh.org.in )` |
|
|
, e : 'exit' } |
|
|
, e : 'exit' } |
|
|
|
|
|
|
|
|
if(selectedinstance.username !== 'guest' && selectedinstance.username !== 'demo') { |
|
|
if(selectedinstance.username !== 'guest' && selectedinstance.username !== 'demo') { |
|
|
|
|
|
|
|
|
return GIT |
|
|
return GIT |
|
|
})(); |
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
function createInstanceData(target, source) { |
|
|
|
|
|
|
|
|
|
|
|
var sourceinstance = source || target; |
|
|
|
|
|
console.dir(sourceinstance) |
|
|
|
|
|
var args = { |
|
|
|
|
|
remotebase : sourceinstance.reposerver + '/chess/' |
|
|
|
|
|
, sourcerepo : sourceinstance.repo || 'chess-data' |
|
|
|
|
|
, targetrepo : `${target.instanceName}-data-${target.instanceType}${target.nodeName ? ('-' + target.nodeName) : ''}` |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(sourceinstance.local) { |
|
|
|
|
|
|
|
|
|
|
|
var options = { |
|
|
|
|
|
inherit: true, shell: true, |
|
|
|
|
|
env: process.env |
|
|
|
|
|
, cwd : instanceroot |
|
|
|
|
|
, runas: processedArgs.runas |
|
|
|
|
|
} |
|
|
|
|
|
var cmdseq = [ |
|
|
|
|
|
['git', ['clone', `${args.remotebase}${args.sourcerepo}`, `${args.targetrepo}`], options] |
|
|
|
|
|
] |
|
|
|
|
|
return any(cmdseq.map(getshelltask)).then(() => { return true }) |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
// http://try.gitea.io/api/v1/org/{org}/repos |
|
|
|
|
|
|
|
|
|
|
|
if(source.reposerver !== target.reposerver && source.username !== target.username) { |
|
|
|
|
|
throw 'createInstanceData is possible only within the same repository server.' |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var server = new URL(target.reposerver); |
|
|
|
|
|
return GITEA.repository.fork( { hostname : server.host, protocol : server.protocol |
|
|
|
|
|
, username : target.username, password : target.password |
|
|
|
|
|
} |
|
|
|
|
|
// , { repo : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}`} |
|
|
|
|
|
, { repo : `${args.sourcerepo}`, owner : `${target.username}` }, {}, function( repository ){ |
|
|
|
|
|
return GITEA.repository.updateattributes( { |
|
|
|
|
|
hostname : server.host, protocol : server.protocol |
|
|
|
|
|
, username : target.username, password : target.password |
|
|
|
|
|
} |
|
|
|
|
|
, { repo : `${args.sourcerepo}`, owner : `${target.username}` } |
|
|
|
|
|
, { name : `${args.targetrepo}`} |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 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 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function createInstance(target, source) { |
|
|
function createInstance(target, source) { |
|
|
|
|
|
|
|
|
var sourceinstance = source || target; |
|
|
var sourceinstance = source || target; |