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:
2026-06-11 19:01:27 -04:00
parent 63bf125420
commit 0ce24c4b8f
3 changed files with 16 additions and 20 deletions

View File

@@ -21,6 +21,7 @@ echo "[1/5] Creating config directory..."
mkdir -p "$CONFIG_DIR"
echo "[2/5] Installing agent binary..."
mkdir -p "$(dirname "$AGENT_BIN")"
cat > "$AGENT_BIN" << 'AGENTSCRIPT'
#!/bin/bash
set -e
@@ -49,7 +50,6 @@ collect_metrics() {
}
push_metrics() {
local payload
payload=$(cat <<EOF
{
"agent_key": "$AGENT_KEY",
@@ -75,7 +75,7 @@ main() {
exit 1
fi
echo "ServerManager Agent started (interval: ${INTERVAL}s)"
sleep 5
sleep 2
while true; do
collect_metrics
http_code=$(push_metrics)
@@ -91,6 +91,12 @@ main
AGENTSCRIPT
chmod +x "$AGENT_BIN"
if [ ! -f "$AGENT_BIN" ]; then
echo "ERROR: Agent binary was not created at $AGENT_BIN"
exit 1
fi
echo " Verified: $AGENT_BIN ($(wc -c < "$AGENT_BIN") bytes)"
echo "[3/5] Writing config..."
cat > "$CONFIG_FILE" << EOF
SERVER_URL="$SERVER_URL"