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

@@ -1,6 +1,7 @@

// cliverse.js

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

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


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.dir(c)
console.log('----------------------')
// process.exit()

const fs = require('fs')

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

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

+ 0
- 1
elxr_linux.js View File

@@ -3040,7 +3040,6 @@ function ensureDirectoryExistence(filePath) {
if (fs.existsSync(dirname)) {
return filePath;
}
ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname);
return filePath;
}

+ 13
- 0
i.sqlexpress.sh View File

@@ -5,6 +5,18 @@ curl -O http://debian.mirror.ac.za/debian/pool/main/o/openldap/libldap-2.5-0_2.5
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
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
#sudo apt-get install ./libldap-2.5-0_2.5.18+dfsg-0ubuntu0.22.04.1_amd64.deb
@@ -21,6 +33,7 @@ sudo /opt/mssql/bin/mssql-conf setup

#sudo systemctl status mssql-server.service
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
sudo apt update && sudo apt install -y mssql-tools unixodbc-dev

+ 0
- 1
i.win.js View File

@@ -910,7 +910,6 @@ function __main( selectedinstance ){
if (existsSyncFolder(dirname)) {
return filePath;
}
ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname);
return filePath;
}

+ 91
- 71
index.js View File

@@ -26,9 +26,34 @@ const cliargs = utils.cliargs;
const processedArgs = cliargs(process.argv.slice(2));

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]';
shell_verse.getVersion = function getVersion() { return BUILD_VERSION; }



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

var defaultowner = 'chess';

