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

View File

@@ -120,7 +120,38 @@ fi
# 6. Kopiere Dateien # 6. Kopiere Dateien
log_info "Kopiere Dateien..." log_info "Kopiere Dateien..."
sudo cp "$BUILD_DIR/yourpart-daemon" /usr/local/bin/ sudo cp "$BUILD_DIR/yourpart-daemon" /usr/local/bin/
# 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 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/ sudo cp yourpart-daemon.service /etc/systemd/system/
# 7. Setze Berechtigungen # 7. Setze Berechtigungen
@@ -128,6 +159,7 @@ log_info "Setze Berechtigungen..."
sudo chmod +x /usr/local/bin/yourpart-daemon sudo chmod +x /usr/local/bin/yourpart-daemon
sudo chown -R "$DAEMON_USER:$DAEMON_USER" "$REMOTE_DIR" sudo chown -R "$DAEMON_USER:$DAEMON_USER" "$REMOTE_DIR"
sudo chown -R "$DAEMON_USER:$DAEMON_USER" /var/log/yourpart 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 sudo chmod 600 /etc/yourpart/daemon.conf
# 8. Lade systemd neu # 8. Lade systemd neu

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"