Updated Linux interactive installer.

This commit is contained in:
Ylian Saint-Hilaire 2020-09-10 15:18:33 -07:00
parent 1452746b71
commit 7311b23743
2 changed files with 152 additions and 126 deletions

View File

@ -24,6 +24,7 @@
<Compile Include="agents\meshcmd.min.js" /> <Compile Include="agents\meshcmd.min.js" />
<Compile Include="agents\meshcore.js" /> <Compile Include="agents\meshcore.js" />
<Compile Include="agents\meshcore.min.js" /> <Compile Include="agents\meshcore.min.js" />
<Compile Include="agents\meshinstall-linux.js" />
<Compile Include="agents\modules_meshcmd\amt-ider.js" /> <Compile Include="agents\modules_meshcmd\amt-ider.js" />
<Compile Include="agents\modules_meshcmd\amt-lme.js" /> <Compile Include="agents\modules_meshcmd\amt-lme.js" />
<Compile Include="agents\modules_meshcmd\amt-mei.js" /> <Compile Include="agents\modules_meshcmd\amt-mei.js" />

View File

@ -14,12 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
var msh = {}; var s = null, msh = {}, buttons = ['Cancel'], skip = false;
var s = null;
try { s = require('service-manager').manager.getService('meshagent'); } catch (e) { } try { s = require('service-manager').manager.getService('meshagent'); } catch (e) { }
function _install() function _install(parms) {
{
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');
@ -27,160 +25,187 @@ function _install()
mstr.write('ServerID=' + msh.ServerID + '\n'); mstr.write('ServerID=' + msh.ServerID + '\n');
mstr.write('MeshServer=' + msh.MeshServer + '\n'); mstr.write('MeshServer=' + msh.MeshServer + '\n');
mstr.end(); mstr.end();
global._child = require('child_process').execFile(process.execPath, if (parms == null) { parms = []; }
[process.execPath.split('/').pop(), '-fullinstall', '--no-embedded=1', '--copy-msh=1']); parms.unshift('--copy-msh=1');
parms.unshift('--no-embedded=1');
global._child.stdout.on('data', function (c) { process.stdout.write(c.toString()); }); parms.unshift('-fullinstall');
global._child.stderr.on('data', function (c) { process.stdout.write(c.toString()); }); parms.unshift(process.execPath.split('/').pop());
global._child.waitExit();
} global._child = require('child_process').execFile(process.execPath, parms);
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.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();
} }
var s = null; function _uninstall() {
try { s = require('service-manager').manager.getService('meshagent'); } catch (e) { } global._child = require('child_process').execFile(process.execPath,
var buttons = ['Cancel']; [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();
}
if (msh.InstallFlags == null) if (msh.InstallFlags == null) {
{
msh.InstallFlags = 3; msh.InstallFlags = 3;
} } else {
else
{
msh.InstallFlags = parseInt(msh.InstallFlags.toString()); msh.InstallFlags = parseInt(msh.InstallFlags.toString());
} }
if ((msh.InstallFlags & 1) == 1) { buttons.unshift('Connect'); }
if ((msh.InstallFlags & 1) == 1) { buttons.unshift("Connect"); } if ((msh.InstallFlags & 2) == 2) {
if ((msh.InstallFlags & 2) == 2) if (!require('user-sessions').isRoot()) {
{
if (!require('user-sessions').isRoot())
{
console.log('\n' + "Elevated permissions is required to install/uninstall the agent."); console.log('\n' + "Elevated permissions is required to install/uninstall the agent.");
console.log("Please try again with sudo."); console.log("Please try again with sudo.");
process.exit(); process.exit();
} }
if (s) if (s) {
{ if (process.platform == 'darwin' || require('message-box').kdialog) {
if (process.platform == 'darwin' || require('message-box').kdialog)
{
buttons.unshift("Setup"); buttons.unshift("Setup");
} } else {
else
{
buttons.unshift("Uninstall"); buttons.unshift("Uninstall");
buttons.unshift("Update"); buttons.unshift("Update");
} }
} } else {
else
{
buttons.unshift("Install"); buttons.unshift("Install");
} }
} }
if (process.platform != 'darwin') if (process.platform != 'darwin') {
{ if (!require('message-box').kdialog && (require('message-box').zenity == null || (!require('message-box').zenity.extra))) {
if (!require('message-box').kdialog && (require('message-box').zenity == null || (!require('message-box').zenity.extra))) if (process.argv.includes('-install') || process.argv.includes('-update')) {
{ var p = [];
console.log('\n' + "This installer cannot run on this system."); for (var i = 0; i < process.argv.length; ++i) {
console.log("Try installing/updating Zenity, and run again." + '\n'); if (process.argv[i].startsWith('--installPath=')) {
process.exit(); p.push('--installPath="' + process.argv[i].split('=').pop() + '"');
}
}
_install(p);
process.exit();
}
else if (process.argv.includes('-uninstall')) {
_uninstall();
process.exit();
}
else if (process.argv.includes('-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); });
console.log("\nConnecting to: " + msh.MeshServer);
console.log("Device Group: " + msh.MeshName);
console.log('\nPress Ctrl-c to exit\n');
skip = true;
} else {
console.log('\n' + "The graphical version of this installer cannot run on this system.");
console.log("Try installing/updating Zenity, and run again." + '\n');
console.log("You can also run the text version from the command line with the following command(s): ");
if ((msh.InstallFlags & 1) == 1) {
console.log('./' + process.execPath.split('/').pop() + ' -connect');
}
if ((msh.InstallFlags & 2) == 2) {
if (s) {
console.log('./' + process.execPath.split('/').pop() + ' -update');
console.log('./' + process.execPath.split('/').pop() + ' -uninstall');
}
else {
console.log('./' + process.execPath.split('/').pop() + ' -install');
console.log('./' + process.execPath.split('/').pop() + ' -install --installPath="/alternate/path"');
}
}
console.log('');
process.exit();
}
} }
} }
else else {
{
if (!require('user-sessions').isRoot()) { console.log('\n' + "This utility requires elevated permissions. Please try again with sudo."); process.exit(); } if (!require('user-sessions').isRoot()) { console.log('\n' + "This utility requires elevated permissions. Please try again with sudo."); process.exit(); }
} }
if (!s)
{
msg = "Agent: " + "NOT INSTALLED" + '\n';
} else
{
msg = "Agent: " + (s.isRunning() ? "RUNNING" : "NOT RUNNING") + '\n';
}
msg += ("Device Group: " + msh.MeshName + '\n'); if (!skip) {
msg += ("Server URL: " + msh.MeshServer + '\n'); if (!s) {
msg = "Agent: " + "NOT INSTALLED" + '\n';
var p = require('message-box').create("MeshCentral Agent Setup", msg, 99999, buttons); } else {
p.then(function (v) msg = "Agent: " + (s.isRunning() ? "RUNNING" : "NOT RUNNING") + '\n';
{ }
switch (v)
{ msg += ("Device Group: " + msh.MeshName + '\n');
case "Cancel": msg += ("Server URL: " + msh.MeshServer + '\n');
process.exit();
break; var p = require('message-box').create("MeshCentral Agent Setup", msg, 99999, buttons);
case "Setup": p.then(function (v) {
var d = require('message-box').create("MeshCentral Agent", msg, 99999, ["Update", "Uninstall", "Cancel"]); switch (v) {
d.then(function (v) case "Cancel":
{
switch (v)
{
case "Update":
case "Install":
_install();
break;
case "Uninstall":
_uninstall();
break;
default:
break;
}
process.exit(); process.exit();
}).catch(function (v) { process.exit(); }); break;
break; case 'Setup':
case "Connect": var d = require('message-box').create("MeshCentral Agent", msg, 99999, ['Update', 'Uninstall', 'Cancel']);
global._child = require('child_process').execFile(process.execPath, d.then(function (v) {
[process.execPath.split('/').pop(), '--no-embedded=1', '--disableUpdate=1', 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 + '"', '--MeshName="' + msh.MeshName + '"', '--MeshType="' + msh.MeshType + '"',
'--MeshID="' + msh.MeshID + '"', '--MeshID="' + msh.MeshID + '"',
'--ServerID="' + msh.ServerID + '"', '--ServerID="' + msh.ServerID + '"',
'--MeshServer="' + msh.MeshServer + '"', '--MeshServer="' + msh.MeshServer + '"',
'--AgentCapabilities="0x00000020"']); '--AgentCapabilities="0x00000020"']);
global._child.stdout.on('data', function (c) { }); global._child.stdout.on('data', function (c) { });
global._child.stderr.on('data', function (c) { }); global._child.stderr.on('data', function (c) { });
global._child.on('exit', function (code) { process.exit(code); }); global._child.on('exit', function (code) { process.exit(code); });
msg = ("Device Group: " + msh.MeshName + '\n'); msg = ("Device Group: " + msh.MeshName + '\n');
msg += ("Server URL: " + msh.MeshServer + '\n'); msg += ("Server URL: " + msh.MeshServer + '\n');
if (process.platform != 'darwin') if (process.platform != 'darwin') {
{ if (!require('message-box').zenity && require('message-box').kdialog) {
if (!require('message-box').zenity && require('message-box').kdialog) msg += ('\nPress OK to Disconnect');
{ }
msg += ('\n'+"Press OK to Disconnect");
} }
}
var d = require('message-box').create("MeshCentral Agent", msg, 99999, ['Disconnect']);
var d = require('message-box').create("MeshCentral Agent", msg, 99999, ["Disconnect"]); d.then(function (v) { process.exit(); }).catch(function (v) { process.exit(); });
d.then(function (v) { process.exit(); }).catch(function (v) { process.exit(); }); break;
break; case "Uninstall":
case "Uninstall": _uninstall();
_uninstall(); process.exit();
process.exit(); break;
break; case "Install":
case "Install": case "Update":
case "Update": _install();
_install(); process.exit();
process.exit(); break;
break; default:
default: console.log(v);
console.log(v); process.exit();
process.exit(); break;
break; }
} }).catch(function (e) {
}).catch(function (e) console.log(e);
{ process.exit();
console.log(e); });
process.exit(); }
});