Verbessere die Verwaltung der Konfigurationsdatei im Skript deploy-server.sh. Füge eine Überprüfung hinzu, ob die Konfigurationsdatei existiert, und kopiere sie nur, wenn sie nicht vorhanden ist. Ergänze die Logik zum Hinzufügen fehlender Schlüssel in die bestehende Konfigurationsdatei.

This commit is contained in:
Torsten Schulz (local)
2025-09-01 15:21:24 +02:00
committed by Torsten (PC)
parent d3727ad2f7
commit 92e17a9f43
2 changed files with 119 additions and 1 deletions

86
update-config.sh Normal file
View File

@@ -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"