fix: add sudo fallback to agent installer + improve error output #36
@@ -49,9 +49,12 @@ class AgentService
|
|||||||
|
|
||||||
$script = file_get_contents($scriptPath);
|
$script = file_get_contents($scriptPath);
|
||||||
|
|
||||||
|
$b64 = base64_encode($script);
|
||||||
$remoteCommand = sprintf(
|
$remoteCommand = sprintf(
|
||||||
'echo %s | base64 -d | bash -s -- %s %s 2>&1',
|
'echo %s | base64 -d | (sudo -n true 2>/dev/null && sudo bash -s -- %s %s || bash -s -- %s %s) 2>&1',
|
||||||
escapeshellarg(base64_encode($script)),
|
escapeshellarg($b64),
|
||||||
|
escapeshellarg($serverUrl),
|
||||||
|
escapeshellarg($agentKey),
|
||||||
escapeshellarg($serverUrl),
|
escapeshellarg($serverUrl),
|
||||||
escapeshellarg($agentKey)
|
escapeshellarg($agentKey)
|
||||||
);
|
);
|
||||||
@@ -67,17 +70,17 @@ class AgentService
|
|||||||
|
|
||||||
$output = trim($result['output']);
|
$output = trim($result['output']);
|
||||||
$exitStatus = $result['exit_status'] ?? -1;
|
$exitStatus = $result['exit_status'] ?? -1;
|
||||||
|
$path = '/usr/local/bin/servermanager-agent';
|
||||||
|
|
||||||
if ($exitStatus !== 0) {
|
if ($exitStatus !== 0) {
|
||||||
|
$lastLines = implode("\n", array_slice(explode("\n", $output), -20));
|
||||||
return [
|
return [
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'error' => 'Agent installation failed on remote server',
|
'error' => 'Agent installation failed on remote server',
|
||||||
'output' => $output,
|
'output' => $lastLines,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = '/usr/local/bin/servermanager-agent';
|
|
||||||
|
|
||||||
$serverModel = new \ServerManager\Models\Server();
|
$serverModel = new \ServerManager\Models\Server();
|
||||||
$serverModel->setAgentInstalled($serverId, true, $path);
|
$serverModel->setAgentInstalled($serverId, true, $path);
|
||||||
|
|
||||||
@@ -116,7 +119,7 @@ class AgentService
|
|||||||
$script = file_get_contents($scriptPath);
|
$script = file_get_contents($scriptPath);
|
||||||
|
|
||||||
$remoteCommand = sprintf(
|
$remoteCommand = sprintf(
|
||||||
'echo %s | base64 -d | bash 2>&1',
|
'echo %s | base64 -d | sudo bash 2>&1',
|
||||||
escapeshellarg(base64_encode($script))
|
escapeshellarg(base64_encode($script))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -445,8 +445,9 @@ function confirmAgentAction() {
|
|||||||
showToast('success', action === 'install' ? 'Agent installed successfully.' : 'Agent uninstalled successfully.');
|
showToast('success', action === 'install' ? 'Agent installed successfully.' : 'Agent uninstalled successfully.');
|
||||||
setTimeout(() => location.reload(), 1500);
|
setTimeout(() => location.reload(), 1500);
|
||||||
} else {
|
} else {
|
||||||
showToast('error', data.error || (action === 'install' ? 'Installation failed.' : 'Uninstallation failed.'));
|
let msg = data.error || (action === 'install' ? 'Installation failed.' : 'Uninstallation failed.');
|
||||||
if (data.output) console.log('Output:', data.output);
|
if (data.output) msg += ' Output: ' + data.output.replace(/\n/g, ' | ');
|
||||||
|
showToast('error', msg);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
|||||||
Reference in New Issue
Block a user