Files
zabbix-agent-deployment/update-zabbix-agent.sh

87 lines
4.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# =============================================================================
# Zabbix Agent 2 Update auf Version 7.4
# Unterstützte Systeme: Debian 11/12/13, Ubuntu 20.04 / 22.04 / 24.04
#
# Aufruf:
# sudo bash update-zabbix-agent.sh
#
# Bestehende Konfiguration (/etc/zabbix/zabbix_agent2.conf) bleibt erhalten.
# =============================================================================
set -euo pipefail
ZABBIX_VERSION="7.4"
# Farben
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
error() { echo -e "${RED}[ERROR]${NC} $*" >&2; exit 1; }
# ── Prüfungen ─────────────────────────────────────────────────────────────────
[[ $EUID -ne 0 ]] && error "Bitte als root oder mit sudo ausführen."
# ── OS-Erkennung ──────────────────────────────────────────────────────────────
[[ ! -f /etc/os-release ]] && error "Kein /etc/os-release gefunden."
source /etc/os-release
case "$ID" in
debian) REPO_OS="debian" ;;
ubuntu) REPO_OS="ubuntu" ;;
*) error "Nicht unterstütztes Betriebssystem: $ID" ;;
esac
info "System erkannt: ${PRETTY_NAME}"
# ── Aktuelle Version ermitteln ────────────────────────────────────────────────
CURRENT_VERSION=$(dpkg -l zabbix-agent2 2>/dev/null | awk '/^ii/{print $3}' | head -1 || true)
if [[ -z "$CURRENT_VERSION" ]]; then
error "zabbix-agent2 ist nicht installiert. Bitte zuerst install-zabbix-agent.sh ausführen."
fi
info "Installierte Version: ${CURRENT_VERSION}"
# ── Zabbix 7.4 Repository einrichten ─────────────────────────────────────────
RELEASE_PKG="zabbix-release_latest_${ZABBIX_VERSION}+${REPO_OS}${VERSION_ID}_all.deb"
REPO_URL="https://repo.zabbix.com/zabbix/${ZABBIX_VERSION}/release/${REPO_OS}/pool/main/z/zabbix-release/${RELEASE_PKG}"
info "Lade Zabbix ${ZABBIX_VERSION} Repository-Paket herunter ..."
wget -q --show-progress -O "/tmp/${RELEASE_PKG}" "${REPO_URL}" \
|| error "Download fehlgeschlagen: ${REPO_URL}"
info "Installiere Repository-Paket ..."
# --force-confold: bestehende Repo-Konfiguration behalten, keine Rückfrage
# Hinweis: dpkg kennt kein -o, die Option wird direkt übergeben
DEBIAN_FRONTEND=noninteractive dpkg --force-confold -i "/tmp/${RELEASE_PKG}"
rm -f "/tmp/${RELEASE_PKG}"
apt-get update -qq
# ── Update durchführen ────────────────────────────────────────────────────────
info "Aktualisiere zabbix-agent2 auf Version ${ZABBIX_VERSION} ..."
info "(Bestehende Konfigurationsdatei wird beibehalten)"
# --force-confold: bei Konflikten immer die vorhandene Config behalten, keine Rückfrage
DEBIAN_FRONTEND=noninteractive apt-get install \
--only-upgrade \
-y \
-o Dpkg::Options::="--force-confold" \
-o Dpkg::Options::="--force-confdef" \
zabbix-agent2
# ── Dienst neu starten ────────────────────────────────────────────────────────
info "Starte zabbix-agent2 neu ..."
systemctl restart zabbix-agent2
# ── Ergebnis ──────────────────────────────────────────────────────────────────
NEW_VERSION=$(dpkg -l zabbix-agent2 2>/dev/null | awk '/^ii/{print $3}' | head -1 || true)
echo ""
info "════════════════════════════════════════════════"
info " Zabbix Agent 2 erfolgreich aktualisiert!"
info " Vorher : ${CURRENT_VERSION}"
info " Nachher: ${NEW_VERSION}"
info " Config : /etc/zabbix/zabbix_agent2.conf (unverändert)"
info " Status : $(systemctl is-active zabbix-agent2)"
info "════════════════════════════════════════════════"