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
|
|
|
|
2018-10-26 15:02:11 +02:00
|
|
|
cd $(realpath $(dirname "${0}"))/install
|
2017-09-16 18:55:19 +02:00
|
|
|
|
2018-01-28 09:13:30 +01:00
|
|
|
# Check prerequisites
|
2018-09-14 08:53:27 +02:00
|
|
|
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
|
2017-09-21 21:12:29 +02:00
|
|
|
|
2017-09-16 18:55:19 +02:00
|
|
|
# Create PostgreSQL user and database
|
|
|
|
export SAMBRO_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
|
2017-09-16 18:55:19 +02:00
|
|
|
|
2018-01-28 09:13:30 +01:00
|
|
|
# Prepare persistent directory structure
|
|
|
|
mkdir -p /srv/sambro/conf /srv/sambro/data/databases /srv/sambro/data/uploads /srv/sambro/data/SAMBRO
|
|
|
|
chown -R 8001:8001 /srv/sambro/conf /srv/sambro/data
|
2018-10-28 13:29:01 +01:00
|
|
|
cp -rp /var/lib/lxc/shared/sahana/srv/web2py/applications/eden/models/. /srv/sambro/conf
|
|
|
|
cp -rp /var/lib/lxc/shared/sahana/srv/web2py/applications/eden/modules/templates/SAMBRO/. /srv/sambro/data/SAMBRO
|
2017-09-16 18:55:19 +02:00
|
|
|
|
2018-01-28 09:13:30 +01:00
|
|
|
# Configure SAMBRO
|
2017-09-16 18:55:19 +02:00
|
|
|
export SAMBRO_HMAC=$(head -c 18 /dev/urandom | base64)
|
|
|
|
export SAMBRO_ADMIN_USER=admin@example.com
|
|
|
|
export SAMBRO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
2018-10-25 22:22:36 +02:00
|
|
|
envsubst <srv/sambro/conf/000_config.py >/srv/sambro/conf/000_config.py
|
2018-10-28 13:29:01 +01:00
|
|
|
mkdir -p /var/lib/lxc/sambro/sambro/srv/web2py/applications/eden/modules/templates/default/users
|
|
|
|
envsubst <masterUsers.csv >/var/lib/lxc/sambro/sambro/srv/web2py/applications/eden/modules/templates/default/users/masterUsers.csv
|
2018-10-31 18:02:22 +01:00
|
|
|
chown -R 8001:8001 /var/lib/lxc/sambro/sambro/srv/web2py
|
2018-10-25 22:22:36 +02:00
|
|
|
cp srv/sambro/conf/00_settings.py /srv/sambro/conf/00_settings.py
|
|
|
|
cp srv/sambro/data/SAMBRO/config.py /srv/sambro/data/SAMBRO/config.py
|
2017-09-16 18:55:19 +02:00
|
|
|
|
|
|
|
# Populate database
|
2018-10-28 13:29:01 +01:00
|
|
|
lxc-execute -u 8001 -g 8001 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
|
|
|
|
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-28 09:13:30 +01:00
|
|
|
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/' /srv/sambro/conf/000_config.py
|
|
|
|
sed -i 's/settings.base.debug = True/settings.base.debug = False/' /srv/sambro/conf/000_config.py
|
|
|
|
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sambro/conf/000_config.py
|
2017-09-16 18:55:19 +02:00
|
|
|
fi
|
2018-07-15 21:55:35 +02:00
|
|
|
|
2018-09-14 08:53:27 +02:00
|
|
|
# Install service
|
2018-10-25 22:22:36 +02:00
|
|
|
cp etc/init.d/sambro /etc/init.d/sambro
|
2018-09-14 08:53:27 +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/sambro/update-conf.sh /srv/sambro/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-14 08:53:27 +02:00
|
|
|
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
|
2018-10-28 19:50:35 +01:00
|
|
|
|
2018-11-03 15:53:51 +01:00
|
|
|
# Register application
|
|
|
|
vmmgr register-app sambro "${SAMBRO_ADMIN_USER}" "${SAMBRO_ADMIN_PWD}"
|