mirror of
https://github.com/myronblair/jarvis
synced 2026-06-30 17:50:23 -05:00
99 lines
4.0 KiB
Bash
Executable File
99 lines
4.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# JARVIS Agent Installer — one-liner for any Linux host:
|
|
# curl -sk https://jarvis.orbishosting.com/install-agent.sh | bash -s <hostname> <agent_type>
|
|
#
|
|
# agent_type: linux | proxmox | homeassistant
|
|
# Example: curl -sk https://jarvis.orbishosting.com/install-agent.sh | bash -s myserver linux
|
|
|
|
set -e
|
|
|
|
HOSTNAME="${1:-$(hostname -s)}"
|
|
AGENT_TYPE="${2:-linux}"
|
|
JARVIS_URL="https://165.22.1.228"
|
|
JARVIS_HOST="jarvis.orbishosting.com"
|
|
INSTALL_DIR="/opt/jarvis-agent"
|
|
SERVICE_FILE="/etc/systemd/system/jarvis-agent.service"
|
|
|
|
echo "=== JARVIS Agent Installer ==="
|
|
echo "Host: $HOSTNAME | Type: $AGENT_TYPE | Server: $JARVIS_URL"
|
|
|
|
# ── Dependencies ──────────────────────────────────────────────────────────────
|
|
if command -v apt-get &>/dev/null; then
|
|
apt-get install -yq python3 python3-pip curl 2>/dev/null
|
|
# Prefer apt packages to avoid externally-managed-environment errors
|
|
apt-get install -yq python3-psutil python3-requests 2>/dev/null || true
|
|
elif command -v yum &>/dev/null; then
|
|
yum install -yq python3 python3-pip curl 2>/dev/null
|
|
fi
|
|
|
|
# Install via pip only if apt didn't get them (TrueNAS, non-Debian, etc.)
|
|
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 || \
|
|
pip install -q requests psutil 2>/dev/null || true
|
|
|
|
# ── Download agent ─────────────────────────────────────────────────────────────
|
|
mkdir -p "$INSTALL_DIR"
|
|
curl -sk -H "Host: $JARVIS_HOST" "$JARVIS_URL/agent/jarvis-agent.py" -o "$INSTALL_DIR/jarvis-agent.py"
|
|
chmod +x "$INSTALL_DIR/jarvis-agent.py"
|
|
|
|
# ── Register with JARVIS to get API key ───────────────────────────────────────
|
|
IP=$(hostname -I | awk '{print $1}')
|
|
REG=$(curl -sk -H "Host: $JARVIS_HOST" \
|
|
-H "Content-Type: application/json" \
|
|
-H "X-Registration-Key: f846a9aaf7ce9a61742c63c87c4186052a71d2a580c65518" \
|
|
-X POST "$JARVIS_URL/api/agent/register" \
|
|
-d "{\"hostname\":\"$HOSTNAME\",\"agent_type\":\"$AGENT_TYPE\",\"ip_address\":\"$IP\",\"capabilities\":[\"metrics\",\"commands\"]}")
|
|
|
|
AGENT_ID=$(echo "$REG" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['agent_id'])" 2>/dev/null)
|
|
API_KEY=$(echo "$REG" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['api_key'])" 2>/dev/null)
|
|
|
|
if [ -z "$API_KEY" ]; then
|
|
echo "ERROR: Registration failed — $REG"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Registered: agent_id=$AGENT_ID"
|
|
|
|
# ── Write config ───────────────────────────────────────────────────────────────
|
|
cat > "$INSTALL_DIR/config.json" << EOF
|
|
{
|
|
"server_url": "$JARVIS_URL",
|
|
"host_header": "$JARVIS_HOST",
|
|
"agent_id": "$AGENT_ID",
|
|
"api_key": "$API_KEY",
|
|
"agent_type": "$AGENT_TYPE",
|
|
"heartbeat_interval": 10,
|
|
"metrics_interval": 30
|
|
}
|
|
EOF
|
|
|
|
# ── Systemd service ────────────────────────────────────────────────────────────
|
|
cat > "$SERVICE_FILE" << EOF
|
|
[Unit]
|
|
Description=JARVIS Agent
|
|
After=network-online.target
|
|
Wants=network-online.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
ExecStart=/usr/bin/python3 $INSTALL_DIR/jarvis-agent.py
|
|
WorkingDirectory=$INSTALL_DIR
|
|
Restart=always
|
|
RestartSec=10
|
|
StartLimitInterval=60
|
|
StartLimitBurst=5
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable jarvis-agent
|
|
systemctl restart jarvis-agent
|
|
|
|
echo "=== JARVIS Agent installed and running ==="
|
|
echo "Config: $INSTALL_DIR/config.json"
|
|
echo "Logs: journalctl -u jarvis-agent -f"
|
|
systemctl is-active jarvis-agent
|