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

1. Fixed bug in windows installer when installing when agent already installed

2. Added verbose mode for installer
This commit is contained in:
Bryan Roe
2020-09-17 17:30:16 -07:00
parent 3f4e5df9a2
commit f332ddb59c
3 changed files with 58 additions and 18 deletions

File diff suppressed because one or more lines are too long

View File

@@ -15,9 +15,26 @@ limitations under the License.
*/
function getParameter(name, parms)
{
var tokens;
for(var i=0;i<parms.length;++i)
{
tokens = parms[i].split('=');
if(tokens[0]==name)
{
if (tokens[1].startsWith('"')) { return (tokens[1].substring(1, tokens[1].length - 1)); }
return (tokens[1]);
}
}
return (null);
}
function installService(params)
{
process.stdout.write('...Installing service');
console.info1('');
var proxyFile = process.execPath;
if (process.platform == 'win32')
{
@@ -468,10 +485,18 @@ function fullUninstall(jsonString)
function fullInstall(jsonString)
{
console.setDestination(console.Destinations.DISABLED);
var parms = JSON.parse(jsonString);
var loc = null;
if (!(getParameter('--verbose', parms) != null && parseInt(getParameter('--verbose', parms)) > 0))
{
console.setDestination(console.Destinations.DISABLED);
}
else
{
console.setInfoLevel(1);
}
try
{
process.stdout.write('...Checking for previous installation');
@@ -479,6 +504,8 @@ function fullInstall(jsonString)
loc = s.appLocation();
global._workingpath = s.appWorkingDirectory();
console.info1('');
console.info1('Previous Working Path: ' + global._workingpath);
s.close();
}
catch (e)

View File

@@ -1852,35 +1852,32 @@ function serviceManager()
if (!this.isAdmin()) { throw ('Installing as Service, requires admin'); }
// Before we start, we need to copy the binary to the right place
var folder;
if(!options.installPath)
{
options.installPath = this.getProgramFolder();
switch(options.companyName)
{
case null:
options.installPath += '\\mesh';
options.installPath += ('\\mesh\\' + options.name + '\\');
break;
case '':
options.installPath += ('\\' + options.name + '\\');
break;
default:
options.installPath += ('\\' + options.companyName);
options.installPath += ('\\' + options.companyName + '\\' + options.name + '\\');
break;
}
}
folder = options.installPath;
if (folder.endsWith('\\')) { folder = folder.substring(0, folder.length - 1); }
if (!options.installInPlace) { prepareFolders(folder + '\\' + options.name); }
if (!options.installInPlace) { prepareFolders(options.installPath); }
if (options.servicePath == process.execPath) { options._isMeshAgent = true; }
if (!options.installInPlace)
{
if (options.servicePath != folder + '\\' + options.name + '\\' + options.target + '.exe')
if (options.servicePath != (options.installPath + options.target + '.exe'))
{
require('fs').copyFileSync(options.servicePath, folder + '\\' + options.name + '\\' + options.target + '.exe');
require('fs').copyFileSync(options.servicePath, options.installPath + options.target + '.exe');
}
options.servicePath = folder + '\\' + options.name + '\\' + options.target + '.exe';
options.installPath = folder + '\\' + options.name + '\\';
options.servicePath = options.installPath + options.target + '.exe';
}
else
{
@@ -1890,9 +1887,12 @@ function serviceManager()
options.installPath = options.installPath.join('\\') + '\\';
}
console.info1(' Install Path = ' + options.installPath);
console.info1(' OpenSCManagerA()');
var servicePath = this.GM.CreateVariable('"' + options.servicePath + '"', { wide: true });
var handle = this.proxy.OpenSCManagerA(0x00, 0x00, 0x0002);
if (handle.Val == 0) { throw ('error opening SCManager'); }
console.info1(' => SUCCESS');
var serviceName = this.GM.CreateVariable(options.name, { wide: true });
var displayName = this.GM.CreateVariable(options.displayName, { wide: true});
var allAccess = 0x000F01FF;
@@ -1902,18 +1902,24 @@ function serviceManager()
switch (options.startType) {
case 'AUTO_START':
serviceType = 0x02; // Automatic
console.info1(' startType = automatic');
break;
case 'DEMAND_START':
default:
serviceType = 0x03; // Manual
console.info1(' startType = manual');
break;
case 'DISABLED':
serviceType = 0x04; // Disabled
console.info1(' startType = disabled');
break;
}
console.info1(' CreateServiceW()');
var h = this.proxy.CreateServiceW(handle, serviceName, displayName, allAccess, 0x10 | 0x100, serviceType, 0, servicePath, 0, 0, 0, 0, 0);
if (h.Val == 0) { this.proxy.CloseServiceHandle(handle); throw ('Error Creating Service: ' + this.proxy2.GetLastError().Val); }
console.info1(' => SUCCESS');
if (options.description)
{
var dsc = this.GM.CreateVariable(options.description, { wide: true });
@@ -1950,9 +1956,16 @@ function serviceManager()
if (options.parameters)
{
var imagePath = reg.QueryKey(reg.HKEY.LocalMachine, 'SYSTEM\\CurrentControlSet\\Services\\' + options.name, 'ImagePath');
imagePath += (' ' + options.parameters.join(' '));
reg.WriteKey(reg.HKEY.LocalMachine, 'SYSTEM\\CurrentControlSet\\Services\\' + options.name, 'ImagePath', imagePath);
try
{
var imagePath = reg.QueryKey(reg.HKEY.LocalMachine, 'SYSTEM\\CurrentControlSet\\Services\\' + options.name, 'ImagePath');
imagePath += (' ' + options.parameters.join(' '));
reg.WriteKey(reg.HKEY.LocalMachine, 'SYSTEM\\CurrentControlSet\\Services\\' + options.name, 'ImagePath', imagePath);
}
catch(xxx)
{
console.info1(xxx);
}
}
try