From 77b260a2acc51144460484fd491f1192ba4d74e0 Mon Sep 17 00:00:00 2001 From: Abhilash Raj Date: Wed, 26 Jul 2017 03:23:00 -0700 Subject: [PATCH] Create a superuser if environment variables are defined. (#93) Create a superuser if environment variables are defined. --- README.md | 4 ++++ web/README.md | 4 ++++ web/assets/run.sh | 11 +++++++++++ 3 files changed, 19 insertions(+) diff --git a/README.md b/README.md index db131b6..e270a73 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,10 @@ These are the settings that you MUST change before deploying: - `HYPERKITTY_API_KEY`: Hyperkitty's API Key, should be set to the same value as set for the mailman-core. +- `MAILMAN_ADMIN_USER`: The username for the admin user to be created by default. + +- `MAILMAN_ADMIN_EMAIL`: The email for the admin user to be created by default. + For more details on how to configure this image, please look at [Mailman-web's Readme](web/README.md) diff --git a/web/README.md b/web/README.md index 958dc94..653fb89 100644 --- a/web/README.md +++ b/web/README.md @@ -17,6 +17,10 @@ These are the settings that you MUST change before deploying: - `HYPERKITTY_API_KEY`: Hyperkitty's API Key, should be set to the same value as set for the mailman-core. +- `MAILMAN_ADMIN_USER`: The username for the admin user to be created by default. + +- `MAILMAN_ADMIN_EMAIL`: The email for the admin user to be created by default. + These are the settings that are set to sane default and you do not need to change them unless you know what you want. diff --git a/web/assets/run.sh b/web/assets/run.sh index f2e7bde..063ecaa 100755 --- a/web/assets/run.sh +++ b/web/assets/run.sh @@ -89,6 +89,17 @@ 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" +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