#!/bin/bash echo "=== Beeper Bridge Token Verifier ===" echo "Checks if config.yaml and registration.yaml tokens match." cat << 'PYTHON_SCRIPT' > verify_tokens.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() services = ["telegram", "whatsapp", "signal", "googlechat"] base_dir = "data" for service in services: print(f"\n--- Checking {service} ---") 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(config_path): print(f" [MISSING] config.yaml not found.") continue if not os.path.exists(reg_path): print(f" [MISSING] registration.yaml not found. Bridge needs to generate it.") continue try: with open(config_path, 'r') as f: c_data = yaml.load(f) with open(reg_path, 'r') as f: r_data = yaml.load(f) # Get tokens from config # Mautrix bridges store tokens in appservice.as_token / hs_token usually c_as = c_data.get('appservice', {}).get('as_token') c_hs = c_data.get('appservice', {}).get('hs_token') # Get tokens from registration r_as = r_data.get('as_token') r_hs = r_data.get('hs_token') match_as = (c_as == r_as) match_hs = (c_hs == r_hs) if match_as and match_hs: print(f" [OK] Tokens match between config and registration.") print(f" -> AS Token start: {str(r_as)[:5]}...") print(f" -> Please ensure the homeserver uses the registration file with AS Token starting with {str(r_as)[:5]}...") else: print(f" [ERROR] Token Mismatch!") print(f" Config AS: {str(c_as)[:10]}... | Reg AS: {str(r_as)[:10]}...") print(f" Config HS: {str(c_hs)[:10]}... | Reg HS: {str(r_hs)[:10]}...") print(f" -> ACTION REQUIRED: Delete registration.yaml and restart container to regenerate, OR fix config.yaml.") except Exception as e: print(f" [ERROR] Failed to parse files: {e}") PYTHON_SCRIPT echo "[*] Running verifier..." docker run --rm \ -v "$(pwd):/work" \ -w /work \ python:3.11-slim \ sh -c "pip install ruamel.yaml && python verify_tokens.py" rm verify_tokens.py