78 lines
2.8 KiB
Bash
Executable File
78 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -eu
|
|
|
|
echo "=> Setting up mautrix-whatsapp bridge"
|
|
|
|
# Create necessary directories
|
|
mkdir -p /app/data
|
|
mkdir -p /app/data/logs
|
|
|
|
# For Cloudron, we run as the cloudron user
|
|
UID=$(id -u cloudron)
|
|
GID=$(id -g cloudron)
|
|
|
|
# Set ownership early to avoid permission issues
|
|
chown -R cloudron:cloudron /app/data
|
|
|
|
# Configuration file paths
|
|
CONFIG_PATH="/app/data/config.yaml"
|
|
REGISTRATION_PATH="/app/data/registration.yaml"
|
|
BACKUP_PATH="/app/data/config.yaml.bak"
|
|
|
|
# Create example config from built-in template
|
|
if [ ! -f "$CONFIG_PATH" ]; then
|
|
echo "=> Generating example configuration"
|
|
# Generate config as root first, then fix permissions
|
|
/app/pkg/mautrix-whatsapp -g -c "$CONFIG_PATH" -r "$REGISTRATION_PATH"
|
|
|
|
# Configure for Cloudron environment
|
|
if [ -n "${CLOUDRON_POSTGRESQL_URL:-}" ]; then
|
|
echo "=> Configuring PostgreSQL database"
|
|
yq eval ".database = \"$CLOUDRON_POSTGRESQL_URL\"" -i "$CONFIG_PATH"
|
|
fi
|
|
|
|
if [ -n "${CLOUDRON_APP_DOMAIN:-}" ]; then
|
|
echo "=> Configuring homeserver and appservice settings"
|
|
BASE_DOMAIN=$(echo "$CLOUDRON_APP_DOMAIN" | cut -d. -f2-)
|
|
|
|
# Update homeserver configuration
|
|
yq eval ".homeserver.address = \"https://matrix.$BASE_DOMAIN\"" -i "$CONFIG_PATH"
|
|
yq eval ".homeserver.domain = \"$BASE_DOMAIN\"" -i "$CONFIG_PATH"
|
|
|
|
# Update appservice configuration
|
|
yq eval ".appservice.address = \"https://$CLOUDRON_APP_DOMAIN\"" -i "$CONFIG_PATH"
|
|
yq eval ".appservice.hostname = \"0.0.0.0\"" -i "$CONFIG_PATH"
|
|
yq eval ".appservice.port = 29318" -i "$CONFIG_PATH"
|
|
fi
|
|
|
|
# Set log file path
|
|
yq eval ".logging.handlers.file.filename = \"/app/data/logs/mautrix-whatsapp.log\"" -i "$CONFIG_PATH"
|
|
|
|
chown cloudron:cloudron "$CONFIG_PATH" "$REGISTRATION_PATH"
|
|
|
|
echo "=> Initial configuration complete"
|
|
echo "=> IMPORTANT: Please review $CONFIG_PATH and configure your Matrix homeserver settings"
|
|
echo "=> You will need to:"
|
|
echo " 1. Copy $REGISTRATION_PATH to your Matrix homeserver"
|
|
echo " 2. Update your homeserver configuration to include the registration file"
|
|
echo " 3. Restart your Matrix homeserver"
|
|
echo " 4. Restart this bridge app"
|
|
echo " 5. Authenticate with WhatsApp using QR code scanning"
|
|
else
|
|
echo "=> Using existing configuration"
|
|
fi
|
|
|
|
# Final permission fix before starting
|
|
chown -R cloudron:cloudron /app/data
|
|
|
|
# Configure TLS if certificates are available
|
|
if [ -f "/run/tls/tls.crt" ] && [ -f "/run/tls/tls.key" ]; then
|
|
echo "=> Configuring TLS certificates"
|
|
yq eval ".appservice.tls_cert = \"/run/tls/tls.crt\"" -i "$CONFIG_PATH"
|
|
yq eval ".appservice.tls_key = \"/run/tls/tls.key\"" -i "$CONFIG_PATH"
|
|
fi
|
|
|
|
# Start the bridge
|
|
echo "=> Starting mautrix-whatsapp bridge"
|
|
exec gosu cloudron:cloudron /app/pkg/mautrix-whatsapp -c "$CONFIG_PATH" |