Browse Source

linux upgrades

master
pb 5 days ago
parent
commit
c86783a8e9
8 changed files with 119 additions and 105 deletions
  1. 2
    25
      cliverse.js
  2. 0
    1
      elxr_linux.js
  3. 13
    0
      i.sqlexpress.sh
  4. 0
    1
      i.win.js
  5. 91
    71
      index.js
  6. 0
    1
      index_linux.js
  7. 9
    4
      lin_verse.js
  8. 4
    2
      win_verse.js

+ 2
- 25
cliverse.js View File



// cliverse.js // cliverse.js


const util = require('util')
const { spawn, spawnSync } = require('child_process'); const { spawn, spawnSync } = require('child_process');
const fs = require('fs') const fs = require('fs')


}); });
child.on('error', (chunk) => { success = false; messages.push(chunk); /* console.error('e: ' + chunk) */ child.on('error', (chunk) => { success = false; messages.push(chunk); /* console.error('e: ' + chunk) */
console.error('Error exit not handled.') console.error('Error exit not handled.')
console.error(util.inspect(chunk))
}); });
child.stderr.on('data', (chunk) => { child.stderr.on('data', (chunk) => {
if(messages.join('').indexOf('fatal: not a git repository') > -1) opts.haserrors = true; if(messages.join('').indexOf('fatal: not a git repository') > -1) opts.haserrors = true;
} }




function isWin(){ return /^win/.test(process.platform) }
try {

if(isWin()) {
var win_verse = require('./win_verse')
var shell_verse = win_verse;
}
else {
var lin_verse = require('./lin_verse')
var shell_verse = lin_verse;
}
}
catch(e) {
console.dir(e);
console.error('cli environment detection failed')
}

const BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]';
shell_verse.getVersion = function getVersion() { return BUILD_VERSION; }




console.log('----------------------') console.log('----------------------')
// console.dir(c) // console.dir(c)
console.log('----------------------') console.log('----------------------')
// process.exit() // process.exit()


const fs = require('fs')

var {nodeShellExec, createTask} = require('./nodeshell')

var prompt = function(choices, label, defaultchoice, selectedchoice){ var prompt = function(choices, label, defaultchoice, selectedchoice){
// prompt accepts either an array or an object as choices. // prompt accepts either an array or an object as choices.
var choices = choices || []; var choices = choices || [];

+ 0
- 1
elxr_linux.js View File

if (fs.existsSync(dirname)) { if (fs.existsSync(dirname)) {
return filePath; return filePath;
} }
ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname); fs.mkdirSync(dirname);
return filePath; return filePath;
} }

+ 13
- 0
i.sqlexpress.sh View File

sudo dpkg -i libldap-2.5-0_2.5.13+dfsg-5_amd64.deb sudo dpkg -i libldap-2.5-0_2.5.13+dfsg-5_amd64.deb
curl -O http://debian.mirror.ac.za/debian/pool/main/o/openldap/libldap-dev_2.5.13+dfsg-5_amd64.deb curl -O http://debian.mirror.ac.za/debian/pool/main/o/openldap/libldap-dev_2.5.13+dfsg-5_amd64.deb
sudo dpkg -i libldap-dev_2.5.13+dfsg-5_amd64.deb sudo dpkg -i libldap-dev_2.5.13+dfsg-5_amd64.deb
#First upgrade ubuntu to fix libc packaging issues.
#Then
sudo apt upgrade libsasl2-2
sudo apt --fix-broken install
sudo apt upgrade libldap-2.5-0
sudo apt --fix-broken install

sudo apt update
sudo apt install -y libldap-2.5-0
sudo apt install libldap-common




