#!/bin/bash echo "=== Bridge Config Syncer ===" echo "Updates config.yaml with values from registration.yaml" cat << 'PYTHON_SCRIPT' > sync_conf.py import sys import os try: from ruamel.yaml import YAML except ImportError: import subprocess subprocess.check_call([sys.executable, "-m", "pip", "install", "ruamel.yaml"]) from ruamel.yaml import YAML yaml = YAML() yaml.preserve_quotes = True # Only telegram for now, based on user request services = ["telegram"] base_dir = "data" # Beeper specific defaults from your bbctl output hs_url = "https://matrix.beeper.com/_hungryserv/inswe" hs_domain = "beeper.local" for service in services: config_path = os.path.join(base_dir, service, "config.yaml") reg_path = os.path.join(base_dir, service, "registration.yaml") if not os.path.exists(reg_path): print(f"[{service}] SKIPPING: registration.yaml not found.") continue if not os.path.exists(config_path): print(f"[{service}] SKIPPING: config.yaml not found.") continue print(f"[{service}] Syncing config from registration...") try: with open(reg_path, 'r') as f: reg = yaml.load(f) with open(config_path, 'r') as f: conf = yaml.load(f) changed = False # Sync Tokens & ID if conf['appservice']['as_token'] != reg['as_token']: conf['appservice']['as_token'] = reg['as_token'] changed = True print(f" - Updated as_token") if conf['appservice']['hs_token'] != reg['hs_token']: conf['appservice']['hs_token'] = reg['hs_token'] changed = True print(f" - Updated hs_token") if conf['appservice'].get('id') != reg['id']: conf['appservice']['id'] = reg['id'] changed = True print(f" - Updated appservice id") # Sync Homeserver if conf['homeserver'].get('address') != hs_url: conf['homeserver']['address'] = hs_url changed = True print(f" - Updated homeserver address") if conf['homeserver'].get('domain') != hs_domain: conf['homeserver']['domain'] = hs_domain changed = True print(f" - Updated homeserver domain") # Fix SQLite URI if needed (common issue) if isinstance(conf['appservice'].get('database'), str): if conf['appservice']['database'] != "sqlite:////data/bridge.db": conf['appservice']['database'] = "sqlite:////data/bridge.db" changed = True print(f" - Fixed database path") if changed: with open(config_path, 'w') as f: yaml.dump(conf, f) print(f"[{service}] Configuration updated successfully.") else: print(f"[{service}] Config was already in sync.") except Exception as e: print(f"[{service}] Error during sync: {e}") PYTHON_SCRIPT docker run --rm \ -v "$(pwd):/work" \ -w /work \ python:3.11-slim \ sh -c "pip install ruamel.yaml && python sync_conf.py" rm sync_conf.py