From 525604bac40b7fc5e894b3eff981cbcaaa753b9a Mon Sep 17 00:00:00 2001 From: Abhilash Raj Date: Wed, 26 Jul 2017 04:11:58 -0700 Subject: [PATCH] Recreate default domain and fix #94. (#95) Provided MAILMAN_DEFAULT_DOMAIN environment variable, rename example.com with the provided domain name. Fix a bug where if the default username exists carry on without creating the superuser. Reuse the SERVE_FROM_DOMAIN instead of new MAILMAN_FROM_DOMAIN variable to set the default Django SITE. --- README.md | 4 +++- web/README.md | 4 +++- web/assets/run.sh | 18 +++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e270a73..60d2139 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,9 @@ mounted inside the containers. These are the settings that you MUST change before deploying: - `SERVE_FROM_DOMAIN`: The domain name from which Django will be served. To be - added to `ALLOWED_HOSTS` in django settings. Default value is not set. + added to `ALLOWED_HOSTS` in django settings. Default value is not set. This + also replaces Django's default `example.com` SITE and becomes the default SITE + (with SITE_ID=1). - `HYPERKITTY_API_KEY`: Hyperkitty's API Key, should be set to the same value as set for the mailman-core. diff --git a/web/README.md b/web/README.md index 653fb89..700af92 100644 --- a/web/README.md +++ b/web/README.md @@ -12,7 +12,9 @@ Configuration These are the settings that you MUST change before deploying: - `SERVE_FROM_DOMAIN`: The domain name from which Django will be served. To be - added to `ALLOWED_HOSTS` in django settings. Default value is not set. + added to `ALLOWED_HOSTS` in django settings. Default value is not set. This + also replaces Django's default `example.com` SITE and becomes the default SITE + (with SITE_ID=1). - `HYPERKITTY_API_KEY`: Hyperkitty's API Key, should be set to the same value as set for the mailman-core. diff --git a/web/assets/run.sh b/web/assets/run.sh index 063ecaa..d97dc8c 100755 --- a/web/assets/run.sh +++ b/web/assets/run.sh @@ -89,20 +89,28 @@ python manage.py collectstatic --noinput # this command will upgrade the database. python manage.py migrate - - # If MAILMAN_ADMIN_USER and MAILMAN_ADMIN_EMAIL is defined create a new # superuser for Django. There is no password setup so it can't login yet unless # the password is reset. if [[ -v MAILMAN_ADMIN_USER ]] && [[ -v MAILMAN_ADMIN_EMAIL ]]; then - echo "Creating admin user..." - python manage.py createsuperuser --noinput --username "$MAILMAN_ADMIN_USER" --email "$MAILMAN_ADMIN_EMAIL" + echo "Creating admin user $MAILMAN_ADMIN_USER ..." + python manage.py createsuperuser --noinput --username "$MAILMAN_ADMIN_USER"\ + --email "$MAILMAN_ADMIN_EMAIL" 2> /dev/null || \ + echo "Superuser $MAILMAN_ADMIN_USER already exists" +fi + +# If SERVE_FROM_DOMAIN is defined then rename the default `example.com` +# domain to the defined domain. +if [[ -v SERVE_FROM_DOMAIN ]]; +then + echo "Setting $MAILMAN_DEFAULT_DOMAIN as the default domain ..." + python manage.py shell -c \ + "from django.contrib.sites.models import Site; Site.objects.filter(domain='example.com').update(domain='$SERVE_FROM_DOMAIN')" fi # Create a mailman user with the specific UID and GID and do not create home # directory for it. Also chown the logs directory to write the files. chown mailman:mailman /opt/mailman-web-data -R - exec $@