87 lines
2.2 KiB
Bash
Executable File
87 lines
2.2 KiB
Bash
Executable File
#!/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"
|