Replace hardcoded setup with interactive bridge config tool

This commit is contained in:
Gemini Bot
2025-12-06 03:00:38 +00:00
parent d16ba38411
commit bebd7534da
2 changed files with 105 additions and 91 deletions

View File

@@ -1,91 +0,0 @@
#!/bin/bash
echo "=== Beeper Bridge Configuration Helper ==="
echo "This script sets the Beeper Homeserver details in your bridge configs."
echo "Run this on the REMOTE server."
cat << 'PYTHON_SCRIPT' > apply_beeper_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"
# Beeper Standard Config
HS_ADDRESS = "https://matrix.beeper.com"
HS_DOMAIN = "beeper.com"
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 missing. Skipping.")
continue
print(f"[{service}] Updating homeserver config...")
try:
with open(config_path, 'r') as f:
data = yaml.load(f)
changed = False
# Ensure homeserver section exists
if 'homeserver' not in data:
data['homeserver'] = {}
if data['homeserver'].get('address') != HS_ADDRESS:
data['homeserver']['address'] = HS_ADDRESS
changed = True
if data['homeserver'].get('domain') != HS_DOMAIN:
data['homeserver']['domain'] = HS_DOMAIN
changed = True
# Fix Appservice listening port/address if needed (Standard Docker internal)
# The bridge listens on 0.0.0.0:29317 (etc) internally usually, but
# let's just ensure 'address' in 'appservice' is 0.0.0.0 so it accepts docker traffic?
# Actually, let's not touch appservice.address unless requested, default is usually localhost or ::1 which might break in docker.
# Docker images usually default to 0.0.0.0.
if changed:
with open(config_path, 'w') as f:
yaml.dump(data, f)
print(f"[{service}] Updated homeserver to {HS_DOMAIN}.")
else:
print(f"[{service}] Config already correct.")
except Exception as e:
print(f"[{service}] Error: {e}")
PYTHON_SCRIPT
echo "[*] Applying configuration..."
docker run --rm \
-v "$(pwd):/work" \
-w /work \
python:3.11-slim \
sh -c "pip install ruamel.yaml && python apply_beeper_config.py"
rm apply_beeper_config.py
echo ""
echo "=== IMPORTANT NEXT STEPS ==="
echo "1. REGISTRATION FILES:"
echo " You must generate 'registration.yaml' for each bridge using 'bbctl' on your local machine."
echo " Example: 'bbctl register googlechat'"
echo " Then upload the resulting 'registration.yaml' to 'data/googlechat/registration.yaml' on this server."
echo ""
echo " If you see 'as_token was not accepted' in logs, your registration.yaml is wrong or mismatching."
echo ""
echo "2. RESTART:"
echo " After uploading the registration files, run: docker compose restart"

105
configure_bridges.sh Normal file
View File

@@ -0,0 +1,105 @@
#!/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"