2017-12-26 09:33:47 +01:00
|
|
|
#!/bin/sh
|
2018-10-28 16:04:11 +01:00
|
|
|
set -ev
|
2017-11-29 20:01:17 +01:00
|
|
|
|
2018-10-26 15:02:11 +02:00
|
|
|
cd $(realpath $(dirname "${0}"))/install
|
2017-11-29 20:01:17 +01:00
|
|
|
|
2019-10-03 13:19:52 +02:00
|
|
|
# Create Postgres instance
|
|
|
|
mkdir -p /srv/cts/postgres_data
|
|
|
|
chown -R 105432:105432 /srv/cts/postgres_data
|
|
|
|
chmod 700 /srv/cts/postgres_data
|
|
|
|
lxc-execute -n cts-postgres -- initdb -D /var/lib/postgresql
|
|
|
|
|
|
|
|
# Configure Postgres
|
|
|
|
cp postgres_data/postgresql.conf /srv/cts/postgres_data/postgresql.conf
|
|
|
|
cp postgres_data/pg_hba.conf /srv/cts/postgres_data/pg_hba.conf
|
2017-11-29 20:01:17 +01:00
|
|
|
|
|
|
|
# Create database
|
2019-06-05 18:55:15 +02:00
|
|
|
export CTS_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
2019-10-03 13:19:52 +02:00
|
|
|
service cts-postgres start
|
|
|
|
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 cts-postgres -- psql
|
2017-12-26 09:33:47 +01:00
|
|
|
|
|
|
|
# Copy existing config files into persistent storage
|
2019-10-03 13:19:52 +02:00
|
|
|
mkdir -p /srv/cts/cts_conf
|
|
|
|
chown 108006:108006 /srv/cts/cts_conf
|
|
|
|
lxc-execute cts -- tar -cC /srv/cts/cts/settings . | tar -xC /srv/cts/cts_conf
|
2017-11-29 20:01:17 +01:00
|
|
|
|
|
|
|
# Configure CTS
|
2019-06-05 18:55:15 +02:00
|
|
|
export CTS_SECRET=$(head -c 26 /dev/urandom | base64 | tr -d '+/=')
|
2019-10-03 13:19:52 +02:00
|
|
|
envsubst <cts_conf/spotter.py >/srv/cts/cts_conf/spotter.py
|
|
|
|
touch /srv/cts/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
|
2019-10-03 13:19:52 +02:00
|
|
|
sed -i 's/DEBUG = True/DEBUG = False/' /srv/cts/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
|
2019-06-05 18:55:15 +02:00
|
|
|
export CTS_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
|
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)
|
2019-10-03 13:19:52 +02:00
|
|
|
envsubst <adminpwd.sql | lxc-attach -u 5432 -g 5432 cts-postgres -- psql cts
|
2018-09-13 19:27:23 +02:00
|
|
|
|
2018-09-20 15:45:00 +02:00
|
|
|
# Install config update script
|
2019-10-03 13:19:52 +02:00
|
|
|
cp update-conf.sh /srv/cts/update-conf.sh
|
2018-09-20 15:45:00 +02:00
|
|
|
|
2018-09-13 19:27:23 +02:00
|
|
|
# Stop services required for setup
|
2019-10-03 13:19:52 +02:00
|
|
|
service cts-postgres 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 cts cts "${CTS_ADMIN_EMAIL}" "${CTS_ADMIN_PWD}"
|