mirror of
https://github.com/myronblair/jarvis
synced 2026-06-30 17:50:23 -05:00
install-agent.sh: rewrite for agent v3.0 config format
Old installer wrote to /opt/jarvis-agent/config.json with server_url/api_key/ heartbeat_interval keys and pre-registered with JARVIS. Agent v3.0 expects: - Config at /etc/jarvis-agent/config.json with jarvis_url/registration_key/ hostname/poll_interval/heartbeat_every keys - api_key stored by agent itself in /var/lib/jarvis-agent/state.json - Agent self-registers at startup using registration_key Also adds: imagemagick install (headless screenshot support), apk support for Alpine/WireGuard, copies to /usr/local/bin/jarvis-agent.py.
This commit is contained in:
@@ -1,78 +1,62 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# JARVIS Agent Installer
|
# JARVIS Agent Installer — one-liner for any Linux host:
|
||||||
# Usage: curl -sSL https://raw.githubusercontent.com/myronblair/jarvis/master/agent/install.sh | sudo bash
|
# curl -sk https://jarvis.orbishosting.com/install-agent.sh | bash -s <hostname> <agent_type>
|
||||||
# Or: sudo bash install.sh --jarvis-url https://jarvis.orbishosting.com --key YOUR_REGISTRATION_KEY
|
#
|
||||||
|
# agent_type: linux | proxmox | homeassistant
|
||||||
|
# Example: curl -sk https://jarvis.orbishosting.com/install-agent.sh | bash -s myserver linux
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
JARVIS_URL=""
|
HOSTNAME_ARG="${1:-$(hostname -s)}"
|
||||||
REG_KEY=""
|
AGENT_TYPE="${2:-linux}"
|
||||||
AGENT_TYPE="linux"
|
JARVIS_URL="https://165.22.1.228"
|
||||||
|
JARVIS_HOST="jarvis.orbishosting.com"
|
||||||
INSTALL_DIR="/opt/jarvis-agent"
|
INSTALL_DIR="/opt/jarvis-agent"
|
||||||
CONFIG_DIR="/etc/jarvis-agent"
|
CONFIG_DIR="/etc/jarvis-agent"
|
||||||
STATE_DIR="/var/lib/jarvis-agent"
|
STATE_DIR="/var/lib/jarvis-agent"
|
||||||
SERVICE_NAME="jarvis-agent"
|
REG_KEY="f846a9aaf7ce9a61742c63c87c4186052a71d2a580c65518"
|
||||||
|
SERVICE_FILE="/etc/systemd/system/jarvis-agent.service"
|
||||||
|
|
||||||
# ── Parse args ────────────────────────────────────────────────────────────────
|
echo "=== JARVIS Agent Installer v3.0 ==="
|
||||||
while [[ $# -gt 0 ]]; do
|
echo "Host: $HOSTNAME_ARG | Type: $AGENT_TYPE | Server: $JARVIS_URL"
|
||||||
case "$1" in
|
|
||||||
--jarvis-url) JARVIS_URL="$2"; shift 2 ;;
|
|
||||||
--key) REG_KEY="$2"; shift 2 ;;
|
|
||||||
--type) AGENT_TYPE="$2"; shift 2 ;;
|
|
||||||
*) echo "Unknown arg: $1"; exit 1 ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# ── Interactive prompts if not provided ──────────────────────────────────────
|
# ── Dependencies ──────────────────────────────────────────────────────────────
|
||||||
if [[ -z "$JARVIS_URL" ]]; then
|
if command -v apt-get &>/dev/null; then
|
||||||
read -rp "JARVIS URL (e.g. https://jarvis.orbishosting.com): " JARVIS_URL
|
apt-get install -yq python3 curl imagemagick 2>/dev/null || true
|
||||||
fi
|
apt-get install -yq python3-psutil python3-requests 2>/dev/null || true
|
||||||
if [[ -z "$REG_KEY" ]]; then
|
elif command -v yum &>/dev/null; then
|
||||||
read -rp "Registration key: " REG_KEY
|
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
|
fi
|
||||||
|
|
||||||
JARVIS_URL="${JARVIS_URL%/}"
|
# 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
|
||||||
|
|
||||||
echo ""
|
# ── Create directories ─────────────────────────────────────────────────────────
|
||||||
echo "Installing JARVIS Agent..."
|
|
||||||
echo " URL: $JARVIS_URL"
|
|
||||||
echo " Type: $AGENT_TYPE"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# ── Install Python3 if needed ─────────────────────────────────────────────────
|
|
||||||
if ! command -v python3 &>/dev/null; then
|
|
||||||
echo "Installing python3..."
|
|
||||||
apt-get update -qq && apt-get install -y python3 || yum install -y python3 || dnf install -y python3
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ── Create directories ────────────────────────────────────────────────────────
|
|
||||||
mkdir -p "$INSTALL_DIR" "$CONFIG_DIR" "$STATE_DIR"
|
mkdir -p "$INSTALL_DIR" "$CONFIG_DIR" "$STATE_DIR"
|
||||||
|
|
||||||
# ── Copy agent script ─────────────────────────────────────────────────────────
|
# ── Download agent ─────────────────────────────────────────────────────────────
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
echo "Downloading agent..."
|
||||||
if [[ -f "$SCRIPT_DIR/jarvis-agent.py" ]]; then
|
curl -sk -H "Host: $JARVIS_HOST" "$JARVIS_URL/agent/jarvis-agent.py" -o "$INSTALL_DIR/jarvis-agent.py"
|
||||||
cp "$SCRIPT_DIR/jarvis-agent.py" "$INSTALL_DIR/jarvis-agent.py"
|
cp "$INSTALL_DIR/jarvis-agent.py" /usr/local/bin/jarvis-agent.py
|
||||||
else
|
chmod +x "$INSTALL_DIR/jarvis-agent.py" /usr/local/bin/jarvis-agent.py
|
||||||
echo "Downloading agent script..."
|
|
||||||
curl -sSL "https://raw.githubusercontent.com/myronblair/jarvis/master/agent/jarvis-agent.py" \
|
|
||||||
-o "$INSTALL_DIR/jarvis-agent.py"
|
|
||||||
fi
|
|
||||||
chmod +x "$INSTALL_DIR/jarvis-agent.py"
|
|
||||||
|
|
||||||
# ── Write config ──────────────────────────────────────────────────────────────
|
|
||||||
HOSTNAME=$(hostname -f 2>/dev/null || hostname)
|
|
||||||
|
|
||||||
|
# ── Write config (skip if already exists) ────────────────────────────────────
|
||||||
if [[ -f "$CONFIG_DIR/config.json" ]]; then
|
if [[ -f "$CONFIG_DIR/config.json" ]]; then
|
||||||
echo "Config already exists at $CONFIG_DIR/config.json — skipping (keeping existing settings)."
|
echo "Config already exists at $CONFIG_DIR/config.json — keeping existing settings."
|
||||||
else
|
else
|
||||||
cat > "$CONFIG_DIR/config.json" << JSONEOF
|
cat > "$CONFIG_DIR/config.json" << JSONEOF
|
||||||
{
|
{
|
||||||
"jarvis_url": "$JARVIS_URL",
|
"jarvis_url": "$JARVIS_URL",
|
||||||
|
"host_header": "$JARVIS_HOST",
|
||||||
|
"ssl_verify": false,
|
||||||
"registration_key": "$REG_KEY",
|
"registration_key": "$REG_KEY",
|
||||||
"hostname": "$HOSTNAME",
|
"hostname": "$HOSTNAME_ARG",
|
||||||
"agent_type": "$AGENT_TYPE",
|
"agent_type": "$AGENT_TYPE",
|
||||||
"poll_interval": 30,
|
"poll_interval": 30,
|
||||||
"heartbeat_every": 10,
|
"heartbeat_every": 10,
|
||||||
|
"update_check_hours": 24,
|
||||||
"watch_services": ["ollama", "homeassistant", "mysql", "mariadb", "nginx", "apache2", "docker"]
|
"watch_services": ["ollama", "homeassistant", "mysql", "mariadb", "nginx", "apache2", "docker"]
|
||||||
}
|
}
|
||||||
JSONEOF
|
JSONEOF
|
||||||
@@ -80,10 +64,10 @@ JSONEOF
|
|||||||
echo "Config written to $CONFIG_DIR/config.json"
|
echo "Config written to $CONFIG_DIR/config.json"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ── Write systemd service ─────────────────────────────────────────────────────
|
# ── Systemd service ────────────────────────────────────────────────────────────
|
||||||
cat > "/etc/systemd/system/${SERVICE_NAME}.service" << SVCEOF
|
cat > "$SERVICE_FILE" << SVCEOF
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=JARVIS Monitoring Agent
|
Description=JARVIS Agent
|
||||||
After=network-online.target
|
After=network-online.target
|
||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
|
|
||||||
@@ -92,26 +76,23 @@ Type=simple
|
|||||||
ExecStart=/usr/bin/python3 $INSTALL_DIR/jarvis-agent.py
|
ExecStart=/usr/bin/python3 $INSTALL_DIR/jarvis-agent.py
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=10
|
RestartSec=10
|
||||||
StandardOutput=journal
|
|
||||||
StandardError=journal
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
SVCEOF
|
SVCEOF
|
||||||
|
|
||||||
# ── Enable and start ──────────────────────────────────────────────────────────
|
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl enable "$SERVICE_NAME"
|
systemctl enable jarvis-agent
|
||||||
systemctl restart "$SERVICE_NAME"
|
systemctl restart jarvis-agent
|
||||||
|
|
||||||
sleep 2
|
sleep 2
|
||||||
if systemctl is-active --quiet "$SERVICE_NAME"; then
|
if systemctl is-active --quiet jarvis-agent; then
|
||||||
echo ""
|
echo ""
|
||||||
echo "✓ JARVIS Agent installed and running."
|
echo "=== JARVIS Agent v3.0 installed and running ==="
|
||||||
echo " View logs: journalctl -u $SERVICE_NAME -f"
|
|
||||||
echo "Config: $CONFIG_DIR/config.json"
|
echo "Config: $CONFIG_DIR/config.json"
|
||||||
|
echo "State: $STATE_DIR/state.json (created on first run)"
|
||||||
|
echo "Logs: journalctl -u jarvis-agent -f"
|
||||||
else
|
else
|
||||||
echo ""
|
echo ""
|
||||||
echo "⚠ Agent installed but not running. Check logs:"
|
echo "WARNING: Agent installed but not running. Check: journalctl -u jarvis-agent -n 30"
|
||||||
echo " journalctl -u $SERVICE_NAME -n 30"
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -7,69 +7,65 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
HOSTNAME="${1:-$(hostname -s)}"
|
HOSTNAME_ARG="${1:-$(hostname -s)}"
|
||||||
AGENT_TYPE="${2:-linux}"
|
AGENT_TYPE="${2:-linux}"
|
||||||
JARVIS_URL="https://165.22.1.228"
|
JARVIS_URL="https://165.22.1.228"
|
||||||
JARVIS_HOST="jarvis.orbishosting.com"
|
JARVIS_HOST="jarvis.orbishosting.com"
|
||||||
INSTALL_DIR="/opt/jarvis-agent"
|
INSTALL_DIR="/opt/jarvis-agent"
|
||||||
|
CONFIG_DIR="/etc/jarvis-agent"
|
||||||
|
STATE_DIR="/var/lib/jarvis-agent"
|
||||||
|
REG_KEY="f846a9aaf7ce9a61742c63c87c4186052a71d2a580c65518"
|
||||||
SERVICE_FILE="/etc/systemd/system/jarvis-agent.service"
|
SERVICE_FILE="/etc/systemd/system/jarvis-agent.service"
|
||||||
|
|
||||||
echo "=== JARVIS Agent Installer ==="
|
echo "=== JARVIS Agent Installer v3.0 ==="
|
||||||
echo "Host: $HOSTNAME | Type: $AGENT_TYPE | Server: $JARVIS_URL"
|
echo "Host: $HOSTNAME_ARG | Type: $AGENT_TYPE | Server: $JARVIS_URL"
|
||||||
|
|
||||||
# ── Dependencies ──────────────────────────────────────────────────────────────
|
# ── Dependencies ──────────────────────────────────────────────────────────────
|
||||||
if command -v apt-get &>/dev/null; then
|
if command -v apt-get &>/dev/null; then
|
||||||
apt-get install -yq python3 python3-pip curl 2>/dev/null
|
apt-get install -yq python3 curl imagemagick 2>/dev/null || true
|
||||||
# Prefer apt packages to avoid externally-managed-environment errors
|
|
||||||
apt-get install -yq python3-psutil python3-requests 2>/dev/null || true
|
apt-get install -yq python3-psutil python3-requests 2>/dev/null || true
|
||||||
elif command -v yum &>/dev/null; then
|
elif command -v yum &>/dev/null; then
|
||||||
yum install -yq python3 python3-pip curl 2>/dev/null
|
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
|
fi
|
||||||
|
|
||||||
# Install via pip only if apt didn't get them (TrueNAS, non-Debian, etc.)
|
# pip fallback if psutil/requests not available via package manager
|
||||||
python3 -c "import psutil, requests" 2>/dev/null || \
|
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
|
||||||
pip3 install -q --break-system-packages requests psutil 2>/dev/null || \
|
|
||||||
pip3 install -q requests psutil 2>/dev/null || \
|
# ── Create directories ─────────────────────────────────────────────────────────
|
||||||
pip install -q requests psutil 2>/dev/null || true
|
mkdir -p "$INSTALL_DIR" "$CONFIG_DIR" "$STATE_DIR"
|
||||||
|
|
||||||
# ── Download agent ─────────────────────────────────────────────────────────────
|
# ── Download agent ─────────────────────────────────────────────────────────────
|
||||||
mkdir -p "$INSTALL_DIR"
|
echo "Downloading agent..."
|
||||||
curl -sk -H "Host: $JARVIS_HOST" "$JARVIS_URL/agent/jarvis-agent.py" -o "$INSTALL_DIR/jarvis-agent.py"
|
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"
|
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
|
||||||
|
|
||||||
# ── Register with JARVIS to get API key ───────────────────────────────────────
|
# ── Write config (skip if already exists) ────────────────────────────────────
|
||||||
IP=$(hostname -I | awk '{print $1}')
|
if [[ -f "$CONFIG_DIR/config.json" ]]; then
|
||||||
REG=$(curl -sk -H "Host: $JARVIS_HOST" \
|
echo "Config already exists at $CONFIG_DIR/config.json — keeping existing settings."
|
||||||
-H "Content-Type: application/json" \
|
else
|
||||||
-H "X-Registration-Key: f846a9aaf7ce9a61742c63c87c4186052a71d2a580c65518" \
|
cat > "$CONFIG_DIR/config.json" << JSONEOF
|
||||||
-X POST "$JARVIS_URL/api/agent/register" \
|
{
|
||||||
-d "{\"hostname\":\"$HOSTNAME\",\"agent_type\":\"$AGENT_TYPE\",\"ip_address\":\"$IP\",\"capabilities\":[\"metrics\",\"commands\"]}")
|
"jarvis_url": "$JARVIS_URL",
|
||||||
|
"host_header": "$JARVIS_HOST",
|
||||||
AGENT_ID=$(echo "$REG" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['agent_id'])" 2>/dev/null)
|
"ssl_verify": false,
|
||||||
API_KEY=$(echo "$REG" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['api_key'])" 2>/dev/null)
|
"registration_key": "$REG_KEY",
|
||||||
|
"hostname": "$HOSTNAME_ARG",
|
||||||
if [ -z "$API_KEY" ]; then
|
"agent_type": "$AGENT_TYPE",
|
||||||
echo "ERROR: Registration failed — $REG"
|
"poll_interval": 30,
|
||||||
exit 1
|
"heartbeat_every": 10,
|
||||||
|
"update_check_hours": 24,
|
||||||
|
"watch_services": ["ollama", "homeassistant", "mysql", "mariadb", "nginx", "apache2", "docker"]
|
||||||
|
}
|
||||||
|
JSONEOF
|
||||||
|
chmod 600 "$CONFIG_DIR/config.json"
|
||||||
|
echo "Config written to $CONFIG_DIR/config.json"
|
||||||
fi
|
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 ────────────────────────────────────────────────────────────
|
# ── Systemd service ────────────────────────────────────────────────────────────
|
||||||
cat > "$SERVICE_FILE" << EOF
|
cat > "$SERVICE_FILE" << SVCEOF
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=JARVIS Agent
|
Description=JARVIS Agent
|
||||||
After=network-online.target
|
After=network-online.target
|
||||||
@@ -78,21 +74,25 @@ Wants=network-online.target
|
|||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
ExecStart=/usr/bin/python3 $INSTALL_DIR/jarvis-agent.py
|
ExecStart=/usr/bin/python3 $INSTALL_DIR/jarvis-agent.py
|
||||||
WorkingDirectory=$INSTALL_DIR
|
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=10
|
RestartSec=10
|
||||||
StartLimitInterval=60
|
|
||||||
StartLimitBurst=5
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
EOF
|
SVCEOF
|
||||||
|
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl enable jarvis-agent
|
systemctl enable jarvis-agent
|
||||||
systemctl restart jarvis-agent
|
systemctl restart jarvis-agent
|
||||||
|
|
||||||
echo "=== JARVIS Agent installed and running ==="
|
sleep 2
|
||||||
echo "Config: $INSTALL_DIR/config.json"
|
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"
|
echo "Logs: journalctl -u jarvis-agent -f"
|
||||||
systemctl is-active jarvis-agent
|
else
|
||||||
|
echo ""
|
||||||
|
echo "WARNING: Agent installed but not running. Check: journalctl -u jarvis-agent -n 30"
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user