Spotter-VM/sambro/setup.sh

46 lines
2.2 KiB
Bash
Raw Normal View History

2018-02-06 19:05:38 +01:00
#!/bin/sh
set -e
2018-09-14 08:53:27 +02:00
SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
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
# Create PostgreSQL user and database
export SAMBRO_PWD=$(head -c 18 /dev/urandom | base64)
2018-09-14 08:53:27 +02:00
envsubst <${SOURCE_DIR}/createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
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-09-14 08:53:27 +02:00
cp -rp /var/lib/lxc/sahana/sahana/srv/web2py/applications/eden/models/. /srv/sahana-demo/conf
2018-09-14 18:13:11 +02:00
cp -rp /var/lib/lxc/sahana/sahana/srv/web2py/applications/eden/modules/templates/SAMBRO/. /srv/sahana-demo/data/SAMBRO
2018-01-28 09:13:30 +01:00
# Configure SAMBRO
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)
envsubst <${SOURCE_DIR}/srv/sambro/conf/000_config.py >/srv/sambro/conf/000_config.py
2018-09-14 08:53:27 +02:00
envsubst <${SOURCE_DIR}/masterUsers.csv >/var/lib/lxc/sahana/sahana/tmp/masterUsers.csv
cp ${SOURCE_DIR}/srv/sambro/conf/00_settings.py /srv/sambro/conf/00_settings.py
cp ${SOURCE_DIR}/srv/sambro/data/SAMBRO/config.py /srv/sambro/data/SAMBRO/config.py
2018-09-04 21:42:26 +02:00
vmmgr update-login sambro "${SAMBRO_ADMIN_USER}" "${SAMBRO_ADMIN_PWD}"
# Populate database
2018-09-14 08:53:27 +02:00
lxc-execute -u 8001 -g 8001 sahana -- sh -c 'cd /srv/web2py; cp /tmp/masterUsers.csv applications/eden/modules/templates/default/users/masterUsers.csv; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py'
rm /var/lib/lxc/sahana/sahana/tmp/masterUsers.csv
# 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
fi
2018-09-14 08:53:27 +02:00
# Install service
cp ${SOURCE_DIR}/etc/init.d/sambro /etc/init.d/sambro
rc-update -u
# Stop services required for build
2018-09-14 08:53:27 +02:00
[ ! -z ${STOP_POSTGRES} ] && service postgres stop