#curl -OL http://archive.ubuntu.com/ubuntu/pool/main/o/openldap/libldap-2.5-0_2.5.18+dfsg-0ubuntu0.22.04.1_amd64.deb #curl -OL http://archive.ubuntu.com/ubuntu/pool/main/o/openldap/libldap-2.5-0_2.5.18+dfsg-0ubuntu0.22.04.1_amd64.deb
#sudo apt-get install ./libldap-2.5-0_2.5.18+dfsg-0ubuntu0.22.04.1_amd64.deb #sudo apt-get install ./libldap-2.5-0_2.5.18+dfsg-0ubuntu0.22.04.1_amd64.deb


#sudo systemctl status mssql-server.service #sudo systemctl status mssql-server.service
sudo systemctl status mssql-server --no-pager sudo systemctl status mssql-server --no-pager
sudo ldd /opt/mssql/bin/sqlservr


curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt update && sudo apt install -y mssql-tools unixodbc-dev sudo apt update && sudo apt install -y mssql-tools unixodbc-dev

+ 0
- 1
i.win.js View File

if (existsSyncFolder(dirname)) { if (existsSyncFolder(dirname)) {
return filePath; return filePath;
} }
ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname); fs.mkdirSync(dirname);
return filePath; return filePath;
} }

+ 91
- 71
index.js View File

const processedArgs = cliargs(process.argv.slice(2)); const processedArgs = cliargs(process.argv.slice(2));


const __ALIAS__STAMP__ = '9e7bebe0-1f57-11ec-8f88-778ffeea9d1b' const __ALIAS__STAMP__ = '9e7bebe0-1f57-11ec-8f88-778ffeea9d1b'

// var shell_verse = cli.shell_verse;
// const getVersion = cli.shell_verse.getVersion


function isWin(){ return /^win/.test(process.platform) }
try {

if(isWin()) {
var win_verse = require('./win_verse')
var shell_verse = win_verse;
}
else {
var lin_verse = require('./lin_verse')
var shell_verse = lin_verse;
}
}
catch(e) {
console.dir(e);
console.error('cli environment detection failed')
}

const BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]'; const BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]';
shell_verse.getVersion = function getVersion() { return BUILD_VERSION; }



const runtimestamp = processedArgs.runtimestamp ? (new Date(processedArgs.runtimestamp)).getTime() : (new Date()).getTime(); const runtimestamp = processedArgs.runtimestamp ? (new Date(processedArgs.runtimestamp)).getTime() : (new Date()).getTime();
function getVersion() { return BUILD_VERSION; }


var defaultowner = 'chess'; var defaultowner = 'chess';


const { Console } = require('console'); const { Console } = require('console');
const { env } = require('process'); const { env } = require('process');
const { validate } = require('uuid'); const { validate } = require('uuid');
const PATTERNAPI = require('serververse').PATTERNAPI
const PATTERNAPI = utils.PATTERNAPI
// const RESTAPI = require('serververse').RESTAPI // const RESTAPI = require('serververse').RESTAPI
const RESTAPI = (function(){ const RESTAPI = (function(){


} }
}()); }());


function isWin(){ return /^win/.test(process.platform) }
if(isWin()) {
var win_verse = require('./win_verse')
var shell_verse = win_verse;
shell_verse.getVersion = getVersion
}
else {
var lin_verse = require('./lin_verse')
var shell_verse = lin_verse;
}

// SAM : TODO Use nodeshellexec where to detect git installation dir // SAM : TODO Use nodeshellexec where to detect git installation dir
var gitbash = shell_verse.getbash() var gitbash = shell_verse.getbash()
var gitRepos = null
var callshelltask = (args) => {
// console.dir(args)
if( Object.prototype.toString.call(args) === '[object Function]' ) {
return args;
}
return getshelltask(args)()
}

var runconfig = null;

// PB : TODO -- rename as shelltask and bashtask['gitbash']... ( gitbash is a different bash... so previously named to specify that the bash distribution from git is the bash being used...)
var getShellTask = (command, args, options) => {
options = options || {}
var callshell = command === 'rm' ? getgitbashtask : getshelltask;
return () => {
var p = callshell( [command, args, Object.assign({
inherit: true, shell: true, env: ENV, title: `${command} ${args}`
}, options)
])()
if (options.ignorefailures) {
return p.catch(e => {
// Ignore. Not a major error.
})
}
else return p;
}
}

