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
|
||||
# JARVIS Agent Installer
|
||||
# Usage: curl -sSL https://raw.githubusercontent.com/myronblair/jarvis/master/agent/install.sh | sudo bash
|
||||
# Or: sudo bash install.sh --jarvis-url https://jarvis.orbishosting.com --key YOUR_REGISTRATION_KEY
|
||||
# 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
|
||||
|
||||
JARVIS_URL=""
|
||||
REG_KEY=""
|
||||
AGENT_TYPE="linux"
|
||||
HOSTNAME_ARG="${1:-$(hostname -s)}"
|
||||
AGENT_TYPE="${2:-linux}"
|
||||
JARVIS_URL="https://165.22.1.228"
|
||||
JARVIS_HOST="jarvis.orbishosting.com"
|
||||
INSTALL_DIR="/opt/jarvis-agent"
|
||||
CONFIG_DIR="/etc/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 ────────────────────────────────────────────────────────────────
|
||||
while [[ $# -gt 0 ]]; do
|
||||
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
|
||||
echo "=== JARVIS Agent Installer v3.0 ==="
|
||||
echo "Host: $HOSTNAME_ARG | Type: $AGENT_TYPE | Server: $JARVIS_URL"
|
||||
|
||||
# ── Interactive prompts if not provided ──────────────────────────────────────
|
||||
if [[ -z "$JARVIS_URL" ]]; then
|
||||
read -rp "JARVIS URL (e.g. https://jarvis.orbishosting.com): " JARVIS_URL
|
||||
fi
|
||||
if [[ -z "$REG_KEY" ]]; then
|
||||
read -rp "Registration key: " REG_KEY
|
||||
# ── 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
|
||||
|
||||
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 ""
|
||||
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 ────────────────────────────────────────────────────────
|
||||
# ── Create directories ─────────────────────────────────────────────────────────
|
||||
mkdir -p "$INSTALL_DIR" "$CONFIG_DIR" "$STATE_DIR"
|
||||
|
||||
# ── Copy agent script ─────────────────────────────────────────────────────────
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
if [[ -f "$SCRIPT_DIR/jarvis-agent.py" ]]; then
|
||||
cp "$SCRIPT_DIR/jarvis-agent.py" "$INSTALL_DIR/jarvis-agent.py"
|
||||
else
|
||||
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)
|
||||
# ── Download agent ─────────────────────────────────────────────────────────────
|
||||
echo "Downloading agent..."
|
||||
curl -sk -H "Host: $JARVIS_HOST" "$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 — skipping (keeping existing settings)."
|
||||
echo "Config already exists at $CONFIG_DIR/config.json — keeping existing settings."
|
||||
else
|
||||
cat > "$CONFIG_DIR/config.json" << JSONEOF
|
||||
cat > "$CONFIG_DIR/config.json" << JSONEOF
|
||||
{
|
||||
"jarvis_url": "$JARVIS_URL",
|
||||
"host_header": "$JARVIS_HOST",
|
||||
"ssl_verify": false,
|
||||
"registration_key": "$REG_KEY",
|
||||
"hostname": "$HOSTNAME",
|
||||
"hostname": "$HOSTNAME_ARG",
|
||||
"agent_type": "$AGENT_TYPE",
|
||||
"poll_interval": 30,
|
||||
"heartbeat_every": 10,
|
||||
"update_check_hours": 24,
|
||||
"watch_services": ["ollama", "homeassistant", "mysql", "mariadb", "nginx", "apache2", "docker"]
|
||||
}
|
||||
JSONEOF
|
||||
@@ -80,10 +64,10 @@ JSONEOF
|
||||
echo "Config written to $CONFIG_DIR/config.json"
|
||||
fi
|
||||
|
||||
# ── Write systemd service ─────────────────────────────────────────────────────
|
||||
cat > "/etc/systemd/system/${SERVICE_NAME}.service" << SVCEOF
|
||||
# ── Systemd service ────────────────────────────────────────────────────────────
|
||||
cat > "$SERVICE_FILE" << SVCEOF
|
||||
[Unit]
|
||||
Description=JARVIS Monitoring Agent
|
||||
Description=JARVIS Agent
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
@@ -92,26 +76,23 @@ Type=simple
|
||||
ExecStart=/usr/bin/python3 $INSTALL_DIR/jarvis-agent.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
SVCEOF
|
||||
|
||||
# ── Enable and start ──────────────────────────────────────────────────────────
|
||||
systemctl daemon-reload
|
||||
systemctl enable "$SERVICE_NAME"
|
||||
systemctl restart "$SERVICE_NAME"
|
||||
systemctl enable jarvis-agent
|
||||
systemctl restart jarvis-agent
|
||||
|
||||
sleep 2
|
||||
if systemctl is-active --quiet "$SERVICE_NAME"; then
|
||||
if systemctl is-active --quiet jarvis-agent; then
|
||||
echo ""
|
||||
echo "✓ JARVIS Agent installed and running."
|
||||
echo " View logs: journalctl -u $SERVICE_NAME -f"
|
||||
echo " Config: $CONFIG_DIR/config.json"
|
||||
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 "⚠ Agent installed but not running. Check logs:"
|
||||
echo " journalctl -u $SERVICE_NAME -n 30"
|
||||
echo "WARNING: Agent installed but not running. Check: journalctl -u jarvis-agent -n 30"
|
||||
fi
|
||||
|
||||
@@ -7,69 +7,65 @@
|
||||
|
||||
set -e
|
||||
|
||||
HOSTNAME="${1:-$(hostname -s)}"
|
||||
HOSTNAME_ARG="${1:-$(hostname -s)}"
|
||||
AGENT_TYPE="${2:-linux}"
|
||||
JARVIS_URL="https://165.22.1.228"
|
||||
JARVIS_HOST="jarvis.orbishosting.com"
|
||||
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"
|
||||
|
||||
echo "=== JARVIS Agent Installer ==="
|
||||
echo "Host: $HOSTNAME | Type: $AGENT_TYPE | Server: $JARVIS_URL"
|
||||
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 python3-pip curl 2>/dev/null
|
||||
# Prefer apt packages to avoid externally-managed-environment errors
|
||||
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 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
|
||||
|
||||
# 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
|
||||
# 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 ─────────────────────────────────────────────────────────────
|
||||
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"
|
||||
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 ───────────────────────────────────────
|
||||
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
|
||||
# ── 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": false,
|
||||
"registration_key": "$REG_KEY",
|
||||
"hostname": "$HOSTNAME_ARG",
|
||||
"agent_type": "$AGENT_TYPE",
|
||||
"poll_interval": 30,
|
||||
"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
|
||||
|
||||
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
|
||||
cat > "$SERVICE_FILE" << SVCEOF
|
||||
[Unit]
|
||||
Description=JARVIS Agent
|
||||
After=network-online.target
|
||||
@@ -78,21 +74,25 @@ 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
|
||||
SVCEOF
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user