Spotter-VM/lxc-apps/pandora/install.sh

67 lines
2.8 KiB
Bash
Executable File

#!/bin/sh
set -ev
cd $(realpath $(dirname "${0}"))/install
# 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
# Create PostgreSQL user and database
export PANDORA_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
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
# Configure RabbitMQ
export PANDORA_RABBIT_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
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 ".*" ".*" ".*"
# Configure Pandora
mkdir -p /srv/pandora/pandora_conf /srv/pandora/pandora_data
chown 108080:108080 /srv/pandora/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 pandora_conf/config.jsonc /srv/pandora/pandora_conf/config.jsonc
else
lxc-execute pandora -- cat /srv/pandora/pandora/config.pandora.jsonc >/srv/pandora/pandora_conf/config.jsonc
fi
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
chown -R 108080:108080 /srv/pandora/pandora_conf
# Populate database
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
# 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 | tr -d '+/=')
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}'))\"")
envsubst <adminpwd.sql | lxc-attach -u 5432 -g 5432 pandora-postgres -- psql pandora
# Install config update script
cp update-conf.sh /srv/pandora/update-conf.sh
# Stop services required for setup
service pandora-postgres stop
service pandora-rabbitmq stop
# Register application
vmmgr register-app pandora pandora "${PANDORA_ADMIN_USER}" "${PANDORA_ADMIN_PWD}"