41 lines
2.2 KiB
Bash
Executable File
41 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/sahana-demo
|
|
export TEMPLATE=${TEMPLATE:-"default"}
|
|
|
|
# Check prerequisites
|
|
docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh
|
|
docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh
|
|
docker image ls | grep -q sahana || docker build -t sahana $(realpath $(dirname "${0}"))/sahana
|
|
|
|
# Create PostgreSQL user and database
|
|
export SAHANADEMO_PWD=$(head -c 18 /dev/urandom | base64)
|
|
envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i 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
|
|
docker run --rm -v /srv/sahana-demo/conf:/mnt/conf sahana cp -rp /srv/web2py/applications/eden/models/. /mnt/conf
|
|
docker run --rm -v /srv/sahana-demo/data/${TEMPLATE}:/mnt/data sahana cp -rp /srv/web2py/applications/eden/modules/templates/${TEMPLATE}/. /mnt/data
|
|
|
|
# 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
|
|
envsubst <${SOURCE_DIR}/masterUsers.csv >/tmp/masterUsers.csv
|
|
cp ${SOURCE_DIR}/srv/sahana-demo/update-url.sh /srv/sahana-demo/update-url.sh
|
|
|
|
# Populate database
|
|
docker run --rm -h sahana-demo --link postgres -v /srv/sahana-demo/conf:/srv/web2py/applications/eden/models -v /srv/sahana-demo/data/databases:/srv/web2py/applications/eden/databases -v /tmp/masterUsers.csv:/srv/web2py/applications/eden/modules/templates/default/users/masterUsers.csv sahana su - sahana -c "./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py"
|
|
rm /tmp/masterUsers.csv
|
|
|
|
# Create Sahana service
|
|
envsubst <${SOURCE_DIR}/etc/init.d/sahana-demo >/etc/init.d/sahana-demo
|
|
chmod +x /etc/init.d/sahana-demo
|
|
rc-update add sahana-demo
|
|
service sahana-demo start
|
|
|
|
# Add application definition
|
|
spotter-appmgr add-app sahana-demo "https://sahana-demo.{host}/eden/" "${SAHANADEMO_ADMIN_USER}" "${SAHANADEMO_ADMIN_PWD}"
|