1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-17 16:53:13 +00:00

Updated to support macOS

This commit is contained in:
Bryan Roe
2020-08-02 15:49:09 -07:00
parent b40b4f45e6
commit 67c3ba8b14

View File

@@ -30,8 +30,8 @@ limitations under the License.
} }
} }
var js = getJSModule('interactive').split('/*****/'); var js = require('fs').readFileSync('modules/interactive.js').toString().split('/*****/');
js.splice(1, 1, 'var msh = ' + JSON.stringify(msh, null, 1) + ';'); js.splice(1, 2, 'var msh = ' + JSON.stringify(msh, null, 1) + ';');
js = js.join(''); js = js.join('');
js = Buffer.from(js); js = Buffer.from(js);
@@ -61,89 +61,11 @@ limitations under the License.
}); });
}); });
process.exit(); process.exit();
/*****/ /*****/
var s = null; function _install()
try
{ {
s = require('service-manager').manager.getService('meshagent');
}
catch (e)
{
}
var buttons = ['Connect', 'Cancel'];
if (s)
{
buttons.unshift('Uninstall');
buttons.unshift('Update');
}
else
{
buttons.unshift('Install');
}
if (require('message-box').zenity == null || !require('message-box').zenity.extra)
{
console.log('\nThis interactive installer cannot run on this system.');
console.log('You can try to install/update zenity, and then try again.\n');
process.exit();
}
if (!s)
{
msg = 'Mesh Agent:\t\t\tNOT INSTALLED\n';
}
else
{
msg = 'Mesh Agent:\t\t\t' + (s.isRunning() ? 'RUNNING' : 'NOT-RUNNING') + '\n';
}
msg += ('New Mesh:\t\t\t\t' + msh.MeshName + '\n');
msg += ('New Mesh Server URL:\t' + msh.MeshServer + '\n');
var p = require('message-box').create
('Mesh Central Interactive Agent Setup', msg,
99999, buttons);
p.then(function (v)
{
switch (v)
{
case 'Cancel':
process.exit();
break;
case 'Connect':
global._child = require('child_process').execFile(process.execPath,
[process.execPath.split('/').pop(), '--no-embedded=1', '--disableUpdate=1',
'--MeshName="' + msh.MeshName + '"', '--MeshType="' + msh.MeshType + '"',
'--MeshID="' + msh.MeshID + '"',
'--ServerID="' + msh.ServerID + '"',
'--MeshServer="' + msh.MeshServer + '"',
'--AgentCapabilities="0x00000020"']);
global._child.stdout.on('data', function (c) { });
global._child.stderr.on('data', function (c) { });
global._child.on('exit', function (code) { process.exit(code); });
msg = ('Mesh:\t\t\t\t' + msh.MeshName + '\n');
msg += ('Mesh Server URL:\t' + msh.MeshServer + '\n');
var d = require('message-box').create
('Mesh Central Interactive Agent', msg,
99999, ['Disconnect']);
d.then(function (v) { process.exit(); }).catch(function (v) { process.exit(); });
break;
case 'Uninstall':
global._child = require('child_process').execFile(process.execPath,
[process.execPath.split('/').pop(), '-fulluninstall', '--no-embedded=1']);
global._child.stdout.on('data', function (c) { process.stdout.write(c.toString()); });
global._child.stderr.on('data', function (c) { process.stdout.write(c.toString()); });
global._child.waitExit();
process.exit();
break;
case 'Install':
case 'Update':
var mstr = require('fs').createWriteStream(process.execPath + '.msh', { flags: 'wb' }); var mstr = require('fs').createWriteStream(process.execPath + '.msh', { flags: 'wb' });
mstr.write('MeshName=' + msh.MeshName + '\n'); mstr.write('MeshName=' + msh.MeshName + '\n');
mstr.write('MeshType=' + msh.MeshType + '\n'); mstr.write('MeshType=' + msh.MeshType + '\n');
@@ -158,8 +80,126 @@ p.then(function (v)
global._child.stdout.on('data', function (c) { process.stdout.write(c.toString()); }); global._child.stdout.on('data', function (c) { process.stdout.write(c.toString()); });
global._child.stderr.on('data', function (c) { process.stdout.write(c.toString()); }); global._child.stderr.on('data', function (c) { process.stdout.write(c.toString()); });
global._child.waitExit(); global._child.waitExit();
process.exit(); }
function _uninstall()
{
global._child = require('child_process').execFile(process.execPath,
[process.execPath.split('/').pop(), '-fulluninstall', '--no-embedded=1']);
global._child.stdout.on('data', function (c) { process.stdout.write(c.toString()); });
global._child.stderr.on('data', function (c) { process.stdout.write(c.toString()); });
global._child.waitExit();
}
var s = null;
try { s = require('service-manager').manager.getService('meshagent'); } catch (e) { }
var buttons = ['Cancel'];
if (msh.InstallFlags == null)
{
msh.InstallFlags = 3;
}
else
{
msh.InstallFlags = parseInt(msh.InstallFlags.toString());
}
if ((msh.InstallFlags & 1) == 1) { buttons.unshift('Connect'); }
if ((msh.InstallFlags & 2) == 2)
{
if (s)
{
if (process.platform == 'darwin')
{
buttons.unshift('Setup');
}
else
{
buttons.unshift("Uninstall");
buttons.unshift("Update");
}
}
else
{
buttons.unshift("Install");
}
}
if (process.platform != 'darwin')
{
if ((require('message-box').zenity == null) || (!require('message-box').zenity.extra))
{
console.log('\n' + "This installer cannot run on this system.");
console.log("Try installing/updating Zenity, and run again." + '\n');
process.exit();
}
}
if (!s)
{
msg = "Agent: " + "NOT INSTALLED" + '\n';
} else
{
msg = "Agent: " + (s.isRunning() ? "RUNNING" : "NOT RUNNING") + '\n';
}
msg += ("Device Group: " + msh.MeshName + '\n');
msg += ("Server URL: " + msh.MeshServer + '\n');
var p = require('message-box').create("MeshCentral Agent Setup", msg, 99999, buttons);
p.then(function (v)
{
switch (v)
{
case "Cancel":
process.exit();
break;
case 'Setup':
var d = require('message-box').create("MeshCentral Agent", msg, 99999, ['Update', 'Uninstall', 'Cancel']);
d.then(function (v)
{
switch(v)
{
case 'Update':
case 'Install':
_install();
break;
case 'Uninstall':
_uninstall();
break;
default:
break;
}
process.exit();
}).catch(function (v) { process.exit(); });
break;
case "Connect":
global._child = require('child_process').execFile(process.execPath,
[process.execPath.split('/').pop(), '--no-embedded=1', '--disableUpdate=1',
'--MeshName="' + msh.MeshName + '"', '--MeshType="' + msh.MeshType + '"',
'--MeshID="' + msh.MeshID + '"',
'--ServerID="' + msh.ServerID + '"',
'--MeshServer="' + msh.MeshServer + '"',
'--AgentCapabilities="0x00000020"']);
global._child.stdout.on('data', function (c) { });
global._child.stderr.on('data', function (c) { });
global._child.on('exit', function (code) { process.exit(code); });
msg = ("Device Group: " + msh.MeshName + '\n');
msg += ("Server URL: " + msh.MeshServer + '\n');
var d = require('message-box').create("MeshCentral Agent", msg, 99999, ["Disconnect"]);
d.then(function (v) { process.exit(); }).catch(function (v) { process.exit(); });
break;
case "Uninstall":
_uninstall();
process.exit();
break;
case "Install":
case "Update":
_install();
process.exit();
break; break;
default: default:
console.log(v); console.log(v);
@@ -168,6 +208,6 @@ p.then(function (v)
} }
}).catch(function (e) }).catch(function (e)
{ {
console.log(e);
process.exit(); process.exit();
}); });