Added customization support
This commit is contained in:
parent
326dbb0b19
commit
cffd86091d
|
@ -14,63 +14,83 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// The folloing line just below with 'msh=' needs to stay exactly like this since MeshCentral will replace it with the correct settings.
|
// The folloing line just below with 'msh=' needs to stay exactly like this since MeshCentral will replace it with the correct settings.
|
||||||
var msh = {};
|
var msh = {};
|
||||||
|
var displayName = msh.displayName ? msh.displayName : 'MeshCentral Agent';
|
||||||
var s = null, buttons = ['Cancel'], skip = false;
|
var s = null, buttons = ['Cancel'], skip = false;
|
||||||
try { s = require('service-manager').manager.getService('meshagent'); } catch (e) { }
|
var serviceName = msh.meshServiceName ? msh.meshServiceName : 'meshagent';
|
||||||
|
|
||||||
function _install(parms) {
|
try { s = require('service-manager').manager.getService(serviceName); } catch (e) { }
|
||||||
|
|
||||||
|
var connectArgs = [process.execPath.split('/').pop(), '--no-embedded=1', '--disableUpdate=1'];
|
||||||
|
connectArgs.push('--MeshName="' + msh.MeshName + '"');
|
||||||
|
connectArgs.push('--MeshType="' + msh.MeshType + '"');
|
||||||
|
connectArgs.push('--MeshID="' + msh.MeshID + '"');
|
||||||
|
connectArgs.push('--ServerID="' + msh.ServerID + '"');
|
||||||
|
connectArgs.push('--MeshServer="' + msh.MeshServer + '"');
|
||||||
|
connectArgs.push('--AgentCapabilities="0x00000020"');
|
||||||
|
if (msh.displayName) { connectArgs.push('--displayName="' + msh.displayName + '"'); }
|
||||||
|
if (msh.agentName) { connectArgs.push('--agentName="' + msh.agentName + '"'); }
|
||||||
|
|
||||||
|
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');
|
||||||
mstr.write('MeshID=' + msh.MeshID + '\n');
|
mstr.write('MeshID=' + msh.MeshID + '\n');
|
||||||
mstr.write('ServerID=' + msh.ServerID + '\n');
|
mstr.write('ServerID=' + msh.ServerID + '\n');
|
||||||
mstr.write('MeshServer=' + msh.MeshServer + '\n');
|
mstr.write('MeshServer=' + msh.MeshServer + '\n');
|
||||||
|
if (msh.agentName) { mstr.write('agentName=' + msh.agentName + '\n'); }
|
||||||
|
if (msh.meshServiceName) { mstr.write('meshServiceName=' + msh.meshServiceName + '\n'); }
|
||||||
mstr.end();
|
mstr.end();
|
||||||
|
|
||||||
if (parms == null) { parms = []; }
|
if (parms == null) { parms = []; }
|
||||||
|
if (msh.companyName) { parms.unshift('--companyName="' + msh.companyName + '"'); }
|
||||||
|
if (msh.displayName) { parms.unshift('--displayName="' + msh.displayName + '"'); }
|
||||||
|
if (msh.meshServiceName) { parms.unshift('--meshServiceName="' + msh.meshServiceName + '"'); }
|
||||||
parms.unshift('--copy-msh=1');
|
parms.unshift('--copy-msh=1');
|
||||||
parms.unshift('--no-embedded=1');
|
parms.unshift('--no-embedded=1');
|
||||||
parms.unshift('-fullinstall');
|
parms.unshift('-fullinstall');
|
||||||
parms.unshift(process.execPath.split('/').pop());
|
parms.unshift(process.execPath.split('/').pop());
|
||||||
|
|
||||||
global._child = require('child_process').execFile(process.execPath, parms);
|
global._child = require('child_process').execFile(process.execPath, parms);
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
function _uninstall() {
|
function _uninstall()
|
||||||
|
{
|
||||||
global._child = require('child_process').execFile(process.execPath,
|
global._child = require('child_process').execFile(process.execPath,
|
||||||
[process.execPath.split('/').pop(), '-fulluninstall', '--no-embedded=1']);
|
[process.execPath.split('/').pop(), '-fulluninstall', '--no-embedded=1', '--meshServiceName="' + serviceName + '"']);
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (process.argv.includes('-mesh')) {
|
if (process.argv.includes('-mesh'))
|
||||||
|
{
|
||||||
console.log(JSON.stringify(msh, null, 2));
|
console.log(JSON.stringify(msh, null, 2));
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((msh.InstallFlags & 1) == 1) {
|
if ((msh.InstallFlags & 1) == 1)
|
||||||
|
{
|
||||||
buttons.unshift('Connect');
|
buttons.unshift('Connect');
|
||||||
if (process.argv.includes('-connect')) {
|
if (process.argv.includes('-connect'))
|
||||||
global._child = require('child_process').execFile(process.execPath,
|
{
|
||||||
[process.execPath.split('/').pop(), '--no-embedded=1', '--disableUpdate=1',
|
global._child = require('child_process').execFile(process.execPath, connectArgs);
|
||||||
'--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.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); });
|
||||||
|
@ -82,54 +102,72 @@ if ((msh.InstallFlags & 1) == 1) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!skip) && ((msh.InstallFlags & 2) == 2)) {
|
if ((!skip) && ((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 (!skip) {
|
if (!skip)
|
||||||
if (process.platform != 'darwin') {
|
{
|
||||||
if (process.argv.includes('-install') || process.argv.includes('-update')) {
|
if (process.platform != 'darwin')
|
||||||
|
{
|
||||||
|
if (process.argv.includes('-install') || process.argv.includes('-update'))
|
||||||
|
{
|
||||||
var p = [];
|
var p = [];
|
||||||
for (var i = 0; i < process.argv.length; ++i) {
|
for (var i = 0; i < process.argv.length; ++i)
|
||||||
if (process.argv[i].startsWith('--installPath=')) {
|
{
|
||||||
|
if (process.argv[i].startsWith('--installPath='))
|
||||||
|
{
|
||||||
p.push('--installPath="' + process.argv[i].split('=').pop() + '"');
|
p.push('--installPath="' + process.argv[i].split('=').pop() + '"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_install(p);
|
_install(p);
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
else if (process.argv.includes('-uninstall')) {
|
else if (process.argv.includes('-uninstall'))
|
||||||
|
{
|
||||||
_uninstall();
|
_uninstall();
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
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)))
|
||||||
|
{
|
||||||
console.log('\n' + "The graphical version of this installer cannot run on this system.");
|
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("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): ");
|
console.log("You can also run the text version from the command line with the following command(s): ");
|
||||||
if ((msh.InstallFlags & 1) == 1) {
|
if ((msh.InstallFlags & 1) == 1)
|
||||||
|
{
|
||||||
console.log('./' + process.execPath.split('/').pop() + ' -connect');
|
console.log('./' + process.execPath.split('/').pop() + ' -connect');
|
||||||
}
|
}
|
||||||
if ((msh.InstallFlags & 2) == 2) {
|
if ((msh.InstallFlags & 2) == 2)
|
||||||
if (s) {
|
{
|
||||||
|
if (s)
|
||||||
|
{
|
||||||
console.log('./' + process.execPath.split('/').pop() + ' -update');
|
console.log('./' + process.execPath.split('/').pop() + ' -update');
|
||||||
console.log('./' + process.execPath.split('/').pop() + ' -uninstall');
|
console.log('./' + process.execPath.split('/').pop() + ' -uninstall');
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
console.log('./' + process.execPath.split('/').pop() + ' -install');
|
console.log('./' + process.execPath.split('/').pop() + ' -install');
|
||||||
console.log('./' + process.execPath.split('/').pop() + ' -install --installPath="/alternate/path"');
|
console.log('./' + process.execPath.split('/').pop() + ' -install --installPath="/alternate/path"');
|
||||||
}
|
}
|
||||||
|
@ -139,32 +177,40 @@ if (!skip) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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 (!skip) {
|
if (!skip)
|
||||||
if (!s) {
|
{
|
||||||
|
if (!s)
|
||||||
|
{
|
||||||
msg = "Agent: " + "NOT INSTALLED" + '\n';
|
msg = "Agent: " + "NOT INSTALLED" + '\n';
|
||||||
} else {
|
} else
|
||||||
|
{
|
||||||
msg = "Agent: " + (s.isRunning() ? "RUNNING" : "NOT RUNNING") + '\n';
|
msg = "Agent: " + (s.isRunning() ? "RUNNING" : "NOT RUNNING") + '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
msg += ("Device Group: " + msh.MeshName + '\n');
|
msg += ("Device Group: " + msh.MeshName + '\n');
|
||||||
msg += ("Server URL: " + msh.MeshServer + '\n');
|
msg += ("Server URL: " + msh.MeshServer + '\n');
|
||||||
|
|
||||||
var p = require('message-box').create("MeshCentral Agent Setup", msg, 99999, buttons);
|
var p = require('message-box').create(displayName + " Setup", msg, 99999, buttons);
|
||||||
p.then(function (v) {
|
p.then(function (v)
|
||||||
switch (v) {
|
{
|
||||||
|
switch (v)
|
||||||
|
{
|
||||||
case "Cancel":
|
case "Cancel":
|
||||||
process.exit();
|
process.exit();
|
||||||
break;
|
break;
|
||||||
case 'Setup':
|
case 'Setup':
|
||||||
var d = require('message-box').create("MeshCentral Agent", msg, 99999, ['Update', 'Uninstall', 'Cancel']);
|
var d = require('message-box').create(displayName, msg, 99999, ['Update', 'Uninstall', 'Cancel']);
|
||||||
d.then(function (v) {
|
d.then(function (v)
|
||||||
switch (v) {
|
{
|
||||||
|
switch (v)
|
||||||
|
{
|
||||||
case 'Update':
|
case 'Update':
|
||||||
case 'Install':
|
case 'Install':
|
||||||
_install();
|
_install();
|
||||||
|
@ -179,28 +225,23 @@ if (!skip) {
|
||||||
}).catch(function (v) { process.exit(); });
|
}).catch(function (v) { process.exit(); });
|
||||||
break;
|
break;
|
||||||
case "Connect":
|
case "Connect":
|
||||||
global._child = require('child_process').execFile(process.execPath,
|
global._child = require('child_process').execFile(process.execPath, connectArgs);
|
||||||
[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.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 += ('\nPress OK to Disconnect');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var d = require('message-box').create("MeshCentral Agent", msg, 99999, ['Disconnect']);
|
var d = require('message-box').create(displayName, 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":
|
||||||
|
@ -217,7 +258,8 @@ if (!skip) {
|
||||||
process.exit();
|
process.exit();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}).catch(function (e) {
|
}).catch(function (e)
|
||||||
|
{
|
||||||
console.log(e);
|
console.log(e);
|
||||||
process.exit();
|
process.exit();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue