1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-06 00:13:33 +00:00

Fixed Installer/Uninstaller

1. Remapped -fulluninstall to -funinstall
2. Updated behavior so db is not loaded if agent-installer is invoked
3. Renamed Windows Uninstaller from MeshCentralAgent to Mesh Agent for consistency
4. Update service-manager.installService(), such that if the service is the mesh agent, the windows uninstaller will invoke -fulluninstall
5. Updated agent-installer so that secondary agent and its scheduled tasks will be deleted on uninstall
6. Updated event-emitter, so if process.exit() is called on an emit(), it won't throw a catchable exception
This commit is contained in:
Bryan Roe
2020-04-07 00:03:11 -07:00
parent d1fcb0cd61
commit b8208f63ed
6 changed files with 123 additions and 52 deletions

View File

@@ -3894,26 +3894,6 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
// We are a Mesh Agent
if (agentHost->masterDb == NULL) { agentHost->masterDb = ILibSimpleDataStore_Create(MeshAgent_MakeAbsolutePath(agentHost->exePath, ".db")); }
if (agentHost->masterDb == NULL)
{
void **data = (void**)ILibScratchPad;
data[0] = agentHost;
((int*)&(data[1]))[0] = paramLen;
data[2] = param;
((int*)&(data[3]))[0] = parseCommands;
switch (agentHost->dbRetryCount)
{
case 10:
printf("Unable to open database.\r\n");
return 0;
default:
printf("Unable to open database (%d/10)...\r\n", agentHost->dbRetryCount + 1);
agentHost->dbRetryCount++;
ILibLifeTime_AddEx(ILibGetBaseTimer(agentHost->chain), data, 2000, MeshAgent_AgentMost_dbRetryCallback, NULL);
return 1;
}
}
int ixr = 0;
int installFlag = 0;
@@ -3930,7 +3910,7 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
{
installFlag = 1;
}
if (strcmp("-funinstall", param[ri]) == 0)
if (strcmp("-funinstall", param[ri]) == 0 || strcmp("-fulluninstall", param[ri]) == 0)
{
installFlag = 2;
}
@@ -3991,6 +3971,29 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
duk_destroy_heap(ctxx);
}
else
{
if (agentHost->masterDb == NULL)
{
void **data = (void**)ILibScratchPad;
data[0] = agentHost;
((int*)&(data[1]))[0] = paramLen;
data[2] = param;
((int*)&(data[3]))[0] = parseCommands;
switch (agentHost->dbRetryCount)
{
case 10:
printf("Unable to open database.\r\n");
return 0;
default:
printf("Unable to open database (%d/10)...\r\n", agentHost->dbRetryCount + 1);
agentHost->dbRetryCount++;
ILibLifeTime_AddEx(ILibGetBaseTimer(agentHost->chain), data, 2000, MeshAgent_AgentMost_dbRetryCallback, NULL);
return 1;
}
}
}
agentHost->httpClientManager = ILibCreateWebClient(3, agentHost->chain);

View File

