2018-02-06 19:05:38 +01:00
|
|
|
#!/bin/sh
|
2018-10-28 16:04:11 +01:00
|
|
|
set -ev
|
2017-09-16 18:55:19 +02:00
|
|
|
|
2020-03-22 20:59:26 +01:00
|
|
|
# Volumes
|
|
|
|
POSTGRES_DATA="${VOLUMES_DIR}/sambro/postgres_data"
|
|
|
|
SAHANA_DATA="${VOLUMES_DIR}/sambro/sahana_data"
|
|
|
|
SAHANA_CONF="${VOLUMES_DIR}/sambro/sahana_conf"
|
2020-10-22 23:05:01 +02:00
|
|
|
SAHANA_LAYER="${LAYERS_DIR}/sahana_1.0.3-201021"
|
2020-03-22 20:59:26 +01:00
|
|
|
|
2019-10-05 16:10:29 +02:00
|
|
|
# Create Postgres instance
|
2020-03-22 20:59:26 +01:00
|
|
|
install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}
|
|
|
|
spoc-container exec sambro-postgres -- initdb -D /var/lib/postgresql
|
2019-10-05 16:10:29 +02:00
|
|
|
|
|
|
|
# Configure Postgres
|
2020-03-22 20:59:26 +01:00
|
|
|
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
|
2017-09-21 21:12:29 +02:00
|
|
|
|
2017-09-16 18:55:19 +02:00
|
|
|
# Create PostgreSQL user and database
|
2019-06-05 18:55:15 +02:00
|
|
|
export SAMBRO_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
2020-03-22 20:59:26 +01:00
|
|
|
spoc-container start sambro-postgres
|
|
|
|
envsubst <createdb.sql | spoc-container exec sambro-postgres -- psql
|
2017-09-16 18:55:19 +02:00
|
|
|
|
2018-01-28 09:13:30 +01:00
|
|
|
# Prepare persistent directory structure
|
2020-03-22 20:59:26 +01:00
|
|
|
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-03-22 20:59:26 +01:00
|
|
|
install -o 108080 -g 108080 -m 750 -d ${SAHANA_DATA}/uploads
|
2020-03-23 10:10:57 +01:00
|
|
|
cp -rp ${SAHANA_LAYER}/srv/web2py/applications/eden/models ${SAHANA_CONF}
|
|
|
|
cp -rp ${SAHANA_LAYER}/srv/web2py/applications/eden/modules/templates/SAMBRO ${SAHANA_DATA}/SAMBRO
|
2017-09-16 18:55:19 +02:00
|
|
|
|
2018-01-28 09:13:30 +01:00
|
|
|
# Configure SAMBRO
|
2019-06-05 18:55:15 +02:00
|
|
|
export SAMBRO_HMAC=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
2020-04-10 11:21:39 +02:00
|
|
|
export SAMBRO_ADMIN_USER="admin@example.com"
|
2019-06-05 18:55:15 +02:00
|
|
|
export SAMBRO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
|
2020-03-22 20:59:26 +01:00
|
|
|
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/SAMBRO/config.py ${SAHANA_DATA}/SAMBRO/config.py
|
2017-09-16 18:55:19 +02:00
|
|
|
|
|
|
|
# Populate database
|
2020-03-22 20:59:26 +01:00
|
|
|
spoc-container exec -u sahana sambro -- sh -c 'cd /srv/web2py; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py'
|
2017-09-16 18:55:19 +02:00
|
|
|
|
2020-06-21 20:10:21 +02:00
|
|
|
# Set production values to increases performance
|
|
|
|
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
|
2018-07-15 21:55:35 +02:00
|
|
|
|
2019-10-05 16:10:29 +02:00
|
|
|
# Stop services required for setup
|
2020-03-22 20:59:26 +01:00
|
|
|
spoc-container stop sambro-postgres
|
2018-10-28 19:50:35 +01:00
|
|
|
|
2018-11-03 15:53:51 +01:00
|
|
|
# Register application
|
2019-02-26 21:12:41 +01:00
|
|
|
vmmgr register-app sambro sambro "${SAMBRO_ADMIN_USER}" "${SAMBRO_ADMIN_PWD}"
|