var getCmdString = function(args){ return `"${args[0]} ${args[1].join(' ')}"` }
var getgitbashtask = (args, onEachError) => { return () => {
return nodeShellExec( `"${gitbash}"`, ['-c', getCmdString(args)], args[2]).catch( onEachError || function(e){ console.error(e) }) }
}

var getshelltask = (args) => {
return args[0] === 'rm' ? getgitbashtask(args) : () => {
return nodeShellExec.apply(null, args).catch(function(e){
e.benign = args[2].benign;
if(!e.benign) { console.error( JSON.stringify(e) ); }
throw e
})
}
}


// PB : TODO -- In windows if we are run from an elevated shell we never move forward and simply exits !?. // PB : TODO -- In windows if we are run from an elevated shell we never move forward and simply exits !?.
// -- Currently workaround in windows is to always run from a non-elevated shell. // -- Currently workaround in windows is to always run from a non-elevated shell.
} }
else { else {
console.log("Stats object for: example_directory.txt"); console.log("Stats object for: example_directory.txt");
console.log(stats);
console.log(util.inspect(stats));
// Using methods of the Stats object // Using methods of the Stats object
console.log("Path is file:", stats.isFile()); console.log("Path is file:", stats.isFile());
// console.log('launchscriptdir : ' + path.normalize(__dirname)) // console.log('launchscriptdir : ' + path.normalize(__dirname))
console.log('----------------------------------------------------------------') console.log('----------------------------------------------------------------')
console.log('BEFORE DISCOVERY') console.log('BEFORE DISCOVERY')
console.log('version : ' + getVersion());
console.log('version : ' + shell_verse.getVersion());
console.log('process.env.wd : ' + process.env.wd) console.log('process.env.wd : ' + process.env.wd)
console.log('processedArgs.root : ' + processedArgs.root) console.log('processedArgs.root : ' + processedArgs.root)
console.log('----------------------------------------------------------------') console.log('----------------------------------------------------------------')
console.log('----------------------------------------------------------------') console.log('----------------------------------------------------------------')
console.log('AFTER DISCOVERY') console.log('AFTER DISCOVERY')
console.log('version : ' + getVersion());
console.log('version : ' + shell_verse.getVersion());
console.log('process.env.wd : ' + process.env.wd) console.log('process.env.wd : ' + process.env.wd)
console.log('processedArgs.root : ' + processedArgs.root) console.log('processedArgs.root : ' + processedArgs.root)
console.log('----------------------------------------------------------------') console.log('----------------------------------------------------------------')
// console.dir(shell_verse.selectedinstance.launchscript) // console.dir(shell_verse.selectedinstance.launchscript)
// throw shell_verse.selectedinstance.launchscript // throw shell_verse.selectedinstance.launchscript
// Instead of waiting for the root to be establised we start working at the current locatoin and then relocate when root changes. // Instead of waiting for the root to be establised we start working at the current locatoin and then relocate when root changes.
var runlogjson = `${processedArgs.root}/.elxr/run-${runtimestamp}/run.log`
var runlogjson = `${root}/.elxr/run-${runtimestamp}/run.log`
ensureDirectoryExistence(runlogjson) ensureDirectoryExistence(runlogjson)
fs.writeFileSync(runlogjson, JSON.stringify( { message : `Started ${runtimestamp}`, success:true})) // Initialize a new log file with "logrotate" for every run fs.writeFileSync(runlogjson, JSON.stringify( { message : `Started ${runtimestamp}`, success:true})) // Initialize a new log file with "logrotate" for every run
Tasq.addlistener((e)=>{ fs.writeFileSync(runlogjson, ', ' + JSON.stringify( e ), { 'flag': 'a+' }) }) Tasq.addlistener((e)=>{ fs.writeFileSync(runlogjson, ', ' + JSON.stringify( e ), { 'flag': 'a+' }) })
return pT() // Execute it. return pT() // Execute it.
} }


