2018-01-18 13:39:39 +01:00
|
|
|
#!/bin/sh
|
2018-10-28 16:04:11 +01:00
|
|
|
set -ev
|
2017-09-11 17:06:40 +02:00
|
|
|
|
2018-10-26 15:02:11 +02:00
|
|
|
cd $(realpath $(dirname "${0}"))/install
|
2017-09-11 17:06:40 +02:00
|
|
|
|
2019-10-05 15:18:36 +02:00
|
|
|
# Create Postgres instance
|
|
|
|
mkdir -p /srv/pandora/postgres_data
|
|
|
|
chown -R 105432:105432 /srv/pandora/postgres_data
|
|
|
|
chmod 700 /srv/pandora/postgres_data
|
|
|
|
lxc-execute -n pandora-postgres -- initdb -D /var/lib/postgresql
|
|
|
|
|
|
|
|
# Configure Postgres
|
|
|
|
cp postgres_data/postgresql.conf /srv/pandora/postgres_data/postgresql.conf
|
|
|
|
cp postgres_data/pg_hba.conf /srv/pandora/postgres_data/pg_hba.conf
|
2017-09-11 17:06:40 +02:00
|
|
|
|
|
|
|
# Create PostgreSQL user and database
|
2019-06-05 18:55:15 +02:00
|
|
|
export PANDORA_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
2019-10-05 15:18:36 +02:00
|
|
|
service pandora-postgres start
|
|
|
|
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 pandora-postgres -- psql
|
|
|
|
|
|
|
|
# Create RabbitMQ directory structure
|
|
|
|
mkdir -p /srv/pandora/rabbitmq_data
|
|
|
|
chown 105672:105672 /srv/pandora/rabbitmq_data
|
2017-09-11 17:06:40 +02:00
|
|
|
|
|
|
|
# Configure RabbitMQ
|
2019-06-05 18:55:15 +02:00
|
|
|
export PANDORA_RABBIT_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
2019-10-05 15:18:36 +02:00
|
|
|
service pandora-rabbitmq start
|
|
|
|
lxc-attach pandora-rabbitmq -- rabbitmqctl add_user pandora ${PANDORA_RABBIT_PWD}
|
|
|
|
lxc-attach pandora-rabbitmq -- rabbitmqctl add_vhost /pandora
|
|
|
|
lxc-attach pandora-rabbitmq -- rabbitmqctl set_permissions -p /pandora pandora ".*" ".*" ".*"
|
2017-09-11 17:06:40 +02:00
|
|
|
|
|
|
|
# Configure Pandora
|
2019-10-05 15:18:36 +02:00
|
|
|
mkdir -p /srv/pandora/pandora_conf /srv/pandora/pandora_data
|
2019-10-14 07:59:06 +02:00
|
|
|
chown 108080:108080 /srv/pandora/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
|
2019-10-05 15:18:36 +02:00
|
|
|
cp pandora_conf/config.jsonc /srv/pandora/pandora_conf/config.jsonc
|
2018-02-20 20:50:42 +01:00
|
|
|
else
|
2019-10-05 15:18:36 +02:00
|
|
|
lxc-execute pandora -- cat /srv/pandora/pandora/config.pandora.jsonc >/srv/pandora/pandora_conf/config.jsonc
|
2017-11-29 21:27:11 +01:00
|
|
|
fi
|
2019-10-05 15:18:36 +02:00
|
|
|
cp pandora_conf/gunicorn_config.py /srv/pandora/pandora_conf/gunicorn_config.py
|
|
|
|
envsubst <pandora_conf/local_settings.py >/srv/pandora/pandora_conf/local_settings.py
|
2019-10-14 07:59:06 +02:00
|
|
|
chown -R 108080:108080 /srv/pandora/pandora_conf
|
2017-11-29 21:27:11 +01:00
|
|
|
|
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
|
2019-06-05 18:55:15 +02:00
|
|
|
export PANDORA_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
|
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}'))\"")
|
2019-10-05 15:18:36 +02:00
|
|
|
envsubst <adminpwd.sql | lxc-attach -u 5432 -g 5432 pandora-postgres -- psql pandora
|
2018-09-13 22:02:25 +02:00
|
|
|
|
2018-09-20 15:45:00 +02:00
|
|
|
# Install config update script
|
2019-10-05 15:18:36 +02:00
|
|
|
cp update-conf.sh /srv/pandora/update-conf.sh
|
2018-09-20 15:45:00 +02:00
|
|
|
|
2019-10-05 15:18:36 +02:00
|
|
|
# Stop services required for setup
|
|
|
|
service pandora-postgres stop
|
|
|
|
service pandora-rabbitmq stop
|
2018-10-28 19:50:35 +01:00
|
|
|
|
2018-11-03 15:53:51 +01:00
|
|
|
# Register application
|
2019-02-26 21:12:41 +01:00
|
|
|
vmmgr register-app pandora pandora "${PANDORA_ADMIN_USER}" "${PANDORA_ADMIN_PWD}"
|