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
|
|
|
|
docker image ls | grep -q sahana || docker build -t sahana $(realpath $(dirname "${0}"))/sahana
|
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)
|
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
|
2017-09-16 18:55:19 +02:00
|
|
|
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
|
2017-09-16 18:55:19 +02:00
|
|
|
|
|
|
|
# Populate database
|
2018-01-28 09:13:30 +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 ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
|
|
|
|
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
|
|
|
|
|
2018-01-28 09:13:30 +01:00
|
|
|
# Create SAMBRO service
|
|
|
|
cp ${SOURCE_DIR}/etc/init.d/sambro /etc/init.d/sambro
|
2018-02-06 21:54:11 +01:00
|
|
|
rc-update add sambro
|
2018-01-28 09:13:30 +01:00
|
|
|
service sambro start
|
2017-09-16 18:55:19 +02:00
|
|
|
|
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
|
2017-09-16 18:55:19 +02:00
|
|
|
|
|
|
|
# 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}"
|
2018-02-16 19:45:39 +01:00
|
|
|
portal-app-manager sambro-mobile -p clienturl "http://{host}:8899/eden/"
|