var elevatedRunasRepos = null
var exludeMergeRepos = [];
// Maps an environment to a branch. Not required if the branch is appropriately named.
var checkoutMap = { 'development': 'master' }

var oplist = { var oplist = {
'h': () => { console.log(elxr.help()); return '-h' } 'h': () => { console.log(elxr.help()); return '-h' }
, 'clean' : () => { , 'clean' : () => {
, env: ENV , env: ENV
, title: `npm i for ${repo}` , title: `npm i for ${repo}`
}).catch((e) => { }).catch((e) => {
console.error('Ignoring Benign Error'); console.error(e);
console.error('Ignoring Benign Error'); console.error(util.inspect(e));
}).then(() => { }).then(() => {
console.log(`--npm run build for ${repo}--------------------`) console.log(`--npm run build for ${repo}--------------------`)
return nodeShellExec('npm', ['run build'], { return nodeShellExec('npm', ['run build'], {
}]) }])
.then(()=>{ .then(()=>{
console.log(`--rm package-lock.json for ${repodef.repo}--------------------`) console.log(`--rm package-lock.json for ${repodef.repo}--------------------`)
}).catch((e) => { console.error(e) })
}).catch((e) => { console.error(util.inspect(e)) })
// } // }
) )


// }).then(Tasq.then).catch(Tasq.catch) // }).then(Tasq.then).catch(Tasq.catch)
// }) // })


