#! /bin/bash set -e function wait_for_postgres () { # Check if the postgres database is up and accepting connections before # moving forward. # TODO: Use python's psycopg2 module to do this in python instead of # installing postgres-client in the image. until psql $DATABASE_URL -c '\l'; do >&2 echo "Postgres is unavailable - sleeping" sleep 1 done >&2 echo "Postgres is up - continuing" } function wait_for_mysql () { # Check if MySQL is up and accepting connections. HOSTNAME=$(python3 -c "from urllib.parse import urlparse; o = urlparse('$DATABASE_URL'); print(o.hostname);") until mysqladmin ping --host "$HOSTNAME" --silent; do >&2 echo "MySQL is unavailable - sleeping" sleep 1 done >&2 echo "MySQL is up - continuing" } # Empty the config file. echo "# This file is autogenerated at container startup." > /etc/mailman.cfg # Check if $MM_HOSTNAME is set, if not, set it to the value returned by # `hostname -i` command to set it to whatever IP address is assigned to the # container. if [[ ! -v MM_HOSTNAME ]]; then export MM_HOSTNAME=`hostname -i` fi if [[ ! -v SMTP_HOST ]]; then export SMTP_HOST='172.19.199.1' fi if [[ ! -v SMTP_PORT ]]; then export SMTP_PORT=25 fi function setup_database () { if [[ ! -v DATABASE_URL ]] then echo "Environemnt variable DATABASE_URL should be defined..." exit 1 fi # Translate mysql:// urls to mysql+mysql:// backend: if [[ "$DATABASE_URL" == mysql://* ]]; then DATABASE_URL="mysql+pymysql://${DATABASE_URL:8}" echo "Database URL was automatically rewritten to: $DATABASE_URL" fi # If DATABASE_CLASS is not set, guess it for common databases: if [ -z "$DATABASE_CLASS" ]; then if [[ ("$DATABASE_URL" == mysql:*) || ("$DATABASE_URL" == mysql+*) ]]; then DATABASE_CLASS=mailman.database.mysql.MySQLDatabase fi if [[ ("$DATABASE_URL" == postgres:*) || ("$DATABASE_URL" == postgres+*) ]]; then DATABASE_CLASS=mailman.database.postgresql.PostgreSQLDatabase fi fi cat >> /etc/mailman.cfg <> /etc/mailman.cfg < /etc/postfix-mailman.cfg <> /etc/mailman.cfg fi if [[ ! -v HYPERKITTY_API_KEY ]]; then echo "HYPERKITTY_API_KEY not defined, please set this environment variable..." echo "exiting..." exit 1 fi if [[ ! -v HYPERKITTY_URL ]]; then echo "HYPERKITTY_URL not set, using the default value of http://mailman-web:8000/hyperkitty" export HYPERKITTY_URL="http://mailman-web:8000/hyperkitty/" fi # Generate a basic mailman-hyperkitty.cfg. cat > /etc/mailman-hyperkitty.cfg <