Files
Claude f7309a15fc Rotate agent registration key; remove key literals from public scripts/UI
- install.sh, install-agent.sh: require JARVIS_REG_KEY env var or interactive prompt instead of baked-in key (matches install-mac.sh/install-windows.ps1 behavior)

- netscan.php: reuse AGENT_REGISTRATION_KEY constant instead of a duplicate literal

- agent.php + api.php: add session-authed "regkey" action so the admin install modal fetches the current key at runtime

- jarvis-agents.js: fetch reg key via /api/agent/regkey instead of hardcoding it; pass JARVIS_REG_KEY in the Linux install one-liner

- INFRASTRUCTURE-REFERENCE.md: scrub old key literal (rotated; real value lives only in api/config.php on VM211)

Key rotated on the box + rolled out to all 11 agents (verified all re-register online). New value is in the gitignored api/config.php only.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-07 20:22:00 -05:00

113 lines
4.6 KiB
Bash
Executable File

#!/bin/bash
# JARVIS Agent Installer — one-liner for any Linux host:
# curl -sk http://jarvis.orbishosting.com:1972/agent/install.sh | bash -s <hostname> <agent_type>
#
# agent_type: linux | proxmox | homeassistant
# Example: curl -sk http://jarvis.orbishosting.com:1972/agent/install.sh | bash -s myserver linux
#
# On the LAN, set JARVIS_URL to the direct internal address instead (faster,
# doesn't hairpin through Cloudflare): JARVIS_URL=http://10.48.200.211 curl ... | bash -s ...
set -e
HOSTNAME_ARG="${1:-$(hostname -s)}"
AGENT_TYPE="${2:-linux}"
# Fixed 2026-07-07: jarvis.orbishosting.com on the default port isn't reachable
# from outside the LAN at all (no FortiGate VIP forwards it) — :1972 is the
# confirmed-working external path (same fix as the GitHub webhook and the
# Windows agent installer).
JARVIS_URL="${JARVIS_URL:-http://jarvis.orbishosting.com:1972}"
JARVIS_HOST=""
INSTALL_DIR="/opt/jarvis-agent"
CONFIG_DIR="/etc/jarvis-agent"
STATE_DIR="/var/lib/jarvis-agent"
REG_KEY="${JARVIS_REG_KEY:-}"
if [ -z "$REG_KEY" ] && [ -r /dev/tty ]; then
read -rp "Enter JARVIS registration key: " REG_KEY </dev/tty
fi
if [ -z "$REG_KEY" ]; then
echo "ERROR: registration key required (set JARVIS_REG_KEY env var or enter at prompt)" >&2
exit 1
fi
SERVICE_FILE="/etc/systemd/system/jarvis-agent.service"
echo "=== JARVIS Agent Installer v3.0 ==="
echo "Host: $HOSTNAME_ARG | Type: $AGENT_TYPE | Server: $JARVIS_URL"
# ── Dependencies ──────────────────────────────────────────────────────────────
if command -v apt-get &>/dev/null; then
apt-get install -yq python3 curl imagemagick 2>/dev/null || true
apt-get install -yq python3-psutil python3-requests 2>/dev/null || true
elif command -v yum &>/dev/null; then
yum install -yq python3 curl ImageMagick 2>/dev/null || true
elif command -v apk &>/dev/null; then
apk add --no-cache python3 curl imagemagick 2>/dev/null || true
fi
# pip fallback if psutil/requests not available via package manager
python3 -c "import psutil, requests" 2>/dev/null || pip3 install -q --break-system-packages requests psutil 2>/dev/null || pip3 install -q requests psutil 2>/dev/null || true
# ── Create directories ─────────────────────────────────────────────────────────
mkdir -p "$INSTALL_DIR" "$CONFIG_DIR" "$STATE_DIR"
# ── Download agent ─────────────────────────────────────────────────────────────
echo "Downloading agent..."
curl -sk "$JARVIS_URL/agent/jarvis-agent.py" -o "$INSTALL_DIR/jarvis-agent.py"
cp "$INSTALL_DIR/jarvis-agent.py" /usr/local/bin/jarvis-agent.py
chmod +x "$INSTALL_DIR/jarvis-agent.py" /usr/local/bin/jarvis-agent.py
# ── Write config (skip if already exists) ────────────────────────────────────
if [[ -f "$CONFIG_DIR/config.json" ]]; then
echo "Config already exists at $CONFIG_DIR/config.json — keeping existing settings."
else
cat > "$CONFIG_DIR/config.json" << JSONEOF
{
"jarvis_url": "$JARVIS_URL",
"host_header": "$JARVIS_HOST",
"ssl_verify": true,
"registration_key": "$REG_KEY",
"hostname": "$HOSTNAME_ARG",
"agent_type": "$AGENT_TYPE",
"poll_interval": 30,
"heartbeat_every": 10,
"update_check_hours": 24,
"watch_services": []
}
JSONEOF
chmod 600 "$CONFIG_DIR/config.json"
echo "Config written to $CONFIG_DIR/config.json"
fi
# ── Systemd service ────────────────────────────────────────────────────────────
cat > "$SERVICE_FILE" << SVCEOF
[Unit]
Description=JARVIS Agent
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/python3 $INSTALL_DIR/jarvis-agent.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
SVCEOF
systemctl daemon-reload
systemctl enable jarvis-agent
systemctl restart jarvis-agent
sleep 2
if systemctl is-active --quiet jarvis-agent; then
echo ""
echo "=== JARVIS Agent v3.0 installed and running ==="
echo "Config: $CONFIG_DIR/config.json"
echo "State: $STATE_DIR/state.json (created on first run)"
echo "Logs: journalctl -u jarvis-agent -f"
else
echo ""
echo "WARNING: Agent installed but not running. Check: journalctl -u jarvis-agent -n 30"
fi