2018-01-27 22:26:37 +01:00
|
|
|
#!/bin/sh
|
2018-07-15 21:55:35 +02:00
|
|
|
set -e
|
2017-06-25 20:49:41 +02:00
|
|
|
|
2018-10-25 22:22:36 +02:00
|
|
|
cd $(realpath $(dirname "${0}"))/setup
|
2017-06-25 20:49:41 +02:00
|
|
|
|
2018-01-27 22:26:37 +01:00
|
|
|
# Check prerequisites
|
2018-09-13 22:09:01 +02:00
|
|
|
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
|
2017-09-21 21:12:29 +02:00
|
|
|
|
2017-06-25 20:49:41 +02:00
|
|
|
# Create PostgreSQL user and database
|
2017-09-01 14:25:17 +02:00
|
|
|
export SAHANA_PWD=$(head -c 18 /dev/urandom | base64)
|
2018-10-25 22:22:36 +02:00
|
|
|
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
|
2018-01-27 22:26:37 +01:00
|
|
|
|
|
|
|
# Prepare persistent directory structure
|
|
|
|
mkdir -p /srv/sahana/conf /srv/sahana/data/databases /srv/sahana/data/uploads
|
|
|
|
chown -R 8001:8001 /srv/sahana/conf
|
2018-09-14 08:42:37 +02:00
|
|
|
cp -rp /var/lib/lxc/sahana/sahana/srv/web2py/applications/eden/models/. /srv/sahana/conf
|
2017-06-25 20:49:41 +02:00
|
|
|
|
2018-01-27 22:26:37 +01:00
|
|
|
# Copy Spotter template
|
2018-10-25 22:22:36 +02:00
|
|
|
cp -r srv/sahana/data/Spotter /srv/sahana/data/
|
2018-01-27 22:26:37 +01:00
|
|
|
chown -R 8001:8001 /srv/sahana/data
|
2017-06-25 20:49:41 +02:00
|
|
|
|
|
|
|
# Configure Sahana
|
2017-09-01 14:25:17 +02:00
|
|
|
export SAHANA_HMAC=$(head -c 18 /dev/urandom | base64)
|
2017-09-14 21:56:09 +02:00
|
|
|
export SAHANA_ADMIN_USER=admin@example.com
|
2017-09-16 14:38:50 +02:00
|
|
|
export SAHANA_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
2018-10-25 22:22:36 +02:00
|
|
|
envsubst <srv/sahana/conf/000_config.py >/srv/sahana/conf/000_config.py
|
|
|
|
envsubst <srv/sahana/data/Spotter/masterUsers.csv >/srv/sahana/data/Spotter/masterUsers.csv
|
|
|
|
cp srv/sahana/conf/00_settings.py /srv/sahana/conf/00_settings.py
|
2018-09-04 21:42:26 +02:00
|
|
|
vmmgr update-login sahana "${SAHANA_ADMIN_USER}" "${SAHANA_ADMIN_PWD}"
|
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
|
2018-01-27 22:26:37 +01:00
|
|
|
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/' /srv/sahana/conf/000_config.py
|
|
|
|
sed -i 's/settings.base.debug = True/settings.base.debug = False/' /srv/sahana/conf/000_config.py
|
|
|
|
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sahana/conf/000_config.py
|
2017-09-13 13:17:38 +02:00
|
|
|
fi
|
2018-07-15 21:55:35 +02:00
|
|
|
|
2018-09-13 22:09:01 +02:00
|
|
|
# Install service
|
2018-10-25 22:22:36 +02:00
|
|
|
cp etc/init.d/sahana /etc/init.d/sahana
|
2018-09-13 22:09:01 +02:00
|
|
|
rc-update -u
|
|
|
|
|
2018-09-20 15:45:00 +02:00
|
|
|
# Install config update script
|
2018-10-25 22:22:36 +02:00
|
|
|
cp srv/sahana/update-conf.sh /srv/sahana/update-conf.sh
|
2018-09-20 15:45:00 +02:00
|
|
|
|
2018-07-15 21:55:35 +02:00
|
|
|
# Stop services required for build
|
2018-09-13 22:09:01 +02:00
|
|
|
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
|