Spotter-VM/sahana-demo.sh

45 lines
2.3 KiB
Bash
Raw Normal View History

#!/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)
envsubst <${SOURCE_DIR}/srv/sahana-demo/conf/000_config.py >/srv/sahana-demo/conf/000_config.py
cp ${SOURCE_DIR}/srv/sahana-demo/update-ip.sh /srv/sahana-demo/update-ip.sh
export SAHANADEMO_ADMIN_USER=admin@example.com
export SAHANADEMO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
envsubst <${SOURCE_DIR}/masterUsers.csv >/tmp/masterUsers.csv
# 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
# Create nginx app definition
cp ${SOURCE_DIR}/etc/nginx/conf.d/sahana-demo.conf /etc/nginx/conf.d/sahana-demo.conf
service nginx reload
# Add portal application definition
portal-app-manager sahana-eden-demo "https://{host}:8498/eden/" "${SAHANADEMO_ADMIN_USER}" "${SAHANADEMO_ADMIN_PWD}"