2018-02-06 19:05:38 +01:00
|
|
|
#!/bin/sh
|
2017-09-16 18:55:19 +02:00
|
|
|
|
2017-12-04 17:48:37 +01:00
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/sambro
|
2017-09-16 18:55:19 +02:00
|
|
|
|
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
|
2018-04-29 20:48:57 +02:00
|
|
|
service postgres start
|
|
|
|
|
|
|
|
# Build Docker container
|
2018-07-12 22:19:10 +02:00
|
|
|
docker build -t sahana $(realpath $(dirname "${0}"))/sahana
|
2018-04-29 20:48:57 +02:00
|
|
|
cp ${SOURCE_DIR}/etc/init.d/sambro /etc/init.d/sambro
|
|
|
|
rc-update -u
|
2017-09-21 21:12:29 +02:00
|
|
|
|
2017-09-16 18:55:19 +02:00
|
|
|
# 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
|
2017-09-16 18:55:19 +02:00
|
|
|
|
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
|
2017-09-16 18:55:19 +02:00
|
|
|
|
2018-01-28 09:13:30 +01:00
|
|
|
# Configure SAMBRO
|
2017-09-16 18:55:19 +02:00
|
|
|
export SAMBRO_HMAC=$(head -c 18 /dev/urandom | base64)
|
|
|
|
export SAMBRO_ADMIN_USER=admin@example.com
|
|
|
|
export SAMBRO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
2018-03-25 23:20:34 +02:00
|
|
|
envsubst <${SOURCE_DIR}/srv/sambro/conf/000_config.py >/srv/sambro/conf/000_config.py
|
2018-01-28 09:13:30 +01:00
|
|
|
envsubst <${SOURCE_DIR}/masterUsers.csv >/tmp/masterUsers.csv
|
2018-03-25 23:20:34 +02: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
|
|
|
|
cp ${SOURCE_DIR}/srv/sambro/update-url.sh /srv/sambro/update-url.sh
|
2018-04-29 20:48:57 +02:00
|
|
|
spotter-appmgr update-login sambro "${SAMBRO_ADMIN_USER}" "${SAMBRO_ADMIN_PWD}"
|
2017-09-16 18:55:19 +02:00
|
|
|
|
|
|
|
# Populate database
|
2018-03-14 12:13:00 +01:00
|
|
|
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
|
2017-09-16 18:55:19 +02:00
|
|
|
|
2017-09-26 12:52:05 +02:00
|
|
|
# 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
|
2017-09-16 18:55:19 +02:00
|
|
|
fi
|