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
|
|
|
|
2020-03-16 21:35:33 +01:00
|
|
|
# Volumes
|
|
|
|
POSTGRES_DATA="${VOLUMES_DIR}/cts/postgres_data"
|
|
|
|
CTS_CONF="${VOLUMES_DIR}/cts/cts_conf"
|
2020-03-23 10:10:57 +01:00
|
|
|
CTS_LAYER="${LAYERS_DIR}/cts_0.8.0-200313"
|
2020-03-16 21:35:33 +01:00
|
|
|
|
2019-10-03 13:19:52 +02:00
|
|
|
# Create Postgres instance
|
2020-03-16 21:35:33 +01:00
|
|
|
install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}
|
|
|
|
spoc-container exec cts-postgres -- initdb -D /var/lib/postgresql
|
2019-10-03 13:19:52 +02:00
|
|
|
|
|
|
|
# Configure Postgres
|
2020-03-16 21:35:33 +01:00
|
|
|
install -o 105432 -g 105432 -m 600 postgres_data/postgresql.conf ${POSTGRES_DATA}/postgresql.conf
|
|
|
|
install -o 105432 -g 105432 -m 600 postgres_data/pg_hba.conf ${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 '+/=')
|
2020-03-16 21:35:33 +01:00
|
|
|
spoc-container start cts-postgres
|
|
|
|
envsubst <createdb.sql | spoc-container exec cts-postgres -- psql
|
2017-12-26 09:33:47 +01:00
|
|
|
|
|
|
|
# Copy existing config files into persistent storage
|
2020-03-23 10:10:57 +01:00
|
|
|
cp -rp ${CTS_LAYER}/srv/cts/cts/settings ${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 '+/=')
|
2020-03-16 21:35:33 +01:00
|
|
|
envsubst <cts_conf/spotter.py | install -o 100000 -g 108080 -m 640 /dev/stdin ${CTS_CONF}/spotter.py
|
|
|
|
install -o 100000 -g 108080 -m 640 /dev/null ${CTS_CONF}/__init__.py
|
2017-11-29 20:01:17 +01:00
|
|
|
|
|
|
|
# Populate database
|
2020-03-16 21:35:33 +01:00
|
|
|
spoc-container exec 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 '+/=')
|
2020-03-16 21:35:33 +01:00
|
|
|
export CTS_ADMIN_HASH=$(spoc-container exec cts -- python -c "from django.contrib.auth.hashers import make_password; print make_password('${CTS_ADMIN_PWD}')")
|
2020-03-24 21:51:25 +01:00
|
|
|
export CTS_ADMIN_SECRET=$(head -c 12 /dev/urandom | sha256sum | cut -c0-12)
|
2020-03-16 21:35:33 +01:00
|
|
|
envsubst <adminpwd.sql | spoc-container exec cts-postgres -- psql cts
|
2018-09-20 15:45:00 +02:00
|
|
|
|
2018-09-13 19:27:23 +02:00
|
|
|
# Stop services required for setup
|
2020-03-16 21:35:33 +01:00
|
|
|
spoc-container stop cts-postgres
|
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}"
|