diff --git a/install-minion.sh b/install-minion.sh index 3310d57..b6d7115 100755 --- a/install-minion.sh +++ b/install-minion.sh @@ -3,8 +3,6 @@ # Verwendung: bash install-minion.sh # Beispiel: bash install-minion.sh K100163 -set -e - KUNDE=$1 SALT_MASTER="salt.cynfo.net" @@ -38,6 +36,7 @@ echo "" echo "=== Cleanup alte Installation ===" # Stop services +echo "Stoppe Services..." systemctl stop salt-minion 2>/dev/null || true systemctl stop salt-master 2>/dev/null || true systemctl disable salt-minion 2>/dev/null || true @@ -45,22 +44,24 @@ systemctl disable salt-master 2>/dev/null || true # Purge ALL salt packages if [ "$OS" = "debian" ]; then - # Finde alle installierten salt-Pakete SALT_PKGS=$(dpkg -l | grep -i salt | awk '{print $2}' || true) if [ -n "$SALT_PKGS" ]; then echo "Entferne Pakete: $SALT_PKGS" - apt-get remove --purge -y $SALT_PKGS 2>/dev/null || true + apt-get remove --purge -y $SALT_PKGS || true + else + echo "Keine Salt-Pakete gefunden." fi apt-get autoremove --purge -y 2>/dev/null || true - # dpkg purge falls noch Reste da sind + SALT_RESIDUAL=$(dpkg -l | grep -i salt | grep ^rc | awk '{print $2}' || true) if [ -n "$SALT_RESIDUAL" ]; then echo "Purge Reste: $SALT_RESIDUAL" - dpkg --purge $SALT_RESIDUAL 2>/dev/null || true + dpkg --purge $SALT_RESIDUAL || true fi fi # Remove config, keys, cache, logs +echo "Loesche Verzeichnisse..." rm -rf /etc/salt rm -rf /var/cache/salt rm -rf /var/log/salt @@ -81,25 +82,33 @@ echo "" echo "=== Frische Installation ===" if [ "$OS" = "debian" ]; then - apt-get install -y gnupg2 curl >/dev/null 2>&1 + echo "Installiere Abhaengigkeiten..." + apt-get install -y gnupg2 curl 2>&1 || { echo "FEHLER: gnupg2/curl Installation fehlgeschlagen"; exit 1; } - # Salt Repo einrichten + echo "Richte Salt Repo ein..." mkdir -p /etc/apt/keyrings curl -fsSL https://packages.broadcom.com/artifactory/api/security/keypair/SaltProjectKey/public | gpg --dearmor -o /etc/apt/keyrings/salt-archive-keyring.gpg - echo 'deb [signed-by=/etc/apt/keyrings/salt-archive-keyring.gpg] https://packages.broadcom.com/artifactory/saltproject-deb/ stable main' > /etc/apt/sources.list.d/salt.list - - apt-get update >/dev/null 2>&1 - apt-get install -y salt-minion - - # Pruefen ob Installation erfolgreich - if ! command -v salt-minion &>/dev/null; then - echo "FEHLER: salt-minion wurde nicht installiert!" - echo "apt-get install Ausgabe:" - apt-get install -y salt-minion + if [ ! -f /etc/apt/keyrings/salt-archive-keyring.gpg ]; then + echo "FEHLER: GPG Key konnte nicht heruntergeladen werden" exit 1 fi + + echo 'deb [signed-by=/etc/apt/keyrings/salt-archive-keyring.gpg] https://packages.broadcom.com/artifactory/saltproject-deb/ stable main' > /etc/apt/sources.list.d/salt.list + + echo "apt-get update..." + apt-get update 2>&1 || { echo "FEHLER: apt-get update fehlgeschlagen"; exit 1; } + + echo "Installiere salt-minion..." + apt-get install -y salt-minion 2>&1 || { echo "FEHLER: salt-minion Installation fehlgeschlagen"; exit 1; } fi +# Pruefen ob Installation erfolgreich +if ! command -v salt-minion &>/dev/null; then + echo "FEHLER: salt-minion Binary nicht gefunden!" + exit 1 +fi +echo "salt-minion installiert: $(salt-minion --version)" + # Pruefen ob /etc/salt existiert if [ ! -d /etc/salt ]; then echo "WARNUNG: /etc/salt existiert nicht, erstelle manuell..." @@ -108,6 +117,7 @@ if [ ! -d /etc/salt ]; then fi # Configure Master +echo "Konfiguriere Minion..." mkdir -p /etc/salt/minion.d cat > /etc/salt/minion.d/master.conf << EOF master: $SALT_MASTER