mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-15 07:43:50 +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:
File diff suppressed because one or more lines are too long
@@ -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)
|
function installService(params)
|
||||||
{
|
{
|
||||||
process.stdout.write('...Installing service');
|
process.stdout.write('...Installing service');
|
||||||
|
console.info1('');
|
||||||
|
|
||||||
var proxyFile = process.execPath;
|
var proxyFile = process.execPath;
|
||||||
if (process.platform == 'win32')
|
if (process.platform == 'win32')
|
||||||
{
|
{
|
||||||
@@ -468,10 +485,18 @@ function fullUninstall(jsonString)
|
|||||||
|
|
||||||
function fullInstall(jsonString)
|
function fullInstall(jsonString)
|
||||||
{
|
{
|
||||||
console.setDestination(console.Destinations.DISABLED);
|
|
||||||
var parms = JSON.parse(jsonString);
|
var parms = JSON.parse(jsonString);
|
||||||
var loc = null;
|
var loc = null;
|
||||||
|
|
||||||
|
if (!(getParameter('--verbose', parms) != null && parseInt(getParameter('--verbose', parms)) > 0))
|
||||||
|
{
|
||||||
|
console.setDestination(console.Destinations.DISABLED);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
console.setInfoLevel(1);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
process.stdout.write('...Checking for previous installation');
|
process.stdout.write('...Checking for previous installation');
|
||||||
@@ -479,6 +504,8 @@ function fullInstall(jsonString)
|
|||||||
loc = s.appLocation();
|
loc = s.appLocation();
|
||||||
|
|
||||||
global._workingpath = s.appWorkingDirectory();
|
global._workingpath = s.appWorkingDirectory();
|
||||||
|
console.info1('');
|
||||||
|
console.info1('Previous Working Path: ' + global._workingpath);
|
||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
|
|||||||
@@ -1852,35 +1852,32 @@ 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;
|
|
||||||
if(!options.installPath)
|
if(!options.installPath)
|
||||||
{
|
{
|
||||||
options.installPath = this.getProgramFolder();
|
options.installPath = this.getProgramFolder();
|
||||||
switch(options.companyName)
|
switch(options.companyName)
|
||||||
{
|
{
|
||||||
case null:
|
case null:
|
||||||
options.installPath += '\\mesh';
|
options.installPath += ('\\mesh\\' + options.name + '\\');
|
||||||
break;
|
break;
|
||||||
case '':
|
case '':
|
||||||
|
options.installPath += ('\\' + options.name + '\\');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
options.installPath += ('\\' + options.companyName);
|
options.installPath += ('\\' + options.companyName + '\\' + options.name + '\\');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
folder = options.installPath;
|
if (!options.installInPlace) { prepareFolders(options.installPath); }
|
||||||
if (folder.endsWith('\\')) { folder = folder.substring(0, folder.length - 1); }
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
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.servicePath = options.installPath + options.target + '.exe';
|
||||||
options.installPath = folder + '\\' + options.name + '\\';
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1890,9 +1887,12 @@ function serviceManager()
|
|||||||
options.installPath = options.installPath.join('\\') + '\\';
|
options.installPath = options.installPath.join('\\') + '\\';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.info1(' Install Path = ' + options.installPath);
|
||||||
|
console.info1(' OpenSCManagerA()');
|
||||||
var servicePath = this.GM.CreateVariable('"' + options.servicePath + '"', { wide: true });
|
var servicePath = this.GM.CreateVariable('"' + options.servicePath + '"', { wide: true });
|
||||||
var handle = this.proxy.OpenSCManagerA(0x00, 0x00, 0x0002);
|
var handle = this.proxy.OpenSCManagerA(0x00, 0x00, 0x0002);
|
||||||
if (handle.Val == 0) { throw ('error opening SCManager'); }
|
if (handle.Val == 0) { throw ('error opening SCManager'); }
|
||||||
|
console.info1(' => SUCCESS');
|
||||||
var serviceName = this.GM.CreateVariable(options.name, { wide: true });
|
var serviceName = this.GM.CreateVariable(options.name, { wide: true });
|
||||||
var displayName = this.GM.CreateVariable(options.displayName, { wide: true});
|
var displayName = this.GM.CreateVariable(options.displayName, { wide: true});
|
||||||
var allAccess = 0x000F01FF;
|
var allAccess = 0x000F01FF;
|
||||||
@@ -1902,18 +1902,24 @@ function serviceManager()
|
|||||||
switch (options.startType) {
|
switch (options.startType) {
|
||||||
case 'AUTO_START':
|
case 'AUTO_START':
|
||||||
serviceType = 0x02; // Automatic
|
serviceType = 0x02; // Automatic
|
||||||
|
console.info1(' startType = automatic');
|
||||||
break;
|
break;
|
||||||
case 'DEMAND_START':
|
case 'DEMAND_START':
|
||||||
default:
|
default:
|
||||||
serviceType = 0x03; // Manual
|
serviceType = 0x03; // Manual
|
||||||
|
console.info1(' startType = manual');
|
||||||
break;
|
break;
|
||||||
case 'DISABLED':
|
case 'DISABLED':
|
||||||
serviceType = 0x04; // Disabled
|
serviceType = 0x04; // Disabled
|
||||||
|
console.info1(' startType = disabled');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.info1(' CreateServiceW()');
|
||||||
var h = this.proxy.CreateServiceW(handle, serviceName, displayName, allAccess, 0x10 | 0x100, serviceType, 0, servicePath, 0, 0, 0, 0, 0);
|
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); }
|
if (h.Val == 0) { this.proxy.CloseServiceHandle(handle); throw ('Error Creating Service: ' + this.proxy2.GetLastError().Val); }
|
||||||
|
console.info1(' => SUCCESS');
|
||||||
|
|
||||||
if (options.description)
|
if (options.description)
|
||||||
{
|
{
|
||||||
var dsc = this.GM.CreateVariable(options.description, { wide: true });
|
var dsc = this.GM.CreateVariable(options.description, { wide: true });
|
||||||
@@ -1950,9 +1956,16 @@ function serviceManager()
|
|||||||
|
|
||||||
if (options.parameters)
|
if (options.parameters)
|
||||||
{
|
{
|
||||||
var imagePath = reg.QueryKey(reg.HKEY.LocalMachine, 'SYSTEM\\CurrentControlSet\\Services\\' + options.name, 'ImagePath');
|
try
|
||||||
imagePath += (' ' + options.parameters.join(' '));
|
{
|
||||||
reg.WriteKey(reg.HKEY.LocalMachine, 'SYSTEM\\CurrentControlSet\\Services\\' + options.name, 'ImagePath', imagePath);
|
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
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user