2018-01-27 22:26:37 +01:00
|
|
|
#!/bin/sh
|
2018-10-28 16:04:11 +01:00
|
|
|
set -ev
|
2017-06-25 20:49:41 +02:00
|
|
|
|
2018-10-26 15:02:11 +02:00
|
|
|
cd $(realpath $(dirname "${0}"))/install
|
2017-06-25 20:49:41 +02:00
|
|
|
|
2019-10-05 15:49:29 +02:00
|
|
|
# Create Postgres instance
|
|
|
|
mkdir -p /srv/sahana/postgres_data
|
|
|
|
chown -R 105432:105432 /srv/sahana/postgres_data
|
|
|
|
chmod 700 /srv/sahana/postgres_data
|
|
|
|
lxc-execute -n sahana-postgres -- initdb -D /var/lib/postgresql
|
|
|
|
|
|
|
|
# Configure Postgres
|
|
|
|
cp postgres_data/postgresql.conf /srv/sahana/postgres_data/postgresql.conf
|
|
|
|
cp postgres_data/pg_hba.conf /srv/sahana/postgres_data/pg_hba.conf
|
2017-09-21 21:12:29 +02:00
|
|
|
|
2017-06-25 20:49:41 +02:00
|
|
|
# Create PostgreSQL user and database
|
2019-06-05 18:55:15 +02:00
|
|
|
export SAHANA_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
2019-10-05 15:49:29 +02:00
|
|
|
service sahana-postgres start
|
|
|
|
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 sahana-postgres -- psql
|
2018-01-27 22:26:37 +01:00
|
|
|
|
|
|
|
# Prepare persistent directory structure
|
2019-10-05 15:49:29 +02:00
|
|
|
mkdir -p /srv/sahana/sahana_conf /srv/sahana/sahana_data/databases /srv/sahana/sahana_data/uploads
|
|
|
|
chown -R 108001:108001 /srv/sahana/sahana_conf
|
2019-10-05 16:01:55 +02:00
|
|
|
lxc-execute sahana -- tar -cC /srv/web2py/applications/eden/models . | tar -xC /srv/sahana/sahana_conf
|
2017-06-25 20:49:41 +02:00
|
|
|
|
2018-01-27 22:26:37 +01:00
|
|
|
# Copy Spotter template
|
2019-10-05 15:49:29 +02:00
|
|
|
cp -r sahana_data/Spotter /srv/sahana/sahana_data/
|
|
|
|
chown -R 108001:108001 /srv/sahana/sahana_data
|
2017-06-25 20:49:41 +02:00
|
|
|
|
|
|
|
# Configure Sahana
|
2019-06-05 18:55:15 +02:00
|
|
|
export SAHANA_HMAC=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
2017-09-14 21:56:09 +02:00
|
|
|
export SAHANA_ADMIN_USER=admin@example.com
|
2019-06-05 18:55:15 +02:00
|
|
|
export SAHANA_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
|
2019-10-05 15:49:29 +02:00
|
|
|
envsubst <sahana_conf/000_config.py >/srv/sahana/sahana_conf/000_config.py
|
|
|
|
envsubst <sahana_data/Spotter/masterUsers.csv >/srv/sahana/sahana_data/Spotter/masterUsers.csv
|
|
|
|
cp sahana_conf/00_settings.py /srv/sahana/sahana_conf/00_settings.py
|
2019-10-05 16:01:55 +02:00
|
|
|
chown -R 108001:108001 /srv/sahana/sahana_conf /srv/sahana/sahana_data
|
2017-06-25 20:49:41 +02:00
|
|
|
|
|
|
|
# Populate database
|
2018-09-13 22:09:01 +02:00
|
|
|
lxc-execute -u 8001 -g 8001 sahana -- sh -c 'cd /srv/web2py; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py'
|
2017-06-25 20:49:41 +02:00
|
|
|
|
2017-09-26 12:52:05 +02:00
|
|
|
# Set "production values" (increases performance) only if the DEBUG environment variable is not set
|
|
|
|
if [ ${DEBUG:-0} -eq 0 ]; then
|
2019-10-05 15:49:29 +02:00
|
|
|
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/' /srv/sahana/sahana_conf/000_config.py
|
|
|
|
sed -i 's/settings.base.debug = True/settings.base.debug = False/' /srv/sahana/sahana_conf/000_config.py
|
|
|
|
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sahana/sahana_conf/000_config.py
|
2017-09-13 13:17:38 +02:00
|
|
|
fi
|
2018-07-15 21:55:35 +02:00
|
|
|
|
2018-09-20 15:45:00 +02:00
|
|
|
# Install config update script
|
2019-10-05 15:49:29 +02:00
|
|
|
cp update-conf.sh /srv/sahana/update-conf.sh
|
2018-09-20 15:45:00 +02:00
|
|
|
|
2019-10-05 15:49:29 +02:00
|
|
|
# Stop services required for setup
|
|
|
|
service sahana-postgres stop
|
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 sahana sahana "${SAHANA_ADMIN_USER}" "${SAHANA_ADMIN_PWD}"
|