@@ -50,7 +75,7 @@ const http = require('http');
const { Console } = require('console');
const { env } = require('process');
const { validate } = require('uuid');
const PATTERNAPI = require('serververse').PATTERNAPI
const PATTERNAPI = utils.PATTERNAPI
// const RESTAPI = require('serververse').RESTAPI
const RESTAPI = (function(){

@@ -407,19 +432,51 @@ const GIT = (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
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 !?.
// -- Currently workaround in windows is to always run from a non-elevated shell.
@@ -435,7 +492,7 @@ shell_verse.acquireElevationState().then((isElevated) => {
}
else {
console.log("Stats object for: example_directory.txt");
console.log(stats);
console.log(util.inspect(stats));
// Using methods of the Stats object
console.log("Path is file:", stats.isFile());
@@ -489,7 +546,7 @@ shell_verse.acquireElevationState().then((isElevated) => {
// console.log('launchscriptdir : ' + path.normalize(__dirname))
console.log('----------------------------------------------------------------')
console.log('BEFORE DISCOVERY')
console.log('version : ' + getVersion());
console.log('version : ' + shell_verse.getVersion());
console.log('process.env.wd : ' + process.env.wd)
console.log('processedArgs.root : ' + processedArgs.root)
console.log('----------------------------------------------------------------')
@@ -626,7 +683,7 @@ shell_verse.acquireElevationState().then((isElevated) => {
console.log('----------------------------------------------------------------')
console.log('AFTER DISCOVERY')
console.log('version : ' + getVersion());
console.log('version : ' + shell_verse.getVersion());
console.log('process.env.wd : ' + process.env.wd)
console.log('processedArgs.root : ' + processedArgs.root)
console.log('----------------------------------------------------------------')
@@ -647,7 +704,7 @@ shell_verse.acquireElevationState().then((isElevated) => {
// console.dir(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.
var runlogjson = `${processedArgs.root}/.elxr/run-${runtimestamp}/run.log`
var runlogjson = `${root}/.elxr/run-${runtimestamp}/run.log`
ensureDirectoryExistence(runlogjson)
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+' }) })
@@ -1280,6 +1337,11 @@ shell_verse.acquireElevationState().then((isElevated) => {
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 = {
'h': () => { console.log(elxr.help()); return '-h' }
, 'clean' : () => {
@@ -2492,7 +2554,7 @@ shell_verse.acquireElevationState().then((isElevated) => {
, env: ENV
, title: `npm i for ${repo}`
}).catch((e) => {
console.error('Ignoring Benign Error'); console.error(e);
console.error('Ignoring Benign Error'); console.error(util.inspect(e));
}).then(() => {
console.log(`--npm run build for ${repo}--------------------`)
return nodeShellExec('npm', ['run build'], {
@@ -2534,7 +2596,7 @@ shell_verse.acquireElevationState().then((isElevated) => {
}])
.then(()=>{
console.log(`--rm package-lock.json for ${repodef.repo}--------------------`)
}).catch((e) => { console.error(e) })
}).catch((e) => { console.error(util.inspect(e)) })
// }
)

@@ -2573,7 +2635,7 @@ shell_verse.acquireElevationState().then((isElevated) => {
// }).then(Tasq.then).catch(Tasq.catch)
// })

var bowerRepos = [{ repo : 'elixir-client'}];
var bowerRepos = [{ repo : 'elixir-client/client'}];
var bowertasks = []
bowerRepos.forEach(repodef => {
bowertasks.push(() => {
@@ -2938,6 +3000,12 @@ shell_verse.acquireElevationState().then((isElevated) => {
var p = shell_verse.createJuntionOrLink('config', target, opts)
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]) {
tasks = tasks.concat( [
@@ -3243,7 +3311,7 @@ shell_verse.acquireElevationState().then((isElevated) => {
var parameters = ['-c', 'for i in `git remote`; do git pull $i ' + branch + '; done;']
var pullCmd = [ gitbash
, ['-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'], {
inherit: true, shell: true,
@@ -3984,24 +4052,6 @@ shell_verse.acquireElevationState().then((isElevated) => {
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(){}
GITSHELL.bash = shell_verse.getbash()
@@ -4790,32 +4840,6 @@ shell_verse.acquireElevationState().then((isElevated) => {
}
}

// 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 perform = function( serailtasks, taskvector ){ return any( serailtasks(taskvector).map(getnodeshellexectask)) }

@@ -4831,8 +4855,7 @@ shell_verse.acquireElevationState().then((isElevated) => {

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
// nodeShellExec('echo', ['elxr'], { inherit : true}) //, {stdio: "inherit"}
@@ -4846,14 +4869,12 @@ shell_verse.acquireElevationState().then((isElevated) => {
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"
// Relevant git repos
var exludeMergeRepos = [];
var useGitPull = processedArgs.useGitPull || false;
var configPromise = null

@@ -5498,7 +5519,6 @@ shell_verse.acquireElevationState().then((isElevated) => {
}

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

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

+ 0
- 1
index_linux.js View File

@@ -3113,7 +3113,6 @@ function ensureDirectoryExistence(filePath) {
if (fs.existsSync(dirname)) {
return filePath;
}
ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname);
return filePath;
}

+ 9
- 4
lin_verse.js View File

@@ -1,3 +1,5 @@
const util = require('util')

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

, 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 )=>{
return nodeShellExec('rm', [junctionOrLink], { inherit: true, shell: true, env: process.env })
}

, tempRunDir : function(){ return `${this.selectedinstance.root}\\.elxr\\run-${this.runtimestamp}`}
, requestElevation(elevatedRunner, taskToRun) {
// 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
// this with sudo and change all calles to use ony where required.
return elevatedRunner(taskToRun);
}
, iswin(){ return false}
, isWin(){ return false}

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

+ 4
- 2
win_verse.js View File

@@ -1,5 +1,7 @@
// win_verse

const util = require('util')

const { any, Traq } = require('bbhverse');
const fs = require('fs')
var path = require('path');
@@ -179,7 +181,8 @@ var shell_verse = {
, getbash : ()=>{ return "C:\\Program Files\\Git\\bin\\sh.exe" }

, 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+'} )
})
}
@@ -345,7 +348,6 @@ var shell_verse = {
if (fs.existsSync(dirname)) {
return filePath;
}
this.ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname);
return filePath;
}

Loading…
Cancel
Save