commit 19050d5e60c083fa3074cd6523e4eb78d808698d Author: Roger Gonzalez Date: Wed Nov 27 16:05:31 2024 -0300 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..daef273 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.DS_Store +.idea +*.log +tmp/ + +./config/dendrite/* diff --git a/README.md b/README.md new file mode 100644 index 0000000..8fe612d --- /dev/null +++ b/README.md @@ -0,0 +1,68 @@ +# Dendrite Docker Bridges + +A simple way to set up Dendrite with bridges for WhatsApp, Telegram, and Discord. + +## Before Starting + +1. Make sure you set up your domain by following this documentation: [Dendrite Domain Name Setup](https://element-hq.github.io/dendrite/installation/domainname). + +2. Ensure you have `docker` and `docker compose` installed on your server. + +3. All commands will be executed in the project root, i.e., the directory where the repository was cloned. + +## Installation + +1. Clone this repository and enter the directory: + +```sh +git clone https://gitlab.com/rogs/dendrite-docker-bridges.git +cd dendrite-docker-bridges +``` + +2. Run `setup.sh`: + +```sh +./setup.sh +``` + +This script will prompt you for your domain (the one you configured in "Before Starting") and create your private key and config in the `./config/dendrite` directory. When it finishes, make sure to copy the "Registration shared secret," as you will need it for the next step. + +3. Open your configuration file located at `./config/dendrite/dendrite.yaml`. **You may need `sudo` to edit this file.** Search for `registration_shared_secret` and paste the registration secret you copied in the previous step. The section should look similar to this: + +```yaml +client_api: + registration_disabled: true + registration_requires_token: false + registration_shared_secret: "YourBigCopiedKey123" # This is your key! + guests_disabled: false + enable_registration_captcha: false + recaptcha_api_js_url: "" +``` + +4. Start Dendrite: + +```sh +docker compose up -d postgres monolith +``` + +5. Run `setup-db.sh`: + +```sh +./setup-db.sh +``` + +This script will create three new databases: `whatsapp`, `telegram`, and `discord`. These will be used later for the bridges. + +6. Verify the setup by navigating to `http://your-ip-address:8008` in your browser. You should see a screen similar to this: + +```sh +# TODO Add picture +``` + +## That's It! + +Dendrite is now up and running! You can proceed with setting up the bridges: + +- [WhatsApp Bridge](./config/mautrix-whatsapp/README.md) +- [Telegram Bridge](./config/mautrix-telegram/README.md) +- [Discord Bridge](./config/mautrix-discord/README.md) diff --git a/config/mautrix-discord/README.md b/config/mautrix-discord/README.md new file mode 100644 index 0000000..4640904 --- /dev/null +++ b/config/mautrix-discord/README.md @@ -0,0 +1 @@ +# TODO diff --git a/config/mautrix-telegram/README.md b/config/mautrix-telegram/README.md new file mode 100644 index 0000000..4640904 --- /dev/null +++ b/config/mautrix-telegram/README.md @@ -0,0 +1 @@ +# TODO diff --git a/config/mautrix-whatsapp/README.md b/config/mautrix-whatsapp/README.md new file mode 100644 index 0000000..4640904 --- /dev/null +++ b/config/mautrix-whatsapp/README.md @@ -0,0 +1 @@ +# TODO diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..38f7b77 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,66 @@ +services: + postgres: + hostname: postgres + image: postgres:15-alpine + restart: unless-stopped + volumes: + - ./config/postgres:/var/lib/postgresql/data + environment: + POSTGRES_PASSWORD: itsasecret + POSTGRES_USER: dendrite + POSTGRES_DATABASE: dendrite + healthcheck: + test: ["CMD-SHELL", "pg_isready -U dendrite"] + interval: 5s + timeout: 5s + retries: 5 + + monolith: + hostname: monolith + image: matrixdotorg/dendrite-monolith:latest + ports: + - 8008:8008 + - 8448:8448 + volumes: + - ./config/dendrite:/etc/dendrite + - ./config/mautrix-whatsapp:/etc/whatsapp + - ./config/mautrix-telegram:/etc/telegram + - ./config/mautrix-discord:/etc/discord + - ./config/media:/var/dendrite/media + - ./config/jetstream:/var/dendrite/jetstream + - ./config/search_index:/var/dendrite/searchindex + depends_on: + postgres: + condition: service_healthy + restart: unless-stopped + + mautrix-whatsapp: + hostname: whatsapp + image: dock.mau.dev/mautrix/whatsapp + restart: unless-stopped + volumes: + - ./config/mautrix-whatsapp:/data + command: ["/usr/bin/mautrix-whatsapp", "--ignore-unsupported-server"] + depends_on: + postgres: + condition: service_healthy + + mautrix-telegram: + hostname: telegram + image: dock.mau.dev/mautrix/telegram + restart: unless-stopped + volumes: + - ./config/mautrix-telegram:/data + depends_on: + postgres: + condition: service_healthy + + mautrix-discord: + hostname: discord + image: dock.mau.dev/mautrix/discord + restart: unless-stopped + volumes: + - ./config/mautrix-discord:/data + depends_on: + postgres: + condition: service_healthy diff --git a/setup-db.sh b/setup-db.sh new file mode 100755 index 0000000..43cce14 --- /dev/null +++ b/setup-db.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Check if the postgres service is running +docker compose ps postgres | grep "Up" > /dev/null +if [ $? -ne 0 ]; then + echo "The postgres service is not running. Please start it with 'docker compose up -d' and try again." + exit 1 +fi + +# Define database names and user +DATABASES=("whatsapp" "telegram" "discord") +USER="dendrite" + +# Create databases and grant permissions +for DB in "${DATABASES[@]}"; do + echo "Creating database $DB..." + docker compose exec -T postgres psql -U "$USER" -c "CREATE DATABASE $DB;" + docker compose exec -T postgres psql -U "$USER" -c "GRANT ALL PRIVILEGES ON DATABASE $DB TO $USER;" + echo "Database $DB created and permissions granted." +done + +echo "All databases created successfully." diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..be6ff7b --- /dev/null +++ b/setup.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Prompt for domain input +read -p "Enter your domain (e.g., example.com): " DOMAIN +if [[ -z "$DOMAIN" ]]; then + echo "Domain cannot be empty. Exiting." + exit 1 +fi + +# Generate private keys +echo "Generating private keys..." +docker run --rm --entrypoint="/usr/bin/generate-keys" \ + -v $(pwd)/config/dendrite:/mnt \ + matrixdotorg/dendrite-monolith:latest \ + -private-key /mnt/matrix_key.pem + +# Generate configuration +echo "Generating configuration with domain: $DOMAIN..." +docker run --rm --entrypoint="/bin/sh" \ + -v $(pwd)/config/dendrite:/mnt \ + matrixdotorg/dendrite-monolith:latest \ + -c "/usr/bin/generate-config \ + -dir /var/dendrite/ \ + -db postgres://dendrite:itsasecret@postgres/dendrite?sslmode=disable \ + -server $DOMAIN > /mnt/dendrite.yaml" + +# Generate and display the registration shared secret +SHARED_SECRET=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 50) +echo +echo "Registration shared secret: $SHARED_SECRET" +echo "Make sure to copy it!"