Spotter-VM/sambro.sh

53 lines
2.8 KiB
Bash
Raw Normal View History

2018-02-06 19:05:38 +01:00
#!/bin/sh
SOURCE_DIR=$(realpath $(dirname "${0}"))/sambro
2018-01-28 09:13:30 +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-28 09:13:30 +01:00
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)
2018-01-28 09:13:30 +01:00
envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql
2018-01-28 09:13:30 +01:00
# 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
2018-01-28 09:13:30 +01:00
# Configure SAMBRO
export SAMBRO_HMAC=$(head -c 18 /dev/urandom | base64)
2018-01-28 09:13:30 +01:00
envsubst <${SOURCE_DIR}/srv/sambro/conf/000_config.py >/srv/sambro/conf/000_config.py
2018-02-06 09:56:17 +01:00
cp ${SOURCE_DIR}/srv/sambro/update-ip.sh /srv/sambro/update-ip.sh
2018-01-28 09:13:30 +01:00
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)
2018-01-28 09:13:30 +01:00
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 su - sahana -c "./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py"
2018-01-28 09:13:30 +01:00
rm /tmp/masterUsers.csv
# Set "production values" (increases performance) only if the DEBUG environment variable is not set
if [ ${DEBUG:-0} -eq 0 ]; then
2018-01-28 09:13:30 +01:00
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
2018-01-28 09:13:30 +01:00
# Create SAMBRO service
cp ${SOURCE_DIR}/etc/init.d/sambro /etc/init.d/sambro
rc-update add sambro
2018-01-28 09:13:30 +01:00
service sambro start
2018-01-28 09:13:30 +01:00
# 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
2018-01-28 09:13:30 +01:00
portal-app-manager sambro "https://{host}:8499/eden/" "${SAMBRO_ADMIN_USER}" "${SAMBRO_ADMIN_PWD}"
portal-app-manager sambro-mobile -p clienturl "http://{host}:8899/eden/"