Spotter-VM/sahana.sh

55 lines
2.5 KiB
Bash
Raw Normal View History

2018-01-27 22:26:37 +01:00
#!/bin/sh
2017-06-25 20:49:41 +02:00
SOURCE_DIR=$(realpath $(dirname "${0}"))/sahana
2017-06-25 20:49:41 +02:00
2018-01-27 22:26:37 +01:00
# Check prerequisites
2018-02-03 13:42:32 +01:00
docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh
2018-01-27 22:26:37 +01:00
docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh
2017-06-25 20:49:41 +02:00
2018-01-27 22:26:37 +01:00
# Build Docker container
docker build -t sahana ${SOURCE_DIR}
2017-06-25 20:49:41 +02:00
# Create PostgreSQL user and database
export SAHANA_PWD=$(head -c 18 /dev/urandom | base64)
2018-01-27 22:26:37 +01:00
envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql
# Prepare persistent directory structure
mkdir -p /srv/sahana/conf /srv/sahana/data/databases /srv/sahana/data/uploads
chown -R 8001:8001 /srv/sahana/conf
docker run --rm -v /srv/sahana/conf:/mnt/conf sahana cp -rp /srv/web2py/applications/eden/models/. /mnt/conf
2017-06-25 20:49:41 +02:00
2018-01-27 22:26:37 +01:00
# Copy Spotter template
cp -r ${SOURCE_DIR}/srv/sahana/data/Spotter /srv/sahana/data/
chown -R 8001:8001 /srv/sahana/data
2017-06-25 20:49:41 +02:00
# Configure Sahana
export SAHANA_HMAC=$(head -c 18 /dev/urandom | base64)
2018-01-27 22:26:37 +01:00
envsubst <${SOURCE_DIR}/srv/sahana/conf/000_config.py >/srv/sahana/conf/000_config.py
cp ${SOURCE_DIR}/srv/sahana/conf/00_settings.py /srv/sahana/conf/00_settings.py
2018-02-06 09:56:17 +01:00
cp ${SOURCE_DIR}/srv/sahana/update-ip.sh /srv/sahana/update-ip.sh
export SAHANA_ADMIN_USER=admin@example.com
export SAHANA_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
2018-01-27 22:26:37 +01:00
envsubst <${SOURCE_DIR}/srv/sahana/data/Spotter/masterUsers.csv >/srv/sahana/data/Spotter/masterUsers.csv
2017-06-25 20:49:41 +02:00
# Populate database
docker run --rm -h sahana --link postgres -v /srv/sahana/conf:/srv/web2py/applications/eden/models -v /srv/sahana/data/Spotter:/srv/web2py/applications/eden/modules/templates/Spotter -v /srv/sahana/data/databases:/srv/web2py/applications/eden/databases sahana su - sahana -c "./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py"
2017-06-25 20:49:41 +02:00
# Set "production values" (increases performance) only if the DEBUG environment variable is not set
if [ ${DEBUG:-0} -eq 0 ]; then
2018-01-27 22:26:37 +01:00
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/' /srv/sahana/conf/000_config.py
sed -i 's/settings.base.debug = True/settings.base.debug = False/' /srv/sahana/conf/000_config.py
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sahana/conf/000_config.py
fi
2017-06-25 20:49:41 +02:00
2018-01-27 22:26:37 +01:00
# Create Sahana service
cp ${SOURCE_DIR}/etc/init.d/sahana /etc/init.d/sahana
rc-update add sahana
2018-01-27 22:26:37 +01:00
service sahana start
2017-06-25 20:49:41 +02:00
2018-01-27 22:26:37 +01:00
# Create nginx app definition
cp ${SOURCE_DIR}/etc/nginx/conf.d/sahana.conf /etc/nginx/conf.d/sahana.conf
service nginx reload
2017-06-25 20:49:41 +02:00
# Add portal application definition
2018-01-27 22:26:37 +01:00
portal-app-manager sahana-eden "https://{host}:8401/eden/" "${SAHANA_ADMIN_USER}" "${SAHANA_ADMIN_PWD}"