#!/bin/sh

# Fail the whole script on the first failure.
set -e

cat <<EOF > /etc/ihatemoney/ihatemoney.cfg
DEBUG = $DEBUG
ACTIVATE_ADMIN_DASHBOARD = $ACTIVATE_ADMIN_DASHBOARD
ACTIVATE_DEMO_PROJECT = $ACTIVATE_DEMO_PROJECT
ADMIN_PASSWORD = '$ADMIN_PASSWORD'
ALLOW_PUBLIC_PROJECT_CREATION = $ALLOW_PUBLIC_PROJECT_CREATION
BABEL_DEFAULT_TIMEZONE = "$BABEL_DEFAULT_TIMEZONE"
MAIL_DEFAULT_SENDER = "$MAIL_DEFAULT_SENDER"
MAIL_PASSWORD = "$MAIL_PASSWORD"
MAIL_PORT = $MAIL_PORT
MAIL_SERVER = "$MAIL_SERVER"
MAIL_USE_SSL = $MAIL_USE_SSL
MAIL_USE_TLS = $MAIL_USE_TLS
MAIL_USERNAME = "$MAIL_USERNAME"
SECRET_KEY = "$SECRET_KEY"
SESSION_COOKIE_SECURE = $SESSION_COOKIE_SECURE
SQLACHEMY_DEBUG = DEBUG
SQLALCHEMY_DATABASE_URI = "$SQLALCHEMY_DATABASE_URI"
SQLALCHEMY_TRACK_MODIFICATIONS = $SQLALCHEMY_TRACK_MODIFICATIONS
ENABLE_CAPTCHA = $ENABLE_CAPTCHA
LEGAL_LINK = "$LEGAL_LINK"
EOF

# Start gunicorn without forking
exec gunicorn ihatemoney.wsgi:application \
     -b 0.0.0.0:8000 \
     --log-syslog \
     "$@"
