95 lines
2.6 KiB
Bash
Executable File
95 lines
2.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# FINAL FINAL ATTEMPT (Template Version)
|
|
# Uses config.template.yaml to ensure YAML syntax is perfect.
|
|
|
|
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"
|
|
|
|
# --- Token Gathering ---
|
|
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"
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
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
|
|
|
|
if [ -z "$REG_ID" ]; then
|
|
echo "Manual input needed."
|
|
read -p "ID: " REG_ID
|
|
read -p "AS Token: " AS_TOKEN
|
|
read -p "HS Token: " HS_TOKEN
|
|
read -p "Bot Username: " BOT_USERNAME
|
|
fi
|
|
|
|
if [ -z "$API_ID" ]; then
|
|
read -p "Telegram API ID: " API_ID
|
|
read -p "Telegram API Hash: " API_HASH
|
|
fi
|
|
|
|
# --- Config Generation via Template ---
|
|
if [ ! -f "config.template.yaml" ]; then
|
|
echo "Error: config.template.yaml not found! Please git pull."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Generating config.yaml from template..."
|
|
cp config.template.yaml "$CONFIG_FILE"
|
|
|
|
# Replace placeholders using sed
|
|
# We use | as delimiter to avoid issues with slashes in tokens
|
|
sed -i "s|REPLACE_REG_ID|$REG_ID|g" "$CONFIG_FILE"
|
|
sed -i "s|REPLACE_BOT_USERNAME|$BOT_USERNAME|g" "$CONFIG_FILE"
|
|
sed -i "s|REPLACE_AS_TOKEN|$AS_TOKEN|g" "$CONFIG_FILE"
|
|
sed -i "s|REPLACE_HS_TOKEN|$HS_TOKEN|g" "$CONFIG_FILE"
|
|
sed -i "s|REPLACE_API_ID|$API_ID|g" "$CONFIG_FILE"
|
|
sed -i "s|REPLACE_API_HASH|$API_HASH|g" "$CONFIG_FILE"
|
|
|
|
echo "Config generated."
|
|
|
|
# --- Docker Compose ---
|
|
cat <<EOF > docker-compose.yml
|
|
services:
|
|
telegram:
|
|
container_name: beeper-telegram
|
|
image: dock.mau.dev/mautrix/telegram:latest
|
|
restart: unless-stopped
|
|
network_mode: "host"
|
|
volumes:
|
|
- ./data/telegram:/data
|
|
environment:
|
|
- MAUTRIX_TELEGRAM_HOMESERVER_WEBSOCKET=true
|
|
logging:
|
|
driver: json-file
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
EOF
|
|
|
|
echo "Starting..."
|
|
docker compose up -d --force-recreate telegram
|
|
docker compose logs -f telegram
|