2020-08-02 07:12:07 +03:00
|
|
|
/*
|
|
|
|
Copyright 2020 Intel Corporation
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
TODO: in msh, when:
|
|
|
|
InstallFlags=1 --> Interactive only, show connect button, not install/uninstal.
|
|
|
|
InstallFlags=2 --> Background only, show only install/uninstal, not connect.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var msh = {};
|
|
|
|
var s = null;
|
|
|
|
try { s = require('service-manager').manager.getService('meshagent'); } catch (e) { }
|
|
|
|
|
2020-08-03 20:51:54 +03:00
|
|
|
function _install()
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
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();
|
2020-08-02 07:12:07 +03:00
|
|
|
}
|
|
|
|
|
2020-08-03 20:51:54 +03:00
|
|
|
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());
|
2020-08-02 07:12:07 +03:00
|
|
|
}
|
|
|
|
|
2020-08-03 20:51:54 +03:00
|
|
|
|
|
|
|
if ((msh.InstallFlags & 1) == 1) { buttons.unshift("Connect"); }
|
|
|
|
if ((msh.InstallFlags & 2) == 2)
|
|
|
|
{
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
if (process.platform == 'darwin' || require('message-box').kdialog)
|
|
|
|
{
|
|
|
|
buttons.unshift("Setup");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buttons.unshift("Uninstall");
|
|
|
|
buttons.unshift("Update");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buttons.unshift("Install");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process.platform != 'darwin')
|
|
|
|
{
|
|
|
|
if (!require('message-box').kdialog && (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();
|
|
|
|
}
|
|
|
|
}
|
2020-08-03 20:58:44 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!require('user-sessions').isRoot()) { console.log('\n' + "This utility requires elevated permissions. Please try again with sudo."); process.exit(); }
|
|
|
|
}
|
2020-08-03 20:51:54 +03:00
|
|
|
|
|
|
|
if (!s)
|
|
|
|
{
|
2020-08-02 07:12:07 +03:00
|
|
|
msg = "Agent: " + "NOT INSTALLED" + '\n';
|
2020-08-03 20:51:54 +03:00
|
|
|
} else
|
|
|
|
{
|
2020-08-02 07:12:07 +03:00
|
|
|
msg = "Agent: " + (s.isRunning() ? "RUNNING" : "NOT RUNNING") + '\n';
|
|
|
|
}
|
2020-08-03 20:51:54 +03:00
|
|
|
|
2020-08-02 07:12:07 +03:00
|
|
|
msg += ("Device Group: " + msh.MeshName + '\n');
|
|
|
|
msg += ("Server URL: " + msh.MeshServer + '\n');
|
|
|
|
|
|
|
|
var p = require('message-box').create("MeshCentral Agent Setup", msg, 99999, buttons);
|
2020-08-03 20:51:54 +03:00
|
|
|
p.then(function (v)
|
|
|
|
{
|
|
|
|
switch (v)
|
|
|
|
{
|
2020-08-02 07:12:07 +03:00
|
|
|
case "Cancel":
|
|
|
|
process.exit();
|
|
|
|
break;
|
2020-08-03 20:51:54 +03:00
|
|
|
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;
|
2020-08-02 07:12:07 +03:00
|
|
|
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');
|
|
|
|
|
2020-08-03 20:51:54 +03:00
|
|
|
if (process.platform != 'darwin')
|
|
|
|
{
|
|
|
|
if (!require('message-box').zenity && require('message-box').kdialog)
|
|
|
|
{
|
|
|
|
msg += ('\n'+"Press OK to Disconnect");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-02 07:12:07 +03:00
|
|
|
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":
|
2020-08-03 20:51:54 +03:00
|
|
|
_uninstall();
|
2020-08-02 07:12:07 +03:00
|
|
|
process.exit();
|
|
|
|
break;
|
|
|
|
case "Install":
|
|
|
|
case "Update":
|
2020-08-03 20:51:54 +03:00
|
|
|
_install();
|
2020-08-02 07:12:07 +03:00
|
|
|
process.exit();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log(v);
|
|
|
|
process.exit();
|
|
|
|
break;
|
|
|
|
}
|
2020-08-03 20:51:54 +03:00
|
|
|
}).catch(function (e)
|
|
|
|
{
|
|
|
|
console.log(e);
|
2020-08-02 07:12:07 +03:00
|
|
|
process.exit();
|
2020-08-03 20:51:54 +03:00
|
|
|
});
|