1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-22 19:23:31 +00:00

1. Updated default install path for Windows agent-installer

2. Fixed installer, so it doens't create an empty .db file
3. Updated uninstaller, so it deletes the folder if it's empty
This commit is contained in:
Bryan Roe
2020-06-02 16:53:56 -07:00
parent a0cda3989c
commit 28e8a8db81
4 changed files with 73 additions and 31 deletions

View File

@@ -4043,6 +4043,17 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
#endif #endif
} }
for (ri = 0; ri < paramLen; ++ri)
{
if (strcmp("-finstall", param[ri]) == 0 || strcmp("-funinstall", param[ri]) == 0 ||
strcmp("-fullinstall", param[ri]) == 0 || strcmp("-fulluninstall", param[ri]) == 0 ||
strcmp("-install", param[ri]) == 0 || strcmp("-uninstall", param[ri]) == 0)
{
// Create a readonly DB, because we don't need to persist anything
agentHost->masterDb = ILibSimpleDataStore_CreateCachedOnly();
break;
}
}
// We are a Mesh Agent // We are a Mesh Agent
if (agentHost->masterDb == NULL) { agentHost->masterDb = ILibSimpleDataStore_Create(MeshAgent_MakeAbsolutePath(agentHost->exePath, ".db")); } if (agentHost->masterDb == NULL) { agentHost->masterDb = ILibSimpleDataStore_Create(MeshAgent_MakeAbsolutePath(agentHost->exePath, ".db")); }
@@ -4066,13 +4077,11 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
if (strcmp("-install", param[ri]) == 0) if (strcmp("-install", param[ri]) == 0)
{ {
installFlag = 5; installFlag = 5;
if (agentHost->masterDb == NULL && installFlag != 0) { agentHost->masterDb = ILibSimpleDataStore_CreateCachedOnly(); }
ILibSimpleDataStore_Cached(agentHost->masterDb, "_localService", 13, "1", 1); ILibSimpleDataStore_Cached(agentHost->masterDb, "_localService", 13, "1", 1);
} }
if (strcmp("-funinstall", param[ri]) == 0 || strcmp("-fulluninstall", param[ri]) == 0) if (strcmp("-funinstall", param[ri]) == 0 || strcmp("-fulluninstall", param[ri]) == 0)
{ {
installFlag = 2; installFlag = 2;
if (agentHost->masterDb == NULL && installFlag != 0) { agentHost->masterDb = ILibSimpleDataStore_CreateCachedOnly(); }
ILibSimpleDataStore_Cached(agentHost->masterDb, "_deleteData", 11, "1", 1); ILibSimpleDataStore_Cached(agentHost->masterDb, "_deleteData", 11, "1", 1);
} }
if (strcmp("-uninstall", param[ri]) == 0) if (strcmp("-uninstall", param[ri]) == 0)
@@ -4080,10 +4089,10 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
installFlag = 2; installFlag = 2;
} }
if (agentHost->masterDb == NULL && installFlag != 0) { agentHost->masterDb = ILibSimpleDataStore_CreateCachedOnly(); }
if ((ix = ILibString_IndexOf(param[ri], len, "=", 1)) > 2 && strncmp(param[ri], "--", 2) == 0) if ((ix = ILibString_IndexOf(param[ri], len, "=", 1)) > 2 && strncmp(param[ri], "--", 2) == 0)
{ {
if (agentHost->masterDb != NULL) { ILibSimpleDataStore_Cached(agentHost->masterDb, param[ri] + 2, ix - 2, param[ri] + ix + 1, len - (ix + 1)); } if (agentHost->masterDb == NULL) { agentHost->masterDb = ILibSimpleDataStore_CreateCachedOnly(); }
ILibSimpleDataStore_Cached(agentHost->masterDb, param[ri] + 2, ix - 2, param[ri] + ix + 1, len - (ix + 1));
++ixr; ++ixr;
} }
} }

File diff suppressed because one or more lines are too long

View File

