1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-22 11:13:21 +00:00

Added ability to specify RecoveryCore location

This commit is contained in:
Bryan Roe
2022-06-28 00:20:16 -07:00
parent 160b4b946d
commit fb6a935782

View File

@@ -79,12 +79,22 @@ var updateState = 0;
var agentBinaryFD = null; var agentBinaryFD = null;
var agentBinary_Size = 0; var agentBinary_Size = 0;
var agentBinary_BytesSent = 0; var agentBinary_BytesSent = 0;
const recoveryCore = require('fs').readFileSync('recoverycore.js');
var cycleCount = -1; var cycleCount = -1;
var targetCount = 1; var targetCount = 1;
var delayMinimum = 0; var delayMinimum = 0;
var delayMaximum = 100; var delayMaximum = 100;
var recoverycorePath = process.argv.getParameter('RecoveryCore', '');
if (recoverycorePath.endsWith('\\')) { var x = recoverycorePath.split('\\'); x.pop(); recoverycorePath = x.join('\\'); }
if (recoverycorePath.endsWith('/')) { var x = recoverycorePath.split('/'); x.pop(); recoverycorePath = x.join('/'); }
if (recoverycorePath == '')
{
recoverycorePath = 'recoverycore.js';
}
else
{
recoverycorePath += (process.platform == 'win32' ? '\\recoverycore.js' : '/recoverycore.js');
}
// Check Permissions... Need Root/Elevated Permissions // Check Permissions... Need Root/Elevated Permissions
if (!require('user-sessions').isRoot()) if (!require('user-sessions').isRoot())
@@ -104,10 +114,20 @@ if (process.argv.getParameter('help') != null)
console.log(' binary, and the specified binary, up until CycleCount cycles are completed.'); console.log(' binary, and the specified binary, up until CycleCount cycles are completed.');
console.log(' --JS If specified, update-test will utilize the recoverycore to perform the update'); console.log(' --JS If specified, update-test will utilize the recoverycore to perform the update');
console.log(' rather than the native update mechanism.'); console.log(' rather than the native update mechanism.');
console.log(' --RecoveryCore= Path to where recoverycore.js can be found. Default is the current folder.');
console.log(''); console.log('');
process.exit(); process.exit();
} }
if (!require('fs').existsSync(recoverycorePath))
{
console.log(recoverycorePath + ' cannot be found.');
console.log('Please either copy recoverycore.js, or specify the location using --RecoveryCore');
process.exit();
}
const recoveryCore = require('fs').readFileSync(recoverycorePath);
process.stdout.write('Generating Certificate...'); process.stdout.write('Generating Certificate...');
var cert = require('tls').generateCertificate('test', { certType: 2, noUsages: 1 }); var cert = require('tls').generateCertificate('test', { certType: 2, noUsages: 1 });
var server = require('https').createServer({ pfx: cert, passphrase: 'test' }); var server = require('https').createServer({ pfx: cert, passphrase: 'test' });
@@ -402,9 +422,13 @@ server.on('upgrade', function (msg, sck, head)
var hash = buffer.slice(4).toString('hex'); var hash = buffer.slice(4).toString('hex');
if (updateState < 99) { console.log('CoreModuleHash[' + hash.length + ']=' + hash); } if (updateState < 99) { console.log('CoreModuleHash[' + hash.length + ']=' + hash); }
if (process.argv.getParameter('NoInstall') == null && updateState<99) if (process.argv.getParameter('NoInstall') == null && updateState<99)
{
var pid = getPID();
if (pid != 0)
{ {
console.log('Service PID: ' + getPID()); console.log('Service PID: ' + getPID());
} }
}
if (process.argv.getParameter('JS') != null) if (process.argv.getParameter('JS') != null)
{ {
@@ -454,6 +478,9 @@ server.on('upgrade', function (msg, sck, head)
this.write(b); this.write(b);
} }
break; break;
case MeshCommand_AuthConfirm:
console.log('Agent Authenticated');
break;
default: default:
console.log('Command: ' + cmd); console.log('Command: ' + cmd);
break; break;
@@ -595,7 +622,16 @@ function getPID()
s.close(); s.close();
break; break;
default: default:
ret = 0; if (s.pid != null)
{
try
{
ret = s.pid();
}
catch (x)
{
}
}
break; break;
} }