mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-14 23:33:38 +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:
@@ -3894,26 +3894,6 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
|
|||||||
|
|
||||||
// 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")); }
|
||||||
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 ixr = 0;
|
||||||
int installFlag = 0;
|
int installFlag = 0;
|
||||||
@@ -3930,7 +3910,7 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
|
|||||||
{
|
{
|
||||||
installFlag = 1;
|
installFlag = 1;
|
||||||
}
|
}
|
||||||
if (strcmp("-funinstall", param[ri]) == 0)
|
if (strcmp("-funinstall", param[ri]) == 0 || strcmp("-fulluninstall", param[ri]) == 0)
|
||||||
{
|
{
|
||||||
installFlag = 2;
|
installFlag = 2;
|
||||||
}
|
}
|
||||||
@@ -3991,6 +3971,29 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
|
|||||||
|
|
||||||
duk_destroy_heap(ctxx);
|
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);
|
agentHost->httpClientManager = ILibCreateWebClient(3, agentHost->chain);
|
||||||
|
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ void WINAPI AddUninstallIcon()
|
|||||||
|
|
||||||
int i;
|
int i;
|
||||||
HKEY hKey;
|
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;
|
LPCTSTR str;
|
||||||
char targetexe[_MAX_PATH + 40];
|
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);
|
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[argc] = argv[1];
|
||||||
argv[1] = (char*)ILibMemory_SmartAllocate(4);
|
argv[1] = (char*)ILibMemory_SmartAllocate(4);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -239,8 +239,17 @@ duk_ret_t ILibDuktape_EventEmitter_emit(duk_context *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
duk_push_heapptr(ctx, func); // [func]
|
duk_push_heapptr(ctx, func); // [func]
|
||||||
|
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")));
|
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)
|
if (emitList[i].once != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -136,18 +136,9 @@ function installService(params)
|
|||||||
if (process.platform == 'win32') { svc.close(); }
|
if (process.platform == 'win32') { svc.close(); }
|
||||||
process.exit();
|
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')
|
if (process.platform == 'darwin')
|
||||||
{
|
{
|
||||||
process.stdout.write(' -> Uninstalling launch agent...');
|
process.stdout.write(' -> Uninstalling launch agent...');
|
||||||
@@ -172,6 +163,67 @@ function uninstallService2(params)
|
|||||||
process.exit();
|
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)
|
function uninstallService(params)
|
||||||
{
|
{
|
||||||
var svc = require('service-manager').manager.getService(process.platform == 'win32' ? 'Mesh Agent' : 'meshagent');
|
var svc = require('service-manager').manager.getService(process.platform == 'win32' ? 'Mesh Agent' : 'meshagent');
|
||||||
|
|||||||
@@ -1676,8 +1676,15 @@ 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, '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, '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, 'NoRepair', 0x1);
|
||||||
|
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);
|
reg.WriteKey(reg.HKEY.LocalMachine, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\' + options.name, 'UninstallString', folder + '\\' + options.name + '\\' + options.target + '.exe -b64exec ' + script);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (xx)
|
catch (xx)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user