@@ -29,6 +29,8 @@ function installService(params)
startType: 'AUTO_START', startType: 'AUTO_START',
parameters: params parameters: params
}; };
if (process.platform == 'win32') { options.companyName = ''; }
var i; var i;
if ((i=params.indexOf('--_localService="1"'))>=0) if ((i=params.indexOf('--_localService="1"'))>=0)
{ {
@@ -46,8 +48,14 @@ function installService(params)
options.installInPlace = false; options.installInPlace = false;
break; break;
} }
if (options.parameters[i].startsWith('--companyName='))
{
options.companyName = options.parameters[i].split('=')[1];
if (options.companyName.startsWith('"')) { options.companyName = options.companyName.substring(1, options.companyName.length - 1); }
options.parameters.splice(i, 1);
break;
}
} }
try try
{ {
require('service-manager').manager.installService(options); require('service-manager').manager.installService(options);
@@ -220,17 +228,27 @@ function uninstallService2(params)
process.stdout.write(' -> Deleting agent data...'); process.stdout.write(' -> Deleting agent data...');
if (process.platform != 'win32') if (process.platform != 'win32')
{ {
var levelUp = dataFolder.split('/');
levelUp.pop();
levelUp = levelUp.join('/');
var child = require('child_process').execFile('/bin/sh', ['sh']); var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.on('data', function (c) { }); child.stdout.on('data', function (c) { });
child.stderr.on('data', function (c) { }); child.stderr.on('data', function (c) { });
child.stdin.write('cd ' + dataFolder + '\n'); child.stdin.write('cd ' + dataFolder + '\n');
child.stdin.write('rm ' + appPrefix + '.*\r\n'); child.stdin.write('rm ' + appPrefix + '.*\n');
child.stdin.write('cd /\n');
child.stdin.write('rmdir ' + dataFolder + '\n');
child.stdin.write('rmdir ' + levelUp + '\n');
child.stdin.write('exit\n'); child.stdin.write('exit\n');
child.waitExit(); child.waitExit();
} }
else else
{ {
var child = require('child_process').execFile(process.env['windir'] + '\\system32\\cmd.exe', ['/C del "' + dataFolder + '\\' + appPrefix + '.*"']); var levelUp = dataFolder.split('\\');
levelUp.pop();
levelUp = levelUp.join('\\');
var child = require('child_process').execFile(process.env['windir'] + '\\system32\\cmd.exe', ['/C del "' + dataFolder + '\\' + appPrefix + '.*" && rmdir "' + dataFolder + '" && rmdir "' + levelUp + '"']);
child.stdout.on('data', function (c) { }); child.stdout.on('data', function (c) { });
child.stderr.on('data', function (c) { }); child.stderr.on('data', function (c) { });
child.waitExit(); child.waitExit();

View File

@@ -54,7 +54,7 @@ function extractFileSource(filePath)
return (typeof (filePath) == 'string' ? filePath : filePath.source); return (typeof (filePath) == 'string' ? filePath : filePath.source);
} }
function perpareFolders(folderPath) function prepareFolders(folderPath)
{ {
var dlmtr = process.platform == 'win32' ? '\\' : '/'; var dlmtr = process.platform == 'win32' ? '\\' : '/';
@@ -570,7 +570,6 @@ function serviceManager()
// 32 bit Windows // 32 bit Windows
return process.env['ProgramFiles']; return process.env['ProgramFiles'];
}; };
this.getServiceFolder = function getServiceFolder() { return this.getProgramFolder() + '\\mesh'; };
this.enumerateService = function () { this.enumerateService = function () {
var machineName = this.GM.CreatePointer(); var machineName = this.GM.CreatePointer();
@@ -1577,9 +1576,25 @@ function serviceManager()
if (!this.isAdmin()) { throw ('Installing as Service, requires admin'); } if (!this.isAdmin()) { throw ('Installing as Service, requires admin'); }
// Before we start, we need to copy the binary to the right place // Before we start, we need to copy the binary to the right place
var folder = options.installPath == null ? this.getServiceFolder() : options.installPath; var folder;
if(!options.installPath)
{
options.installPath = this.getProgramFolder();
switch(options.companyName)
{
case null:
options.installPath += '\\mesh';
break;
case '':
break;
default:
options.installPath += ('\\' + options.companyName);
break;
}
}
folder = options.installPath;
if (folder.endsWith('\\')) { folder = folder.substring(0, folder.length - 1); } if (folder.endsWith('\\')) { folder = folder.substring(0, folder.length - 1); }
if (!options.installInPlace) { perpareFolders(folder + '\\' + options.name); } if (!options.installInPlace) { prepareFolders(folder + '\\' + options.name); }
if (options.servicePath == process.execPath) { options._isMeshAgent = true; } if (options.servicePath == process.execPath) { options._isMeshAgent = true; }
if (!options.installInPlace) if (!options.installInPlace)