From fe852ed8b9eddd6420a650eaa1feda01551d6e4a Mon Sep 17 00:00:00 2001 From: Gemini Bot Date: Sat, 6 Dec 2025 18:34:58 +0000 Subject: [PATCH] Add setup_beeper_bridge.sh for clean installation --- setup_beeper_bridge.sh | 185 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100755 setup_beeper_bridge.sh diff --git a/setup_beeper_bridge.sh b/setup_beeper_bridge.sh new file mode 100755 index 0000000..5dfd671 --- /dev/null +++ b/setup_beeper_bridge.sh @@ -0,0 +1,185 @@ +#!/bin/bash + +# Beeper Bridge "Green Field" Setup Script +# This script sets up a Mautrix bridge for Beeper from scratch. +# It overwrites existing configurations to ensure a clean state. + +BRIDGE_SERVICE=$1 + +if [ -z "$BRIDGE_SERVICE" ]; then + echo "Usage: ./setup_beeper_bridge.sh " + echo "Example: ./setup_beeper_bridge.sh telegram" + exit 1 +fi + +DATA_DIR="data/$BRIDGE_SERVICE" +CONFIG_FILE="$DATA_DIR/config.yaml" +REG_FILE="$DATA_DIR/registration.yaml" + +echo "==================================================" +echo " Beeper Bridge Setup: $BRIDGE_SERVICE" +echo "==================================================" +echo "Warning: This will OVERWRITE contents in $DATA_DIR" +read -p "Continue? (y/N) " confirm +if [[ $confirm != [yY] && $confirm != [yY][eE][sS] ]]; then + exit 0 +fi + +mkdir -p "$DATA_DIR" + +# --- Step 1: Gather Information --- + +echo "" +echo "--- 1. Beeper Registration ---" +echo "Please run 'bbctl register sh-$BRIDGE_SERVICE' on your machine (or retrieve existing values)." +echo "Enter the values below:" + +read -p "ID (e.g., 99ab27...): " REG_ID +while [[ -z "$REG_ID" ]]; do read -p "ID cannot be empty: " REG_ID; done + +read -p "AS Token (e.g., Agqb...): " AS_TOKEN +while [[ -z "$AS_TOKEN" ]]; do read -p "AS Token cannot be empty: " AS_TOKEN; done + +read -p "HS Token (e.g., bR5t...): " HS_TOKEN +while [[ -z "$HS_TOKEN" ]]; do read -p "HS Token cannot be empty: " HS_TOKEN; done + +# Default Beeper values (can be overridden but we default to what we saw in logs) +DEFAULT_HS_URL="https://matrix.beeper.com/_hungryserv/inswe" +read -p "Homeserver URL [$DEFAULT_HS_URL]: " HS_URL +HS_URL=${HS_URL:-$DEFAULT_HS_URL} + +DEFAULT_DOMAIN="beeper.local" +read -p "Homeserver Domain [$DEFAULT_DOMAIN]: " HS_DOMAIN +HS_DOMAIN=${HS_DOMAIN:-$DEFAULT_DOMAIN} + +DEFAULT_USER="@inswe:beeper.com" +read -p "Your Admin User ID [$DEFAULT_USER]: " ADMIN_USER +ADMIN_USER=${ADMIN_USER:-$DEFAULT_USER} + +DEFAULT_BOT="sh-${BRIDGE_SERVICE}bot" +read -p "Bot Username (Localpart) [$DEFAULT_BOT]: " BOT_USERNAME +BOT_USERNAME=${BOT_USERNAME:-$DEFAULT_BOT} + + +echo "" +echo "--- 2. Bridge Specifics ($BRIDGE_SERVICE) ---" + +if [ "$BRIDGE_SERVICE" == "telegram" ]; then + read -p "Telegram API ID: " API_ID + read -p "Telegram API Hash: " API_HASH +fi + +# --- Step 2: Generate registration.yaml --- +echo "" +echo "Generating registration.yaml..." + +cat < "$REG_FILE" +id: $REG_ID +url: websocket +as_token: $AS_TOKEN +hs_token: $HS_TOKEN +sender_localpart: $BOT_USERNAME +namespaces: + users: + - regex: ' @${BOT_USERNAME}_.+:${HS_DOMAIN//.\/\\./}' + exclusive: true +receive_ephemeral: true +EOF + +# --- Step 3: Generate config.yaml (Hardcoded Template) --- +echo "Generating config.yaml..." + +# Escape domain for regex in config if needed, but standard string is fine for config +# We use a minimal but complete config optimized for Beeper + +cat < "$CONFIG_FILE" +homeserver: + address: $HS_URL + domain: $HS_DOMAIN + verify_ssl: true + software: hungry + http_retry_count: 4 + async_media: true + + # Force websocket usage (Beeper requirement) + websocket: true + +appservice: + address: http://localhost:29317 + id: $REG_ID + bot_username: $BOT_USERNAME + + as_token: $AS_TOKEN + hs_token: $HS_TOKEN + + database: sqlite:////data/bridge.db + + # Community advice for Beeper: + async_transactions: true + +bridge: + username_template: ${BRIDGE_SERVICE}_{userid} + displayname_template: "{displayname} ($BRIDGE_SERVICE)" + + permissions: + "*": relay + "$HS_DOMAIN": user + "beeper.com": user + "$ADMIN_USER": admin + + relay: + enabled: true + admin_only: false + +logging: + 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] + +telegram: + api_id: $API_ID + api_hash: $API_HASH + device_info: + device_model: "Beeper Bridge" + system_version: "Docker" + app_version: "0.1" +EOF + +# --- Step 4: Fix Docker Compose (Environment Override) --- +# We ensure MAUTRIX_TELEGRAM_HOMESERVER_WEBSOCKET is set in docker-compose.yml +# This is a bit hacky but ensures we win against any config parsing issues. + +COMPOSE_FILE="docker-compose.yml" +if grep -q "MAUTRIX_TELEGRAM_HOMESERVER_WEBSOCKET" "$COMPOSE_FILE"; then + echo "Env var already present in docker-compose.yml" +else + echo "Adding Websocket Environment Variable to docker-compose.yml..." + # We use sed to insert environment block if missing, or append to it. + # Simplified: We just warn the user or append it if we find the service. + # To be safe/lazy: We rely on the config.yaml 'websocket: true' first. + # But let's append it to the file via sed for the telegram service specifically. + + # Using a temporary file to construct the patch + sed -i '/container_name: beeper-telegram/a \ environment:\n - MAUTRIX_TELEGRAM_HOMESERVER_WEBSOCKET=true' "$COMPOSE_FILE" +fi + +# --- Step 5: Start --- +echo "" +echo "Setup Complete." +echo "Starting container..." + +docker compose up -d $BRIDGE_SERVICE --force-recreate + +echo "" +echo "Logs:" +docker compose logs -f $BRIDGE_SERVICE