Files
beeper-bridge-docker/setup_beeper_bridge.sh

155 lines
3.8 KiB
Bash
Executable File

#!/bin/bash
# Setup Script for Mautrix Telegram (Self-Hosted on Beeper)
# "The Robust Way" - No Bridge Manager, just clean Config
BRIDGE_SERVICE="telegram"
DATA_DIR="data/$BRIDGE_SERVICE"
CONFIG_FILE="$DATA_DIR/config.yaml"
REG_FILE="$DATA_DIR/registration.yaml"
echo "=== Beeper Bridge Setup: $BRIDGE_SERVICE ==="
echo "WARNING: This overwrites $DATA_DIR"
read -p "Continue? (y/N) " confirm
if [[ $confirm != [yY] && $confirm != [yY][eE][sS] ]]; then
exit 0
fi
mkdir -p "$DATA_DIR"
echo ""
echo "--- 1. Gathering Tokens ---"
# Try bbctl auto-discovery
if command -v bbctl &> /dev/null; then
echo "Found 'bbctl'. Fetching registration..."
BBCTL_OUT=$(bbctl register "sh-$BRIDGE_SERVICE" 2>&1)
if [ $? -eq 0 ]; then
YAML_CONTENT=$(echo "$BBCTL_OUT" | sed -n '/^id:/,$p')
if [ ! -z "$YAML_CONTENT" ]; then
echo "$YAML_CONTENT" > "$REG_FILE"
echo "Saved $REG_FILE"
fi
fi
fi
# Parsing
if [ -f "$REG_FILE" ]; then
get_yaml_val() { grep "^$1:" "$REG_FILE" | sed 's/^[^:]*: *//' | tr -d '\r'; }
REG_ID=$(get_yaml_val "id")
AS_TOKEN=$(get_yaml_val "as_token")
HS_TOKEN=$(get_yaml_val "hs_token")
BOT_USERNAME=$(get_yaml_val "sender_localpart")
fi
# Fallback
if [ -z "$REG_ID" ]; then
echo "bbctl failed or not found. Manual input needed."
read -p "ID: " REG_ID
read -p "AS Token: " AS_TOKEN
read -p "HS Token: " HS_TOKEN
DEFAULT_BOT="sh-${BRIDGE_SERVICE}bot"
read -p "Bot Username [$DEFAULT_BOT]: " BOT_USERNAME
BOT_USERNAME=${BOT_USERNAME:-$DEFAULT_BOT}
fi
echo ""
echo "--- 2. Telegram Credentials ---"
read -p "Telegram API ID: " API_ID
read -p "Telegram API Hash: " API_HASH
echo ""
echo "--- 3. Generating Config ---"
# Config optimized for Beeper + Websocket + No Pings
cat <<EOF > "$CONFIG_FILE"
homeserver:
address: https://matrix.beeper.com/_hungryserv/inswe
domain: beeper.local
verify_ssl: true
software: hungry
http_retry_count: 4
async_media: true
# Websocket is critical
websocket: true
# Disable Ping to avoid 502 errors
ping_interval_seconds: -1
appservice:
# Dummy address, bridge uses WS
address: http://localhost:29317
id: $REG_ID
bot_username: $BOT_USERNAME
as_token: $AS_TOKEN
hs_token: $HS_TOKEN
database: sqlite:////data/bridge.db
# Async transactions for Beeper
async_transactions: true
bridge:
username_template: ${BRIDGE_SERVICE}_{userid}
displayname_template: "{displayname} ($BRIDGE_SERVICE)"
permissions:
"*": relay
"beeper.local": user
"beeper.com": user
"@inswe:beeper.com": 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
echo "--- 4. Updating docker-compose.yml ---"
# Simple clean docker-compose rewrite to avoid sed mess
cat <<EOF > docker-compose.yml
services:
telegram:
container_name: beeper-telegram
image: dock.mau.dev/mautrix/telegram:latest
restart: unless-stopped
volumes:
- ./data/telegram:/data
environment:
- MAUTRIX_TELEGRAM_HOMESERVER_WEBSOCKET=true
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
EOF
echo ""
echo "Setup Done. Starting..."
docker compose up -d --force-recreate telegram
docker compose logs -f telegram