fix: use script command for PTY instead of modifying SSHService
- Revert SSHService exec() back to original (remove PTY parameter) - AgentService now writes installer to /tmp/ first, then runs via script -q -c to create a PTY for sudo (handles requiretty) - Falls back to direct sudo bash if script is unavailable - Cleans up temp files after execution - Added mkdir -p for /usr/local/bin in installer - Added file verification and byte-count after writing agent binary
This commit is contained in:
@@ -51,9 +51,11 @@ class AgentService
|
||||
|
||||
$b64 = base64_encode($script);
|
||||
$remoteCommand = sprintf(
|
||||
'echo %s | base64 -d | sudo bash -s -- %s %s 2>&1',
|
||||
'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',
|
||||
escapeshellarg($b64),
|
||||
escapeshellarg($serverUrl),
|
||||
escapeshellarg($agentKey),
|
||||
escapeshellarg($serverUrl),
|
||||
escapeshellarg($agentKey)
|
||||
);
|
||||
|
||||
@@ -63,7 +65,7 @@ class AgentService
|
||||
return ['success' => false, 'error' => 'SSH connection failed'];
|
||||
}
|
||||
|
||||
$result = $ssh->exec($remoteCommand, 120, true);
|
||||
$result = $ssh->exec($remoteCommand, 120);
|
||||
$ssh->disconnect();
|
||||
|
||||
$output = trim($result['output']);
|
||||
@@ -117,7 +119,7 @@ class AgentService
|
||||
$script = file_get_contents($scriptPath);
|
||||
|
||||
$remoteCommand = sprintf(
|
||||
'echo %s | base64 -d | sudo bash 2>&1',
|
||||
'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',
|
||||
escapeshellarg(base64_encode($script))
|
||||
);
|
||||
|
||||
@@ -127,7 +129,7 @@ class AgentService
|
||||
return ['success' => false, 'error' => 'SSH connection failed'];
|
||||
}
|
||||
|
||||
$result = $ssh->exec($remoteCommand, 60, true);
|
||||
$result = $ssh->exec($remoteCommand, 60);
|
||||
$ssh->disconnect();
|
||||
|
||||
$output = trim($result['output']);
|
||||
|
||||
Reference in New Issue
Block a user