62 lines
2.6 KiB
Bash
Executable File
62 lines
2.6 KiB
Bash
Executable File
#!/bin/sh
|
|
set -e
|
|
|
|
cd $(realpath $(dirname "${0}"))/setup
|
|
|
|
# Check prerequisites
|
|
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
|
|
[ ! -e /run/openrc/started/rabbitmq ] && service rabbitmq start && STOP_RABBITMQ=1
|
|
|
|
# Create PostgreSQL user and database
|
|
export PANDORA_PWD=$(head -c 18 /dev/urandom | base64)
|
|
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
|
|
|
|
# Configure RabbitMQ
|
|
export PANDORA_RABBIT_PWD=$(head -c 18 /dev/urandom | base64 | tr -d "/")
|
|
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 ".*" ".*" ".*"
|
|
|
|
# Configure Pandora
|
|
mkdir -p /srv/pandora/conf /srv/pandora/data
|
|
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 srv/pandora/conf/config.jsonc /srv/pandora/conf
|
|
else
|
|
chown 8002:8002 /srv/pandora/conf
|
|
cp /var/lib/lxc/pandora/pandora/srv/pandora/pandora/config.pandora.jsonc /srv/pandora/conf
|
|
fi
|
|
cp srv/pandora/conf/gunicorn_config.py /srv/pandora/conf/gunicorn_config.py
|
|
envsubst <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
|
|
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)
|
|
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 postgres -- psql pandora
|
|
vmmgr update-login pandora "${PANDORA_ADMIN_USER}" "${PANDORA_ADMIN_PWD}"
|
|
|
|
# Install service
|
|
cp etc/init.d/pandora /etc/init.d/pandora
|
|
rc-update -u
|
|
|
|
# Install config update script
|
|
cp srv/pandora/update-conf.sh /srv/pandora/update-conf.sh
|
|
|
|
# Stop services required for build
|
|
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
|
|
[ ! -z ${STOP_RABBITMQ} ] && service rabbitmq stop
|