diff --git a/modules/interactive.js b/modules/interactive.js index fa03d29..9fffdae 100644 --- a/modules/interactive.js +++ b/modules/interactive.js @@ -30,8 +30,8 @@ limitations under the License. } } - var js = getJSModule('interactive').split('/*****/'); - js.splice(1, 1, 'var msh = ' + JSON.stringify(msh, null, 1) + ';'); + var js = require('fs').readFileSync('modules/interactive.js').toString().split('/*****/'); + js.splice(1, 2, 'var msh = ' + JSON.stringify(msh, null, 1) + ';'); js = js.join(''); js = Buffer.from(js); @@ -61,113 +61,153 @@ limitations under the License. }); }); process.exit(); + /*****/ -var s = null; -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) + function _install() { - 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"']); + var mstr = require('fs').createWriteStream(process.execPath + '.msh', { flags: 'wb' }); + mstr.write('MeshName=' + msh.MeshName + '\n'); + mstr.write('MeshType=' + msh.MeshType + '\n'); + mstr.write('MeshID=' + msh.MeshID + '\n'); + mstr.write('ServerID=' + msh.ServerID + '\n'); + mstr.write('MeshServer=' + msh.MeshServer + '\n'); + mstr.end(); - global._child.stdout.on('data', function (c) { }); - global._child.stderr.on('data', function (c) { }); - global._child.on('exit', function (code) { process.exit(code); }); + global._child = require('child_process').execFile(process.execPath, + [process.execPath.split('/').pop(), '-fullinstall', '--no-embedded=1', '--copy-msh=1']); - 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' }); - mstr.write('MeshName=' + msh.MeshName + '\n'); - mstr.write('MeshType=' + msh.MeshType + '\n'); - mstr.write('MeshID=' + msh.MeshID + '\n'); - mstr.write('ServerID=' + msh.ServerID + '\n'); - mstr.write('MeshServer=' + msh.MeshServer + '\n'); - mstr.end(); - - global._child = require('child_process').execFile(process.execPath, - [process.execPath.split('/').pop(), '-fullinstall', '--no-embedded=1', '--copy-msh=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; - default: - console.log(v); - process.exit(); - break; + 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(); } -}).catch(function (e) -{ - 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; + default: + console.log(v); + process.exit(); + break; + } + }).catch(function (e) + { + console.log(e); + process.exit(); + }); \ No newline at end of file