mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-11-07 23:43:54 +00:00
Script actually downloads on deb systems (i only use deb, sm1 else will have to test the other distros)
This commit is contained in:
@@ -50,24 +50,25 @@ router.get('/agent/download', async (req, res) => {
|
|||||||
|
|
||||||
// Use script content from database if available, otherwise fallback to file
|
// Use script content from database if available, otherwise fallback to file
|
||||||
if (agentVersion.script_content) {
|
if (agentVersion.script_content) {
|
||||||
|
// Convert Windows line endings to Unix line endings
|
||||||
|
const scriptContent = agentVersion.script_content.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
||||||
res.setHeader('Content-Type', 'application/x-shellscript');
|
res.setHeader('Content-Type', 'application/x-shellscript');
|
||||||
res.setHeader('Content-Disposition', `attachment; filename="patchmon-agent-${agentVersion.version}.sh"`);
|
res.setHeader('Content-Disposition', `attachment; filename="patchmon-agent-${agentVersion.version}.sh"`);
|
||||||
res.send(agentVersion.script_content);
|
res.send(scriptContent);
|
||||||
} else {
|
} else {
|
||||||
// Fallback to file system
|
// Fallback to file system
|
||||||
const agentPath = path.join(__dirname, '../../../agents/patchmon-agent.sh');
|
const agentPath = path.join(__dirname, '../../../agents/patchmon-agent.sh');
|
||||||
|
|
||||||
if (!fs.existsSync(agentPath)) {
|
if (!fs.existsSync(agentPath)) {
|
||||||
return res.status(404).json({error: 'Agent script not found'});
|
return res.status(404).json({error: 'Agent script not found'});
|
||||||
}
|
}
|
||||||
|
// Read file and convert line endings
|
||||||
|
const scriptContent = fs.readFileSync(agentPath, 'utf8').replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
||||||
res.setHeader('Content-Type', 'application/x-shellscript');
|
res.setHeader('Content-Type', 'application/x-shellscript');
|
||||||
res.setHeader('Content-Disposition', `attachment; filename="patchmon-agent-${agentVersion.version}.sh"`);
|
res.setHeader('Content-Disposition', `attachment; filename="patchmon-agent-${agentVersion.version}.sh"`);
|
||||||
res.sendFile(path.resolve(agentPath));
|
res.send(scriptContent);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Agent download error:', error);
|
console.error('Agent download error:', error);
|
||||||
res.status(500).json({ error: 'Failed to download agent script' });
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -832,6 +833,9 @@ router.get('/install', async (req, res) => {
|
|||||||
|
|
||||||
let script = fs.readFileSync(scriptPath, 'utf8');
|
let script = fs.readFileSync(scriptPath, 'utf8');
|
||||||
|
|
||||||
|
// Convert Windows line endings to Unix line endings
|
||||||
|
script = script.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
||||||
|
|
||||||
// Get the configured server URL from settings
|
// Get the configured server URL from settings
|
||||||
try {
|
try {
|
||||||
const settings = await prisma.settings.findFirst();
|
const settings = await prisma.settings.findFirst();
|
||||||
|
|||||||
Reference in New Issue
Block a user