Add setup_beeper_bridge.sh for clean installation

This commit is contained in:
Gemini Bot
2025-12-06 18:34:58 +00:00
parent 59d84661f5
commit fe852ed8b9

185
setup_beeper_bridge.sh Executable file
View File

@@ -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 <service>"
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 <<EOF > "$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 <<EOF > "$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