fix: installer self-elevates with script PTY instead of external sudo chain

- agent-install.sh and agent-uninstall.sh now detect if running as root
  at startup and re-execute via 'script -qc sudo bash' if needed
- AgentService commands simplified: just write to /tmp and run bash,
  the scripts handle privilege escalation internally
- Fixes exit code propagation: the script's exit code now correctly
  flows back through exec -> script -> sudo -> bash -> SSH
This commit is contained in:
2026-06-11 19:07:14 -04:00
parent 0ce24c4b8f
commit 0edc882f2e
3 changed files with 18 additions and 6 deletions

View File

@@ -51,11 +51,9 @@ class AgentService
$b64 = base64_encode($script);
$remoteCommand = sprintf(
'echo %s | base64 -d > /tmp/_sm_install.sh && chmod +x /tmp/_sm_install.sh && (script -q -c "sudo bash /tmp/_sm_install.sh %s %s" /dev/null < /dev/null 2>/dev/null || sudo bash /tmp/_sm_install.sh %s %s) 2>&1; rc=$?; rm -f /tmp/_sm_install.sh; exit $rc',
'echo %s | base64 -d > /tmp/_sm_install.sh 2>/dev/null && chmod +x /tmp/_sm_install.sh && bash /tmp/_sm_install.sh %s %s 2>&1; rc=$?; rm -f /tmp/_sm_install.sh 2>/dev/null; exit $rc',
escapeshellarg($b64),
escapeshellarg($serverUrl),
escapeshellarg($agentKey),
escapeshellarg($serverUrl),
escapeshellarg($agentKey)
);
@@ -119,7 +117,7 @@ class AgentService
$script = file_get_contents($scriptPath);
$remoteCommand = sprintf(
'echo %s | base64 -d > /tmp/_sm_uninstall.sh && chmod +x /tmp/_sm_uninstall.sh && (script -q -c "sudo bash /tmp/_sm_uninstall.sh" /dev/null < /dev/null 2>/dev/null || sudo bash /tmp/_sm_uninstall.sh) 2>&1; rc=$?; rm -f /tmp/_sm_uninstall.sh; exit $rc',
'echo %s | base64 -d > /tmp/_sm_uninstall.sh 2>/dev/null && chmod +x /tmp/_sm_uninstall.sh && bash /tmp/_sm_uninstall.sh 2>&1; rc=$?; rm -f /tmp/_sm_uninstall.sh 2>/dev/null; exit $rc',
escapeshellarg(base64_encode($script))
);