From ae1a8617f598863bbf9839dc5d9853b5a1dbf661 Mon Sep 17 00:00:00 2001 From: cynfo3000 Date: Fri, 6 Mar 2026 22:20:20 +0100 Subject: [PATCH] fix: Linux install.sh erstellt (systemd, Debian/Proxmox), Makefile nutzt plattformspezifische install.sh --- Makefile | 7 +- agent-linux/install.sh | 164 ++++++++++++++++++++++++++++++++--------- 2 files changed, 135 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index 95ce654..62b3cbb 100644 --- a/Makefile +++ b/Makefile @@ -43,11 +43,12 @@ release: agent agent-linux updater-freebsd updater-linux @echo "==> Creating release bundles v$(VERSION)..." @mkdir -p build/release @# FreeBSD Bundle (Agent + Updater + install.sh) - @cp opnsense-plugin/install.sh build/install.sh - @cd build && zip -j release/rmm-freebsd-$(VERSION).zip rmm-agent rmm-updater-freebsd install.sh + @cp opnsense-plugin/install.sh build/install-freebsd.sh + @cd build && zip -j release/rmm-freebsd-$(VERSION).zip rmm-agent rmm-updater-freebsd install-freebsd.sh @echo "==> build/release/rmm-freebsd-$(VERSION).zip erstellt" @# Linux Bundle (Agent + Updater + install.sh) - @cd build && zip -j release/rmm-linux-$(VERSION).zip rmm-agent-linux rmm-updater-linux install.sh + @cp agent-linux/install.sh build/install-linux.sh + @cd build && zip -j release/rmm-linux-$(VERSION).zip rmm-agent-linux rmm-updater-linux install-linux.sh @echo "==> build/release/rmm-linux-$(VERSION).zip erstellt" @echo "" @echo "Release v$(VERSION) fertig:" diff --git a/agent-linux/install.sh b/agent-linux/install.sh index 64a7535..d9c488e 100755 --- a/agent-linux/install.sh +++ b/agent-linux/install.sh @@ -1,46 +1,144 @@ #!/bin/bash -# RMM Agent Linux Installation Script +# +# RMM Agent Linux Installer +# Unterstuetzt: Debian, Ubuntu, Proxmox VE +# +# Verwendung nach ZIP-Download: +# unzip rmm-linux-*.zip +# bash install.sh +# set -e -echo "==> Installing RMM Agent Linux" +BASEDIR="$(cd "$(dirname "$0")" && pwd)" +AGENT_BIN="${BASEDIR}/rmm-agent-linux" +UPDATER_BIN="${BASEDIR}/rmm-updater-linux" +INSTALL_DIR="/usr/local/bin" +CONFIG_DIR="/etc/rmm" +CONFIG_FILE="${CONFIG_DIR}/config.yaml" +AGENT_ID_FILE="${CONFIG_DIR}/agent_id" -# Check if running as root -if [[ $EUID -ne 0 ]]; then - echo "This script must be run as root" - exit 1 -fi +echo "========================================" +echo " RMM Agent Linux Installer" +echo "========================================" -# Create directories -mkdir -p /etc/rmm -mkdir -p /usr/local/bin - -# Copy binary -if [ ! -f "rmm-agent-linux" ]; then - echo "Error: rmm-agent-linux binary not found in current directory" +# Root-Check +if [ "$(id -u)" -ne 0 ]; then + echo "FEHLER: Bitte als root ausfuehren (sudo bash install.sh)" exit 1 fi -cp rmm-agent-linux /usr/local/bin/rmm-agent-linux -chmod +x /usr/local/bin/rmm-agent-linux - -# Copy service file -cp rmm-agent-linux.service /etc/systemd/system/ - -# Create example config if it doesn't exist -if [ ! -f "/etc/rmm/config.yaml" ]; then - cp config.yaml.example /etc/rmm/config.yaml - echo "==> Created /etc/rmm/config.yaml - please edit with your backend URL and API key" +# Binaries pruefen +if [ ! -f "${AGENT_BIN}" ]; then + echo "FEHLER: ${AGENT_BIN} nicht gefunden" + echo "ZIP-Inhalt muss 'rmm-agent-linux' enthalten" + exit 1 fi -# Reload systemd and enable service -systemctl daemon-reload -systemctl enable rmm-agent-linux +# Alte Dienste stoppen +echo "[1/5] Alte Dienste stoppen..." +systemctl stop rmm-agent 2>/dev/null || true +systemctl stop rmm-updater 2>/dev/null || true + +# Binaries installieren +echo "[2/5] Binaries installieren..." +cp "${AGENT_BIN}" "${INSTALL_DIR}/rmm-agent" +chmod +x "${INSTALL_DIR}/rmm-agent" +echo " rmm-agent -> ${INSTALL_DIR}/rmm-agent" + +if [ -f "${UPDATER_BIN}" ]; then + cp "${UPDATER_BIN}" "${INSTALL_DIR}/rmm-updater" + chmod +x "${INSTALL_DIR}/rmm-updater" + echo " rmm-updater -> ${INSTALL_DIR}/rmm-updater" +fi + +# Config anlegen (wenn noch nicht vorhanden) +echo "[3/5] Konfiguration anlegen..." +mkdir -p "${CONFIG_DIR}" +if [ ! -f "${CONFIG_FILE}" ]; then + cat > "${CONFIG_FILE}" << 'CFGEOF' +backend_url: "https://BACKEND_IP:8443" +api_key: "DEIN_API_KEY" +interval_seconds: 60 +agent_name: "" +insecure: true +CFGEOF + echo " Config erstellt: ${CONFIG_FILE}" + echo " WICHTIG: Bitte Backend-URL und API-Key eintragen!" +else + echo " Config bereits vorhanden — unveraendert" +fi + +# Systemd Services +echo "[4/5] Systemd Services installieren..." + +cat > /etc/systemd/system/rmm-agent.service << 'SVCEOF' +[Unit] +Description=RMM Agent +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +ExecStart=/usr/local/bin/rmm-agent -config /etc/rmm/config.yaml +Restart=always +RestartSec=10 +StandardOutput=journal +StandardError=journal +SyslogIdentifier=rmm-agent + +[Install] +WantedBy=multi-user.target +SVCEOF + +if [ -f "${INSTALL_DIR}/rmm-updater" ]; then + cat > /etc/systemd/system/rmm-updater.service << 'SVCEOF' +[Unit] +Description=RMM Agent Updater +After=network-online.target rmm-agent.service +Wants=network-online.target + +[Service] +Type=simple +ExecStart=/usr/local/bin/rmm-updater +Restart=always +RestartSec=30 +StandardOutput=journal +StandardError=journal +SyslogIdentifier=rmm-updater + +[Install] +WantedBy=multi-user.target +SVCEOF +fi + +systemctl daemon-reload +systemctl enable rmm-agent +[ -f "${INSTALL_DIR}/rmm-updater" ] && systemctl enable rmm-updater || true + +echo " Systemd Services registriert" + +# Start (nur wenn Config bereits ausgefuellt) +echo "[5/5] Dienste starten..." +if grep -q "BACKEND_IP\|DEIN_API_KEY" "${CONFIG_FILE}" 2>/dev/null; then + echo "" + echo " Config noch nicht angepasst — Agent wird NICHT gestartet." + echo "" + echo " Bitte Config bearbeiten und dann starten:" + echo " nano ${CONFIG_FILE}" + echo " systemctl start rmm-agent" + [ -f "${INSTALL_DIR}/rmm-updater" ] && echo " systemctl start rmm-updater" || true +else + systemctl start rmm-agent + [ -f "${INSTALL_DIR}/rmm-updater" ] && systemctl start rmm-updater || true + echo " Dienste gestartet" +fi -echo "==> Installation complete!" echo "" -echo "Next steps:" -echo "1. Edit /etc/rmm/config.yaml with your backend URL and API key" -echo "2. Start the service: systemctl start rmm-agent-linux" -echo "3. Check status: systemctl status rmm-agent-linux" -echo "4. View logs: journalctl -u rmm-agent-linux -f" \ No newline at end of file +echo "========================================" +echo " RMM Agent Linux installiert!" +echo "" +echo " Config: ${CONFIG_FILE}" +echo " Logs: journalctl -u rmm-agent -f" +echo " Status: systemctl status rmm-agent" +echo "========================================"