var bowerRepos = [{ repo : 'elixir-client'}];
var bowerRepos = [{ repo : 'elixir-client/client'}];
var bowertasks = [] var bowertasks = []
bowerRepos.forEach(repodef => { bowerRepos.forEach(repodef => {
bowertasks.push(() => { bowertasks.push(() => {
var p = shell_verse.createJuntionOrLink('config', target, opts) var p = shell_verse.createJuntionOrLink('config', target, opts)
return p; return p;
} }
, () => {
// Use junctions to avoid npm package issues
var target = runconfig.use + '-' + 'clientconfig' + '-' + ENV.NODE_ENV
var p = shell_verse.createJuntionOrLink('clientconfig', target, opts)
return p;
}
]; ];
// if (processedArgs._[1]) { // if (processedArgs._[1]) {
tasks = tasks.concat( [ tasks = tasks.concat( [
var parameters = ['-c', 'for i in `git remote`; do git pull $i ' + branch + '; done;'] var parameters = ['-c', 'for i in `git remote`; do git pull $i ' + branch + '; done;']
var pullCmd = [ gitbash var pullCmd = [ gitbash
, ['-c', 'for i in `git remote`; do git pull $i ' + branch + '; done;'] , ['-c', 'for i in `git remote`; do git pull $i ' + branch + '; done;']
, { cwd: repodef.repdir + '/' + repo, title : 'pull all remotes for ' + branch + ' ' + repo + ' ' + parameters.join(' ') }]
, { cwd: repodef.repodir + '/' + repo, title : 'pull all remotes for ' + branch + ' ' + repo + ' ' + parameters.join(' ') }]
} }
else pullCmd = ['git', ['pull'], { else pullCmd = ['git', ['pull'], {
inherit: true, shell: true, inherit: true, shell: true,
resetgitconfig() resetgitconfig()
} }



var getCmdString = function(args){ return `"${args[0]} ${args[1].join(' ')}"` }
var getgitbashtask = (args, onEachError) => { return () => {
return nodeShellExec( `"${gitbash}"`, ['-c', getCmdString(args)], args[2]).catch( onEachError || function(e){ console.error(e) }) }
}

var getshelltask = (args) => {
return args[0] === 'rm' ? getgitbashtask(args) : () => {
return nodeShellExec.apply(null, args).catch(function(e){
e.benign = args[2].benign;
if(!e.benign) { console.error( JSON.stringify(e) ); }
throw e
})
}
}



const GITSHELL = (function(){ const GITSHELL = (function(){
const GITSHELL = function(){} const GITSHELL = function(){}
GITSHELL.bash = shell_verse.getbash() GITSHELL.bash = shell_verse.getbash()
} }
} }


// PB : TODO -- rename as shelltask and bashtask['gitbash']... ( gitbash is a different bash... so previously named to specify that the bash distribution from git is the bash being used...)
var getShellTask = (command, args, options) => {
options = options || {}
var callshell = command === 'rm' ? getgitbashtask : getshelltask;
return () => {
var p = callshell( [command, args, Object.assign({
inherit: true, shell: true, env: ENV, title: `${command} ${args}`
}, options)
])()
if (options.ignorefailures) {
return p.catch(e => {
// Ignore. Not a major error.
})
}
else return p;
}
}

var callshelltask = (args) => {
// console.dir(args)
if( Object.prototype.toString.call(args) === '[object Function]' ) {
return args;
}
return getshelltask(args)()
}

var getnodeshellexectask = (args) => { return () => { return nodeShellExec.apply(null, args) }} var getnodeshellexectask = (args) => { return () => { return nodeShellExec.apply(null, args) }}
var perform = function( serailtasks, taskvector ){ return any( serailtasks(taskvector).map(getnodeshellexectask)) } var perform = function( serailtasks, taskvector ){ return any( serailtasks(taskvector).map(getnodeshellexectask)) }




var currentGitAuthUser; // nodeShellExec('git', ['config', 'user.email']) ... PB : TODO-- get the current GITEA username var currentGitAuthUser; // nodeShellExec('git', ['config', 'user.email']) ... PB : TODO-- get the current GITEA username


var elevatedRunasRepos = null
var gitRepos = null



// grep -qxF 'alias elxr="node elxr/index.js"' ~/.bash_profile || echo 'alias elxr="node elxr/index.js"' >> ~/.bash_profile // grep -qxF 'alias elxr="node elxr/index.js"' ~/.bash_profile || echo 'alias elxr="node elxr/index.js"' >> ~/.bash_profile
// nodeShellExec('echo', ['elxr'], { inherit : true}) //, {stdio: "inherit"} // nodeShellExec('echo', ['elxr'], { inherit : true}) //, {stdio: "inherit"}
return dbsForLabel[label] || 'mysql' return dbsForLabel[label] || 'mysql'
} }


// Maps an environment to a branch. Not required if the branch is appropriately named.
var checkoutMap = { 'development': 'master' }






// var gitbash = "G:\\Installed\\Git\\bin\\sh.exe" // var gitbash = "G:\\Installed\\Git\\bin\\sh.exe"
// Relevant git repos // Relevant git repos
var exludeMergeRepos = [];
var useGitPull = processedArgs.useGitPull || false; var useGitPull = processedArgs.useGitPull || false;
var configPromise = null var configPromise = null


} }


// function updateselection(selected) { selectedinstance = utils.assign(selectedinstance, selected) } // function updateselection(selected) { selectedinstance = utils.assign(selectedinstance, selected) }
var runconfig = null;


var promptkeys = { var promptkeys = {
cmd : processedArgs._[0] || 'pull' cmd : processedArgs._[0] || 'pull'

+ 0
- 1
index_linux.js View File

if (fs.existsSync(dirname)) { if (fs.existsSync(dirname)) {
return filePath; return filePath;
} }
ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname); fs.mkdirSync(dirname);
return filePath; return filePath;
} }

+ 9
- 4
lin_verse.js View File

const util = require('util')

const { any } = require('bbhverse'); const { any } = require('bbhverse');
const fs = require('fs') const fs = require('fs')
var path = require('path'); var path = require('path');
.catch((e) => { .catch((e) => {
// fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' }) // fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' })
// fs.writeFileSync('run.done', 'failure') // fs.writeFileSync('run.done', 'failure')
console.error(e)
console.error(util.inspect(e))
}) })
.finally(() => { .finally(() => {
// if(__runasresult && !__runasresult.skipped) fs.unlinkSync('run.done') // if(__runasresult && !__runasresult.skipped) fs.unlinkSync('run.done')
, getbash : ()=>{ return "sh" } , getbash : ()=>{ return "sh" }


, createJuntionOrLink : (dirOrFile, target, opts)=>{ , createJuntionOrLink : (dirOrFile, target, opts)=>{
return nodeShellExec('ln', ['-s', target, dirOrFile], opts).catch((e) => { console.error(e) })
return nodeShellExec('ln', ['-s', target, dirOrFile], opts).catch((e) => {
console.error(util.inspect(e))
fs.writeFileSync( `${this.tempRunDir()}\\run.log`, ', ' + JSON.stringify({ e }), {'flag':'a+'} )
})
} }


, removeJuncionOrLink : ( junctionOrLink )=>{ , removeJuncionOrLink : ( junctionOrLink )=>{
return nodeShellExec('rm', [junctionOrLink], { inherit: true, shell: true, env: process.env }) return nodeShellExec('rm', [junctionOrLink], { inherit: true, shell: true, env: process.env })
} }


, tempRunDir : function(){ return `${this.selectedinstance.root}\\.elxr\\run-${this.runtimestamp}`}
, requestElevation(elevatedRunner, taskToRun) { , requestElevation(elevatedRunner, taskToRun) {
// PB : TODO -- Most linking cmds in linux may not need elevation like in windows. // PB : TODO -- Most linking cmds in linux may not need elevation like in windows.
// However returning true here is pseudo and will break cases where real elevation is required in linux. We need to refactor to reimplement // However returning true here is pseudo and will break cases where real elevation is required in linux. We need to refactor to reimplement
// this with sudo and change all calles to use ony where required. // this with sudo and change all calles to use ony where required.
return elevatedRunner(taskToRun); return elevatedRunner(taskToRun);
} }
, iswin(){ return false}
, isWin(){ return false}


, ensureDirectoryExistence(filePath) { , ensureDirectoryExistence(filePath) {
var dirname = path.dirname(filePath); var dirname = path.dirname(filePath);
if (fs.existsSync(dirname)) { if (fs.existsSync(dirname)) {
return filePath; return filePath;
} }
this.ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname); fs.mkdirSync(dirname);
return filePath; return filePath;
} }

+ 4
- 2
win_verse.js View File

// win_verse // win_verse


const util = require('util')

const { any, Traq } = require('bbhverse'); const { any, Traq } = require('bbhverse');
const fs = require('fs') const fs = require('fs')
var path = require('path'); var path = require('path');
, getbash : ()=>{ return "C:\\Program Files\\Git\\bin\\sh.exe" } , getbash : ()=>{ return "C:\\Program Files\\Git\\bin\\sh.exe" }


, createJuntionOrLink : (dirOrFile, target, opts) =>{ , createJuntionOrLink : (dirOrFile, target, opts) =>{
return nodeShellExec('mklink', ['/J', dirOrFile, target], opts).catch((e) => { console.error(e)
return nodeShellExec('mklink', ['/J', dirOrFile, target], opts).catch((e) => {
console.error(utils.inspect(e))
fs.writeFileSync( `${this.tempRunDir()}\\run.log`, ', ' + JSON.stringify({ e }), {'flag':'a+'} ) fs.writeFileSync( `${this.tempRunDir()}\\run.log`, ', ' + JSON.stringify({ e }), {'flag':'a+'} )
}) })
} }
if (fs.existsSync(dirname)) { if (fs.existsSync(dirname)) {
return filePath; return filePath;
} }
this.ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname); fs.mkdirSync(dirname);
return filePath; return filePath;
} }

Loading…
Cancel
Save