Spotter-VM/pandora.sh

63 lines
3.0 KiB
Bash
Raw Normal View History

2018-01-18 13:39:39 +01:00
#!/bin/sh
set -e
SOURCE_DIR=$(realpath $(dirname "${0}"))/pandora
# Check prerequisites
2018-02-03 13:36:09 +01:00
docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh
2018-01-27 15:23:22 +01:00
docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh
2018-02-03 13:36:09 +01:00
docker image ls | grep -q rabbitmq || $(realpath $(dirname "${0}"))/rabbitmq.sh
service postgres start
service rabbitmq start
2018-01-18 13:39:39 +01:00
# Build Docker container
docker build -t pandora ${SOURCE_DIR}
cp ${SOURCE_DIR}/etc/init.d/pandora /etc/init.d/pandora
rc-update -u
# Create PostgreSQL user and database
export PANDORA_PWD=$(head -c 18 /dev/urandom | base64)
2018-01-18 13:39:39 +01:00
envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql
# Configure RabbitMQ
export PANDORA_RABBIT_PWD=$(head -c 18 /dev/urandom | base64 | tr -d "/")
2018-01-18 13:39:39 +01:00
docker exec rabbitmq rabbitmqctl add_user pandora ${PANDORA_RABBIT_PWD}
docker exec rabbitmq rabbitmqctl add_vhost /pandora
docker exec rabbitmq rabbitmqctl set_permissions -p /pandora pandora ".*" ".*" ".*"
# Configure Pandora
2018-01-18 13:39:39 +01:00
mkdir -p /srv/pandora/conf /srv/pandora/data
2018-01-27 22:35:55 +01:00
chown 8002:8002 /srv/pandora/data
# Copy customized configuration if VANILLA environment variable is not set, else use the default pandora config
if [ ${VANILLA:-0} -eq 0 ]; then
cp ${SOURCE_DIR}/srv/pandora/conf/config.jsonc /srv/pandora/conf/config.jsonc
else
chown 8002:8002 /srv/pandora/conf
docker run --rm -v /srv/pandora/conf:/srv/pandora/conf pandora cp /srv/pandora/pandora/config.pandora.jsonc /srv/pandora/conf/config.jsonc
fi
2018-01-18 13:39:39 +01:00
cp ${SOURCE_DIR}/srv/pandora/conf/gunicorn_config.py /srv/pandora/conf/gunicorn_config.py
envsubst <${SOURCE_DIR}/srv/pandora/conf/local_settings.py >/srv/pandora/conf/local_settings.py
2017-11-29 21:27:11 +01:00
# Set "production values" (increases performance) only if the DEBUG environment variable is not set
if [ ${DEBUG:-0} -eq 0 ]; then
2018-01-18 13:39:39 +01:00
sed -i 's/DEBUG = True/DEBUG = False/' /srv/pandora/conf/local_settings.py
2017-11-29 21:27:11 +01:00
fi
# Populate database
2018-01-18 13:59:24 +01:00
docker run --rm -h pandora --link postgres -v /srv/pandora/conf:/srv/pandora/conf pandora /srv/pandora/pandora/manage.py migrate --noinput
docker run --rm -h pandora --link postgres -v /srv/pandora/conf:/srv/pandora/conf pandora /srv/pandora/pandora/manage.py sqlfindindex
docker run --rm -h pandora --link postgres -v /srv/pandora/conf:/srv/pandora/conf pandora /srv/pandora/pandora/manage.py sync_itemsort
docker run --rm -h pandora --link postgres -v /srv/pandora/conf:/srv/pandora/conf pandora /srv/pandora/pandora/manage.py sync_documentsort
# Create admin account
export PANDORA_ADMIN_USER=admin
export PANDORA_ADMIN_EMAIL=admin@example.com
export PANDORA_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
2018-01-18 13:39:39 +01:00
export PANDORA_ADMIN_HASH=$(docker run --rm -h pandora -e DJANGO_SETTINGS_MODULE=pandora.settings -v /srv/pandora/conf:/srv/pandora/conf pandora python3 -c "from django.contrib.auth.hashers import make_password; print(make_password('${PANDORA_ADMIN_PWD}'))")
envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql pandora
2018-09-03 17:24:48 +02:00
vm-appmgr update-login pandora "${PANDORA_ADMIN_USER}" "${PANDORA_ADMIN_PWD}"
# Stop services required for build
service rabbitmq stop
service postgres stop