@@ -218,7 +218,7 @@ void WINAPI AddUninstallIcon()
int i;
HKEY hKey;
if (RegCreateKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MeshCentralAgent", &hKey) == ERROR_SUCCESS)
if (RegCreateKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Mesh Agent", &hKey) == ERROR_SUCCESS)
{
LPCTSTR str;
char targetexe[_MAX_PATH + 40];
@@ -953,7 +953,7 @@ int wmain(int argc, char* wargv[])
WideCharToMultiByte(CP_UTF8, 0, (LPCWCH)wargv[argvi], -1, argv[argvi], argvsz, NULL, NULL);
}
if (argc > 1 && (strcasecmp(argv[1], "-finstall") == 0 || strcasecmp(argv[1], "-funinstall") == 0))
if (argc > 1 && (strcasecmp(argv[1], "-finstall") == 0 || strcasecmp(argv[1], "-funinstall") == 0 || strcasecmp(argv[1], "-fulluninstall") == 0))
{
argv[argc] = argv[1];
argv[1] = (char*)ILibMemory_SmartAllocate(4);

File diff suppressed because one or more lines are too long

View File

@@ -233,13 +233,22 @@ duk_ret_t ILibDuktape_EventEmitter_emit(duk_context *ctx)
if (emitList[i].once != 0)
{
// Delete reference to callback function
duk_push_heapptr(ctx, data->tmpObject);
duk_push_heapptr(ctx, data->tmpObject);
duk_del_prop_string(ctx, -1, Duktape_GetStashKey(func));
duk_pop(ctx);
}
duk_push_heapptr(ctx, func); // [func]
return(ILibDuktape_Error(ctx, "EventEmitter.emit(): Event dispatch for '%s' on '%s' threw an exception: %s in method '%s()'", name, objid, duk_safe_to_string(ctx, -2), Duktape_GetStringPropertyValue(ctx, -1, "name", "unknown_method")));
if (strcmp(duk_safe_to_string(ctx, -2), "Process.exit() forced script termination") == 0)
{
duk_dup(ctx, -2);
duk_throw(ctx);
return(DUK_RET_ERROR);
}
else
{
return(ILibDuktape_Error(ctx, "EventEmitter.emit(): Event dispatch for '%s' on '%s' threw an exception: %s in method '%s()'", name, objid, duk_safe_to_string(ctx, -2), Duktape_GetStringPropertyValue(ctx, -1, "name", "unknown_method")));
}
}
if (emitList[i].once != 0)

View File

@@ -136,18 +136,9 @@ function installService(params)
if (process.platform == 'win32') { svc.close(); }
process.exit();
}
function uninstallService2(params)
function uninstallService3(params)
{
process.stdout.write(' -> Uninstalling previous installation...');
try
{
require('service-manager').manager.uninstallService(process.platform == 'win32' ? 'Mesh Agent' : 'meshagent');
process.stdout.write(' [DONE]\n');
}
catch (e)
{
process.stdout.write(' [ERROR]\n');
}
if (process.platform == 'darwin')
{
process.stdout.write(' -> Uninstalling launch agent...');
@@ -172,6 +163,67 @@ function uninstallService2(params)
process.exit();
}
}
function uninstallService2(params)
{
var secondaryagent = false;
process.stdout.write(' -> Uninstalling previous installation...');
try
{
require('service-manager').manager.uninstallService(process.platform == 'win32' ? 'Mesh Agent' : 'meshagent');
process.stdout.write(' [DONE]\n');
}
catch (e)
{
process.stdout.write(' [ERROR]\n');
}
// Check for secondary agent
try
{
process.stdout.write(' -> Checking for secondary agent...');
var s = require('service-manager').manager.getService('meshagentDiagnostic');
var loc = s.appLocation();
s.close();
process.stdout.write(' [FOUND]\n');
process.stdout.write(' -> Uninstalling secondary agent...');
secondaryagent = true;
try
{
require('service-manager').manager.uninstallService('meshagentDiagnostic');
process.stdout.write(' [DONE]\n');
}
catch (e)
{
process.stdout.write(' [ERROR]\n');
}
}
catch (e)
{
process.stdout.write(' [NONE]\n');
}
if(secondaryagent)
{
process.stdout.write(' -> removing secondary agent from task scheduler...');
var p = require('task-scheduler').delete('meshagentDiagnostic/periodicStart');
p._params = params;
p.then(function ()
{
process.stdout.write(' [DONE]\n');
uninstallService3(this._params);
}, function ()
{
process.stdout.write(' [ERROR]\n');
uninstallService3(this._params);
});
}
else
{
uninstallService3(params);
}
}
function uninstallService(params)
{
var svc = require('service-manager').manager.getService(process.platform == 'win32' ? 'Mesh Agent' : 'meshagent');

View File

@@ -1676,7 +1676,14 @@ function serviceManager()
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'EstimatedSize', Math.floor(require('fs').statSync(folder + '\\' + options.name + '\\' + options.target + '.exe').size / 1024));
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'NoModify', 0x1);
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'NoRepair', 0x1);
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'UninstallString', folder + '\\' + options.name + '\\' + options.target + '.exe -b64exec ' + script);
if (options.name == 'Mesh Agent')
{
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'UninstallString', folder + '\\' + options.name + '\\' + options.target + '.exe -funinstall');
}
else
{
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'UninstallString', folder + '\\' + options.name + '\\' + options.target + '.exe -b64exec ' + script);
}
}
catch (xx)
{