2018-01-18 13:39:39 +01:00
|
|
|
#!/bin/sh
|
2018-07-15 21:55:35 +02:00
|
|
|
set -e
|
2017-09-11 17:06:40 +02:00
|
|
|
|
2018-09-13 22:02:25 +02:00
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
|
2017-09-11 17:06:40 +02:00
|
|
|
|
2018-01-23 21:27:18 +01:00
|
|
|
# Check prerequisites
|
2018-09-13 22:02:25 +02:00
|
|
|
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
|
|
|
|
[ ! -e /run/openrc/started/rabbitmq ] && service rabbitmq start && STOP_RABBITMQ=1
|
2017-09-11 17:06:40 +02:00
|
|
|
|
|
|
|
# Create PostgreSQL user and database
|
2017-09-16 14:38:50 +02:00
|
|
|
export PANDORA_PWD=$(head -c 18 /dev/urandom | base64)
|
2018-09-13 22:02:25 +02:00
|
|
|
envsubst <${SOURCE_DIR}/createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
|
2017-09-11 17:06:40 +02:00
|
|
|
|
|
|
|
# Configure RabbitMQ
|
2017-10-24 21:51:27 +02:00
|
|
|
export PANDORA_RABBIT_PWD=$(head -c 18 /dev/urandom | base64 | tr -d "/")
|
2018-09-13 22:02:25 +02:00
|
|
|
lxc-attach rabbitmq -- rabbitmqctl add_user pandora ${PANDORA_RABBIT_PWD}
|
|
|
|
lxc-attach rabbitmq -- rabbitmqctl add_vhost /pandora
|
|
|
|
lxc-attach rabbitmq -- rabbitmqctl set_permissions -p /pandora pandora ".*" ".*" ".*"
|
2017-09-11 17:06:40 +02:00
|
|
|
|
|
|
|
# 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
|
2018-02-20 20:50:42 +01:00
|
|
|
# Copy customized configuration if VANILLA environment variable is not set, else use the default pandora config
|
|
|
|
if [ ${VANILLA:-0} -eq 0 ]; then
|
2018-09-13 22:02:25 +02:00
|
|
|
cp ${SOURCE_DIR}/srv/pandora/conf/config.jsonc /srv/pandora/conf
|
2018-02-20 20:50:42 +01:00
|
|
|
else
|
|
|
|
chown 8002:8002 /srv/pandora/conf
|
2018-09-13 22:02:25 +02:00
|
|
|
cp /var/lib/lxc/pandora/pandora/srv/pandora/pandora/config.pandora.jsonc /srv/pandora/conf
|
2018-02-20 20:50:42 +01:00
|
|
|
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-09-11 17:06:40 +02:00
|
|
|
|
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
|
|
|
|
|
2017-09-11 17:06:40 +02:00
|
|
|
# Populate database
|
2018-09-13 22:02:25 +02:00
|
|
|
lxc-execute pandora -- /srv/pandora/pandora/manage.py migrate --noinput
|
|
|
|
lxc-execute pandora -- /srv/pandora/pandora/manage.py sqlfindindex
|
|
|
|
lxc-execute pandora -- /srv/pandora/pandora/manage.py sync_itemsort
|
|
|
|
lxc-execute pandora -- /srv/pandora/pandora/manage.py sync_documentsort
|
2017-09-11 17:06:40 +02:00
|
|
|
|
2017-09-17 22:09:56 +02:00
|
|
|
# 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-09-19 17:04:42 +02:00
|
|
|
export PANDORA_ADMIN_HASH=$(lxc-execute pandora -- sh -c "DJANGO_SETTINGS_MODULE=srv.pandora.pandora.settings python3 -c \"from django.contrib.auth.hashers import make_password; print(make_password('${PANDORA_ADMIN_PWD}'))\"")
|
2018-09-13 22:02:25 +02:00
|
|
|
envsubst <${SOURCE_DIR}/adminpwd.sql | lxc-attach -u 5432 -g 5432 postgres -- psql pandora
|
2018-09-04 21:42:26 +02:00
|
|
|
vmmgr update-login pandora "${PANDORA_ADMIN_USER}" "${PANDORA_ADMIN_PWD}"
|
2018-07-15 21:55:35 +02:00
|
|
|
|
2018-09-13 22:02:25 +02:00
|
|
|
# Install service
|
|
|
|
cp ${SOURCE_DIR}/etc/init.d/pandora /etc/init.d/pandora
|
|
|
|
rc-update -u
|
|
|
|
|
2018-09-20 15:45:00 +02:00
|
|
|
# Install config update script
|
|
|
|
cp ${SOURCE_DIR}/srv/pandora/update-conf.sh /srv/pandora/update-conf.sh
|
|
|
|
|
2018-07-15 21:55:35 +02:00
|
|
|
# Stop services required for build
|
2018-09-13 22:02:25 +02:00
|
|
|
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
|
|
|
|
[ ! -z ${STOP_RABBITMQ} ] && service rabbitmq stop
|