2020-04-14 14:17:21 +02:00
|
|
|
#!/bin/sh
|
|
|
|
set -ev
|
|
|
|
|
|
|
|
# Volumes
|
|
|
|
POSTGRES_DATA="${VOLUMES_DIR}/safire/postgres_data"
|
|
|
|
SAHANA_DATA="${VOLUMES_DIR}/safire/sahana_data"
|
|
|
|
SAHANA_CONF="${VOLUMES_DIR}/safire/sahana_conf"
|
2020-05-04 11:04:29 +02:00
|
|
|
SAHANA_LAYER="${LAYERS_DIR}/sahana_1.0.3-200504"
|
2020-04-14 14:17:21 +02:00
|
|
|
|
|
|
|
# Create Postgres instance
|
|
|
|
install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}
|
|
|
|
spoc-container exec safire-postgres -- initdb -D /var/lib/postgresql
|
|
|
|
|
|
|
|
# Configure Postgres
|
|
|
|
install -o 105432 -g 105432 -m 600 postgres_data/postgresql.conf ${POSTGRES_DATA}/postgresql.conf
|
|
|
|
install -o 105432 -g 105432 -m 600 postgres_data/pg_hba.conf ${POSTGRES_DATA}/pg_hba.conf
|
|
|
|
|
|
|
|
# Create PostgreSQL user and database
|
|
|
|
export SAFIRE_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
|
|
|
spoc-container start safire-postgres
|
|
|
|
envsubst <createdb.sql | spoc-container exec safire-postgres -- psql
|
|
|
|
|
|
|
|
# Prepare persistent directory structure
|
|
|
|
install -o 108080 -g 108080 -m 750 -d ${SAHANA_DATA}/databases
|
2020-05-04 11:06:50 +02:00
|
|
|
install -o 108080 -g 108080 -m 750 -d ${SAHANA_DATA}/errors
|
|
|
|
install -o 108080 -g 108080 -m 750 -d ${SAHANA_DATA}/sessions
|
2020-04-14 14:17:21 +02:00
|
|
|
install -o 108080 -g 108080 -m 750 -d ${SAHANA_DATA}/uploads
|
|
|
|
cp -rp ${SAHANA_LAYER}/srv/web2py/applications/eden/models ${SAHANA_CONF}
|
|
|
|
cp -rp ${SAHANA_LAYER}/srv/web2py/applications/eden/modules/templates/SAFIRE ${SAHANA_DATA}/SAFIRE
|
|
|
|
|
|
|
|
# Configure SAFIRE
|
|
|
|
export SAFIRE_HMAC=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
|
|
|
export SAFIRE_ADMIN_USER="admin@example.com"
|
|
|
|
export SAFIRE_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
|
|
|
|
envsubst <sahana_conf/000_config.py | install -o 108080 -g 108080 -m 640 /dev/stdin ${SAHANA_CONF}/000_config.py
|
|
|
|
envsubst <sahana_data/masterUsers.csv | install -o 108080 -g 108080 -m 640 /dev/stdin ${SAHANA_DATA}/masterUsers.csv
|
|
|
|
install -o 108080 -g 108080 -m 640 sahana_conf/00_settings.py ${SAHANA_CONF}/00_settings.py
|
|
|
|
install -o 108080 -g 108080 -m 640 sahana_data/SAFIRE/config.py ${SAHANA_DATA}/SAFIRE/config.py
|
|
|
|
|
|
|
|
# Populate database
|
|
|
|
spoc-container exec -u sahana safire -- sh -c 'cd /srv/web2py; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py'
|
|
|
|
|
|
|
|
# Set "production values" (increases performance) only if the DEBUG environment variable is not set
|
|
|
|
if [ ${DEBUG:-0} -eq 0 ]; then
|
|
|
|
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/' ${SAHANA_CONF}/000_config.py
|
|
|
|
sed -i 's/settings.base.debug = True/settings.base.debug = False/' ${SAHANA_CONF}/000_config.py
|
|
|
|
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' ${SAHANA_CONF}/000_config.py
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Stop services required for setup
|
|
|
|
spoc-container stop safire-postgres
|
|
|
|
|
|
|
|
# Register application
|
|
|
|
vmmgr register-app safire safire "${SAFIRE_ADMIN_USER}" "${SAFIRE_ADMIN_PWD}"
|