Spotter-VM/sambro.sh

53 lines
2.8 KiB
Bash
Executable File

#!/bin/sh
SOURCE_DIR=$(realpath $(dirname "${0}"))/sambro
# 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 SAMBRO_PWD=$(head -c 18 /dev/urandom | base64)
envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql
# 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
docker run --rm -v /srv/sambro/conf:/mnt/conf sahana cp -rp /srv/web2py/applications/eden/models/. /mnt/conf
docker run --rm -v /srv/sambro/data/SAMBRO:/mnt/data sahana cp -rp /srv/web2py/applications/eden/modules/templates/SAMBRO/. /mnt/data
# Configure SAMBRO
export SAMBRO_HMAC=$(head -c 18 /dev/urandom | base64)
envsubst <${SOURCE_DIR}/srv/sambro/conf/000_config.py >/srv/sambro/conf/000_config.py
cp ${SOURCE_DIR}/srv/sambro/update-ip.sh /srv/sambro/update-ip.sh
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
export SAMBRO_ADMIN_USER=admin@example.com
export SAMBRO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
envsubst <${SOURCE_DIR}/masterUsers.csv >/tmp/masterUsers.csv
# Populate database
docker run --rm -h sambro --link postgres -v /srv/sambro/conf:/srv/web2py/applications/eden/models -v /srv/sambro/data/SAMBRO:/srv/web2py/applications/eden/modules/templates/SAMBRO -v /tmp/masterUsers.csv:/srv/web2py/applications/eden/modules/templates/default/users/masterUsers.csv -v /srv/sambro/data/databases:/srv/web2py/applications/eden/databases sahana ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
rm /tmp/masterUsers.csv
# Set "production values" (increases performance) only if the DEBUG environment variable is not set
if [ ${DEBUG:-0} -eq 0 ]; then
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
# Create SAMBRO service
cp ${SOURCE_DIR}/etc/init.d/sambro /etc/init.d/sambro
rc-update add sambro
service sambro start
# Create nginx app definition
cp ${SOURCE_DIR}/etc/nginx/conf.d/sambro.conf /etc/nginx/conf.d/sambro.conf
service nginx reload
# Add portal application definition
portal-app-manager sambro "https://{host}:8499/eden/" "${SAMBRO_ADMIN_USER}" "${SAMBRO_ADMIN_PWD}"
portal-app-manager sambro-mobile