From 92e17a9f430daca5b5d50715e47f0705adbfd094 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Mon, 1 Sep 2025 15:21:24 +0200 Subject: [PATCH] =?UTF-8?q?Verbessere=20die=20Verwaltung=20der=20Konfigura?= =?UTF-8?q?tionsdatei=20im=20Skript=20deploy-server.sh.=20F=C3=BCge=20eine?= =?UTF-8?q?=20=C3=9Cberpr=C3=BCfung=20hinzu,=20ob=20die=20Konfigurationsda?= =?UTF-8?q?tei=20existiert,=20und=20kopiere=20sie=20nur,=20wenn=20sie=20ni?= =?UTF-8?q?cht=20vorhanden=20ist.=20Erg=C3=A4nze=20die=20Logik=20zum=20Hin?= =?UTF-8?q?zuf=C3=BCgen=20fehlender=20Schl=C3=BCssel=20in=20die=20bestehen?= =?UTF-8?q?de=20Konfigurationsdatei.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy-server.sh | 34 ++++++++++++++++++- update-config.sh | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 update-config.sh diff --git a/deploy-server.sh b/deploy-server.sh index 1b044b7..95d37bc 100755 --- a/deploy-server.sh +++ b/deploy-server.sh @@ -120,7 +120,38 @@ fi # 6. Kopiere Dateien log_info "Kopiere Dateien..." sudo cp "$BUILD_DIR/yourpart-daemon" /usr/local/bin/ -sudo cp daemon.conf /etc/yourpart/ + +# Intelligente Konfigurationsdatei-Verwaltung +log_info "Verwalte Konfigurationsdatei..." +if [ ! -f "/etc/yourpart/daemon.conf" ]; then + log_info "Konfigurationsdatei existiert nicht, kopiere neue..." + sudo cp daemon.conf /etc/yourpart/ + sudo chown yourpart:yourpart /etc/yourpart/daemon.conf +else + log_info "Konfigurationsdatei existiert bereits, prüfe auf fehlende Keys..." + # Erstelle temporäre Datei mit neuen Keys + temp_conf="/tmp/daemon.conf.new" + cp daemon.conf "$temp_conf" + + # Füge fehlende Keys hinzu + while IFS='=' read -r key value; do + # Überspringe Kommentare und leere Zeilen + if [[ "$key" =~ ^[[:space:]]*# ]] || [[ -z "$key" ]]; then + continue + fi + # Entferne Leerzeichen am Anfang + key=$(echo "$key" | sed 's/^[[:space:]]*//') + + # Prüfe ob Key bereits existiert + if ! grep -q "^[[:space:]]*$key[[:space:]]*=" /etc/yourpart/daemon.conf; then + log_info "Füge fehlenden Key hinzu: $key" + echo "$key=$value" | sudo tee -a /etc/yourpart/daemon.conf > /dev/null + fi + done < "$temp_conf" + + rm -f "$temp_conf" +fi + sudo cp yourpart-daemon.service /etc/systemd/system/ # 7. Setze Berechtigungen @@ -128,6 +159,7 @@ log_info "Setze Berechtigungen..." sudo chmod +x /usr/local/bin/yourpart-daemon sudo chown -R "$DAEMON_USER:$DAEMON_USER" "$REMOTE_DIR" sudo chown -R "$DAEMON_USER:$DAEMON_USER" /var/log/yourpart +sudo chown yourpart:yourpart /etc/yourpart/daemon.conf sudo chmod 600 /etc/yourpart/daemon.conf # 8. Lade systemd neu diff --git a/update-config.sh b/update-config.sh new file mode 100644 index 0000000..304c811 --- /dev/null +++ b/update-config.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +# Intelligente Konfigurationsdatei-Verwaltung für YourPart Daemon +# Fügt nur fehlende Keys hinzu, ohne bestehende Konfiguration zu überschreiben + +set -e + +# Farben für Logging +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +log_info() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +log_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +log_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +log_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +CONFIG_FILE="/etc/yourpart/daemon.conf" +TEMPLATE_FILE="daemon.conf" + +if [ ! -f "$TEMPLATE_FILE" ]; then + log_error "Template-Datei $TEMPLATE_FILE nicht gefunden!" + exit 1 +fi + +log_info "Verwalte Konfigurationsdatei: $CONFIG_FILE" + +if [ ! -f "$CONFIG_FILE" ]; then + log_info "Konfigurationsdatei existiert nicht, erstelle neue..." + sudo cp "$TEMPLATE_FILE" "$CONFIG_FILE" + sudo chown yourpart:yourpart "$CONFIG_FILE" + sudo chmod 600 "$CONFIG_FILE" + log_success "Neue Konfigurationsdatei erstellt" +else + log_info "Konfigurationsdatei existiert bereits, prüfe auf fehlende Keys..." + + # Erstelle temporäre Datei mit neuen Keys + temp_conf="/tmp/daemon.conf.new" + cp "$TEMPLATE_FILE" "$temp_conf" + + added_keys=0 + + # Füge fehlende Keys hinzu + while IFS='=' read -r key value; do + # Überspringe Kommentare und leere Zeilen + if [[ "$key" =~ ^[[:space:]]*# ]] || [[ -z "$key" ]]; then + continue + fi + # Entferne Leerzeichen am Anfang + key=$(echo "$key" | sed 's/^[[:space:]]*//') + + # Prüfe ob Key bereits existiert + if ! grep -q "^[[:space:]]*$key[[:space:]]*=" "$CONFIG_FILE"; then + log_info "Füge fehlenden Key hinzu: $key" + echo "$key=$value" | sudo tee -a "$CONFIG_FILE" > /dev/null + ((added_keys++)) + fi + done < "$temp_conf" + + rm -f "$temp_conf" + + if [ $added_keys -eq 0 ]; then + log_success "Keine neuen Keys hinzugefügt - Konfiguration ist aktuell" + else + log_success "$added_keys neue Keys hinzugefügt" + fi +fi + +# Setze korrekte Berechtigungen +sudo chown yourpart:yourpart "$CONFIG_FILE" +sudo chmod 600 "$CONFIG_FILE" + +log_success "Konfigurationsdatei-Verwaltung abgeschlossen"