Update repair.sh to use Python/ruamel.yaml via Docker for safe config fixing
This commit is contained in:
130
repair.sh
130
repair.sh
@@ -1,43 +1,101 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "=== Beeper Bridge Repair Tool ==="
|
||||
echo "=== Beeper Bridge Repair Tool v2 (Python YAML Fix) ==="
|
||||
|
||||
# 1. Berechtigungen fixen
|
||||
echo "[*] Setze Berechtigungen auf 777 für data/..."
|
||||
# 1. Python Script erstellen, das YAML sauber manipuliert
|
||||
cat << 'PYTHON_SCRIPT' > fix_yaml.py
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Versuche ruamel.yaml zu importieren (Standard in mautrix images), sonst pyyaml
|
||||
try:
|
||||
from ruamel.yaml import YAML
|
||||
yaml = YAML()
|
||||
yaml.preserve_quotes = True
|
||||
except ImportError:
|
||||
print("WARNUNG: ruamel.yaml nicht gefunden. Nutze einfaches String-Parsing (weniger sicher).")
|
||||
sys.exit(1)
|
||||
|
||||
files = [
|
||||
"data/whatsapp/config.yaml",
|
||||
"data/telegram/config.yaml",
|
||||
"data/signal/config.yaml",
|
||||
"data/googlechat/config.yaml"
|
||||
]
|
||||
|
||||
# Standard Logging Config für Docker (nur Stdout)
|
||||
logging_config = {
|
||||
"version": 1,
|
||||
"formatters": {
|
||||
"colored": {
|
||||
"format": "[%(asctime)s] [%(levelname)s@%(name)s] %(message)s",
|
||||
"datefmt": "%b %d %H:%M:%S"
|
||||
}
|
||||
},
|
||||
"handlers": {
|
||||
"console": {
|
||||
"class": "logging.StreamHandler",
|
||||
"formatter": "colored",
|
||||
"stream": "ext://sys.stdout"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"level": "INFO",
|
||||
"handlers": ["console"]
|
||||
}
|
||||
}
|
||||
|
||||
for file_path in files:
|
||||
if not os.path.exists(file_path):
|
||||
print(f"Skipping missing file: {file_path}")
|
||||
continue
|
||||
|
||||
print(f"Processing {file_path}...")
|
||||
|
||||
try:
|
||||
with open(file_path, 'r') as f:
|
||||
data = yaml.load(f)
|
||||
|
||||
# 1. Fix Database URI
|
||||
if 'appservice' in data and 'database' in data['appservice']:
|
||||
# Alte Struktur
|
||||
if isinstance(data['appservice']['database'], str):
|
||||
data['appservice']['database'] = "sqlite:////data/bridge.db"
|
||||
# Neue Struktur (oft direkt unter root oder appservice.database.uri)
|
||||
elif isinstance(data['appservice']['database'], dict):
|
||||
data['appservice']['database']['uri'] = "sqlite:////data/bridge.db"
|
||||
|
||||
# Fallback: Suche nach 'database' im Root (manche Bridges)
|
||||
if 'database' in data and isinstance(data['database'], dict) and 'uri' in data['database']:
|
||||
data['database']['uri'] = "sqlite:////data/bridge.db"
|
||||
|
||||
|
||||
# 2. Replace Logging Section completely
|
||||
data['logging'] = logging_config
|
||||
|
||||
with open(file_path, 'w') as f:
|
||||
yaml.dump(data, f)
|
||||
|
||||
print(f" -> Success.")
|
||||
|
||||
except Exception as e:
|
||||
print(f" -> Error processing {file_path}: {e}")
|
||||
|
||||
PYTHON_SCRIPT
|
||||
|
||||
# 2. Prüfen ob Python/ruamel verfügbar ist. Wenn nicht, nutzen wir einen Docker Container zum Fixen!
|
||||
# Da wir eh Docker haben, nutzen wir einfach das whatsapp image, da ist python+ruamel drin.
|
||||
echo "[*] Starte Reparatur im Docker Container (um Python-Abhängigkeiten zu nutzen)..."
|
||||
|
||||
docker run --rm -v $(pwd):/work -w /work dock.mau.dev/mautrix/whatsapp:latest python3 fix_yaml.py
|
||||
|
||||
# 3. Berechtigungen nochmal setzen
|
||||
echo "[*] Setze Berechtigungen auf 777..."
|
||||
chmod -R 777 data/
|
||||
|
||||
# 2. Configs reparieren
|
||||
for SERVICE in whatsapp telegram signal googlechat; do
|
||||
CONFIG="data/$SERVICE/config.yaml"
|
||||
|
||||
if [ -f "$CONFIG" ]; then
|
||||
echo "[*] Prüfe $SERVICE Config..."
|
||||
|
||||
# Fix: Absolute Pfade beim Logging durch lokale Pfade ersetzen
|
||||
# Sucht nach "filename: /..." und ersetzt durch "filename: /data/bridge.log"
|
||||
sed -i 's|filename: /.*|filename: /data/bridge.log|g' "$CONFIG"
|
||||
|
||||
# Fix: Google Chat Logging Version Error
|
||||
if [ "$SERVICE" == "googlechat" ]; then
|
||||
if ! grep -q "version: 1" "$CONFIG"; then
|
||||
echo " -> Füge 'version: 1' zum Logging hinzu"
|
||||
sed -i 's/logging:/logging:\n version: 1/g' "$CONFIG"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Fix: Datenbank Pfad sicherstellen (falls bei Migration vergessen)
|
||||
sed -i 's|uri: sqlite:.*|uri: sqlite:////data/bridge.db|g' "$CONFIG"
|
||||
|
||||
echo " -> Pfade korrigiert."
|
||||
else
|
||||
echo "[!] Warnung: Keine Config für $SERVICE gefunden ($CONFIG)"
|
||||
fi
|
||||
done
|
||||
# Cleanup
|
||||
rm fix_yaml.py
|
||||
|
||||
echo ""
|
||||
echo "=== WICHTIG ==="
|
||||
echo "Die Container haben eventuell deine 'registration.yaml' überschrieben, weil sie sie beim ersten Start nicht lesen konnten."
|
||||
echo "Bitte prüfe jetzt manuell in den Ordnern 'data/whatsapp', 'data/telegram' etc., ob die registration.yaml korrekt ist."
|
||||
echo "Falls sie gerade eben neu erstellt wurde, KOPIERE DEINE ALTE DATEI ERNEUT HIN."
|
||||
echo ""
|
||||
echo "Danach: docker compose restart"
|
||||
echo "=== Fertig ==="
|
||||
echo "Versuche jetzt: docker compose up"
|
||||
|
||||
Reference in New Issue
Block a user