49 lines
1.6 KiB
Bash
Executable File
49 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
set -ev
|
|
|
|
cd $(realpath $(dirname "${0}"))/install
|
|
|
|
# Check prerequisites
|
|
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
|
|
|
|
# Create database
|
|
export CTS_PWD=$(head -c 18 /dev/urandom | base64)
|
|
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
|
|
|
|
# Copy existing config files into persistent storage
|
|
mkdir -p /srv/cts/conf
|
|
cp /var/lib/lxc/cts/cts/srv/cts/cts/settings/base.py /srv/cts/conf
|
|
|
|
# Configure CTS
|
|
export CTS_SECRET=$(head -c 26 /dev/urandom | base64)
|
|
envsubst <srv/cts/conf/spotter.py >/srv/cts/conf/spotter.py
|
|
touch /srv/cts/conf/__init__.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/cts/conf/spotter.py
|
|
fi
|
|
|
|
# Populate database
|
|
lxc-execute cts -- manage.py migrate
|
|
|
|
# Create admin account
|
|
export CTS_ADMIN_EMAIL=admin@example.com
|
|
export CTS_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
|
export CTS_ADMIN_HASH=$(lxc-execute cts -- python -c "from django.contrib.auth.hashers import make_password; print make_password('${CTS_ADMIN_PWD}')")
|
|
export CTS_ADMIN_SECRET=$(head -c 12 /dev/urandom | sha256sum | cut -c1-13)
|
|
envsubst <adminpwd.sql | lxc-attach -u 5432 -g 5432 postgres -- psql cts
|
|
|
|
# Install service
|
|
cp etc/init.d/cts /etc/init.d/cts
|
|
rc-update -u
|
|
|
|
# Install config update script
|
|
cp srv/cts/update-conf.sh /srv/cts/update-conf.sh
|
|
|
|
# Stop services required for setup
|
|
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
|
|
|
|
# Register application
|
|
vmmgr register-app cts cts "${CTS_ADMIN_EMAIL}" "${CTS_ADMIN_PWD}"
|