Files
beeper-bridge-docker/configure_bridges.sh

106 lines
3.0 KiB
Bash

#!/bin/bash
echo "=== Bridge Configuration Tool ==="
echo "This script configures the connection between your Bridges and your Matrix Homeserver."
# Default values
DEFAULT_HS_URL="http://localhost:8008"
DEFAULT_DOMAIN="example.com"
echo ""
read -p "Enter Homeserver URL (default: $DEFAULT_HS_URL): " HS_URL
HS_URL=${HS_URL:-$DEFAULT_HS_URL}
read -p "Enter Homeserver Domain (default: $DEFAULT_DOMAIN): " HS_DOMAIN
HS_DOMAIN=${HS_DOMAIN:-$DEFAULT_DOMAIN}
echo ""
echo "Configuring for:"
echo " URL: $HS_URL"
echo " Domain: $HS_DOMAIN"
echo ""
cat << PYTHON_SCRIPT > apply_config.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
services = ["whatsapp", "telegram", "signal", "googlechat"]
base_dir = "data"
hs_url = "$HS_URL"
hs_domain = "$HS_DOMAIN"
for service in services:
config_path = os.path.join(base_dir, service, "config.yaml")
if not os.path.exists(config_path):
print(f"[{service}] Config not found (run containers once to generate). Skipping.")
continue
print(f"[{service}] Updating config...")
try:
with open(config_path, 'r') as f:
data = yaml.load(f)
changed = False
# 1. Homeserver Config
if 'homeserver' not in data:
data['homeserver'] = {}
if data['homeserver'].get('address') != hs_url:
data['homeserver']['address'] = hs_url
changed = True
if data['homeserver'].get('domain') != hs_domain:
data['homeserver']['domain'] = hs_domain
changed = True
# 2. Appservice Listening (Docker fix)
# Bridges inside Docker must listen on 0.0.0.0 to be reachable from outside (if using HTTP push)
if 'appservice' in data:
if data['appservice'].get('address') != '0.0.0.0':
data['appservice']['address'] = '0.0.0.0'
changed = True
# Ensure registration path is standard
if data['appservice'].get('registration') != 'registration.yaml':
# We don't force this, but it's good practice
pass
if changed:
with open(config_path, 'w') as f:
yaml.dump(data, f)
print(f"[{service}] Updated.")
else:
print(f"[{service}] No changes needed.")
except Exception as e:
print(f"[{service}] Error: {e}")
PYTHON_SCRIPT
echo "[*] Applying configuration via Python container..."
docker run --rm \
-v "$(pwd):/work" \
-w /work \
python:3.11-slim \
sh -c "pip install ruamel.yaml && python apply_config.py"
rm apply_config.py
echo ""
echo "=== Done ==="
echo "Make sure you have copied the correct 'registration.yaml' to data/<service>/registration.yaml"
echo "Then run: docker compose restart"