2017-12-26 09:33:47 +01:00
|
|
|
#!/bin/sh
|
2018-07-15 21:55:35 +02:00
|
|
|
set -e
|
2017-11-29 20:01:17 +01:00
|
|
|
|
2018-09-13 19:27:23 +02:00
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
|
2017-11-29 20:01:17 +01:00
|
|
|
|
2018-01-23 21:27:18 +01:00
|
|
|
# Check prerequisites
|
2018-09-13 20:42:11 +02:00
|
|
|
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
|
2017-11-29 20:01:17 +01:00
|
|
|
|
|
|
|
# Create database
|
|
|
|
export CTS_PWD=$(head -c 18 /dev/urandom | base64)
|
2018-09-13 19:27:23 +02:00
|
|
|
envsubst <${SOURCE_DIR}/createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
|
2017-12-26 09:33:47 +01:00
|
|
|
|
|
|
|
# Copy existing config files into persistent storage
|
|
|
|
mkdir -p /srv/cts/conf
|
2018-09-13 19:27:23 +02:00
|
|
|
cp /var/lib/lxc/cts/cts/srv/cts/cts/settings/base.py /srv/cts/conf
|
2017-11-29 20:01:17 +01:00
|
|
|
|
|
|
|
# Configure CTS
|
|
|
|
export CTS_SECRET=$(head -c 26 /dev/urandom | base64)
|
2017-12-26 09:33:47 +01:00
|
|
|
envsubst <${SOURCE_DIR}/srv/cts/conf/spotter.py >/srv/cts/conf/spotter.py
|
2018-02-01 14:01:05 +01:00
|
|
|
touch /srv/cts/conf/__init__.py
|
2017-11-29 20:01:17 +01:00
|
|
|
|
|
|
|
# Set "production values" (increases performance) only if the DEBUG environment variable is not set
|
|
|
|
if [ ${DEBUG:-0} -eq 0 ]; then
|
2017-12-26 09:33:47 +01:00
|
|
|
sed -i 's/DEBUG = True/DEBUG = False/' /srv/cts/conf/spotter.py
|
2017-11-29 20:01:17 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Populate database
|
2018-09-13 19:27:23 +02:00
|
|
|
lxc-execute cts -- manage.py migrate
|
2017-11-29 20:01:17 +01:00
|
|
|
|
|
|
|
# Create admin account
|
|
|
|
export CTS_ADMIN_EMAIL=admin@example.com
|
|
|
|
export CTS_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
2018-09-13 19:27:23 +02:00
|
|
|
export CTS_ADMIN_HASH=$(lxc-execute cts -- python -c "from django.contrib.auth.hashers import make_password; print make_password('${CTS_ADMIN_PWD}')")
|
2017-11-29 20:01:17 +01:00
|
|
|
export CTS_ADMIN_SECRET=$(head -c 12 /dev/urandom | sha256sum | cut -c1-13)
|
2018-09-13 19:27:23 +02:00
|
|
|
envsubst <${SOURCE_DIR}/adminpwd.sql | lxc-attach -u 5432 -g 5432 postgres -- psql cts
|
2018-09-04 21:42:26 +02:00
|
|
|
vmmgr update-login cts "${CTS_ADMIN_EMAIL}" "${CTS_ADMIN_PWD}"
|
2018-07-15 21:55:35 +02:00
|
|
|
|
2018-09-13 19:27:23 +02:00
|
|
|
# Install service
|
|
|
|
cp ${SOURCE_DIR}/etc/init.d/cts /etc/init.d/cts
|
|
|
|
rc-update -u
|
|
|
|
|
2018-09-20 15:45:00 +02:00
|
|
|
# Install config update script
|
|
|
|
cp ${SOURCE_DIR}/srv/cts/update-conf.sh /srv/cts/update-conf.sh
|
|
|
|
|
2018-09-13 19:27:23 +02:00
|
|
|
# Stop services required for setup
|
2018-09-13 20:42:11 +02:00
|
|
|
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
|