59 lines
2.8 KiB
Bash
Executable File
59 lines
2.8 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/pandora
|
|
|
|
# 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 rabbitmq || $(realpath $(dirname "${0}"))/rabbitmq.sh
|
|
|
|
# Build Docker container
|
|
docker build -t pandora ${SOURCE_DIR}
|
|
|
|
# Create PostgreSQL user and database
|
|
export PANDORA_PWD=$(head -c 18 /dev/urandom | base64)
|
|
envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql
|
|
|
|
# Configure RabbitMQ
|
|
export PANDORA_RABBIT_PWD=$(head -c 18 /dev/urandom | base64 | tr -d "/")
|
|
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
|
|
mkdir -p /srv/pandora/conf /srv/pandora/data
|
|
chown 8002:8002 /srv/pandora/data
|
|
cp ${SOURCE_DIR}/srv/pandora/conf/config.jsonc /srv/pandora/conf/config.jsonc
|
|
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
|
|
|
|
# Set "production values" (increases performance) only if the DEBUG environment variable is not set
|
|
if [ ${DEBUG:-0} -eq 0 ]; then
|
|
sed -i 's/DEBUG = True/DEBUG = False/' /srv/pandora/conf/local_settings.py
|
|
fi
|
|
|
|
# Populate database
|
|
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)
|
|
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
|
|
|
|
# Configure Pandora service
|
|
cp ${SOURCE_DIR}/etc/init.d/pandora /etc/init.d/pandora
|
|
rc-update add pandora boot
|
|
service pandora start
|
|
|
|
# Create nginx app definition
|
|
cp ${SOURCE_DIR}/etc/nginx/conf.d/pandora.conf /etc/nginx/conf.d/pandora.conf
|
|
service nginx reload
|
|
|
|
# Add portal application definition
|
|
portal-app-manager pandora "https://{host}:8402/" "${PANDORA_ADMIN_USER}" "${PANDORA_ADMIN_PWD}"
|