Spotter-VM/sahana-demo/setup.sh

41 lines
1.9 KiB
Bash
Raw Normal View History

#!/bin/sh
set -e
2018-09-14 08:42:37 +02:00
SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
export TEMPLATE=${TEMPLATE:-"default"}
# Check prerequisites
2018-09-14 08:42:37 +02:00
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
# Create PostgreSQL user and database
export SAHANADEMO_PWD=$(head -c 18 /dev/urandom | base64)
2018-09-14 08:42:37 +02:00
envsubst <${SOURCE_DIR}/createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
# Prepare persistent directory structure
mkdir -p /srv/sahana-demo/conf /srv/sahana-demo/data/databases /srv/sahana-demo/data/uploads /srv/sahana-demo/data/${TEMPLATE}
chown -R 8001:8001 /srv/sahana-demo/conf /srv/sahana-demo/data
2018-09-14 08:42:37 +02:00
cp -rp /var/lib/lxc/sahana/sahana/srv/web2py/applications/eden/models/. /srv/sahana-demo/conf
cp -rp /srv/web2py/applications/eden/modules/templates/${TEMPLATE}/. /srv/sahana-demo/data/${TEMPLATE}
# Configure Sahana
export SAHANADEMO_HMAC=$(head -c 18 /dev/urandom | base64)
export SAHANADEMO_ADMIN_USER=admin@example.com
export SAHANADEMO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
envsubst <${SOURCE_DIR}/srv/sahana-demo/conf/000_config.py >/srv/sahana-demo/conf/000_config.py
2018-09-14 08:42:37 +02:00
envsubst <${SOURCE_DIR}/masterUsers.csv >/var/lib/lxc/sahana/sahana/tmp/masterUsers.csv
2018-09-04 21:42:26 +02:00
vmmgr update-login sahana-demo "${SAHANADEMO_ADMIN_USER}" "${SAHANADEMO_ADMIN_PWD}"
2018-09-14 08:53:27 +02:00
# Replace template in LXC container mount definition
2018-09-14 08:42:37 +02:00
sed -i "s/default/${TEMPLATE}/g" /var/lib/lxc/sahana-demo/config
# Populate database
2018-09-14 08:42:37 +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
# Install service
envsubst <${SOURCE_DIR}/etc/init.d/sahana-demo >/etc/init.d/sahana-demo
chmod +x /etc/init.d/sahana-demo
# Stop services required for build
2018-09-14 08:42:37 +02:00
[ ! -z ${STOP_POSTGRES} ] && service postgres stop