Spotter-VM/cts.sh

50 lines
1.8 KiB
Bash
Raw Permalink Normal View History

2017-12-26 09:33:47 +01:00
#!/bin/sh
2017-11-29 20:01:17 +01:00
SOURCE_DIR=$(realpath $(dirname "${0}"))/cts
2017-11-29 20:01:17 +01:00
# Check prerequisites
docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh
2017-12-26 09:33:47 +01:00
# Build Docker container
docker build -t cts ${SOURCE_DIR}
2017-11-29 20:01:17 +01:00
# Create database
export CTS_PWD=$(head -c 18 /dev/urandom | base64)
2017-12-26 09:33:47 +01:00
envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql
# Copy existing config files into persistent storage
mkdir -p /srv/cts/conf
2018-02-01 14:01:05 +01:00
docker run --rm -v /srv/cts/conf:/mnt/conf cts cp /srv/cts/cts/settings/base.py /mnt/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-01-18 13:59:24 +01:00
docker run --rm -h cts --link postgres -v /srv/cts/conf:/srv/cts/cts/settings 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-01-15 21:51:15 +01:00
export CTS_ADMIN_HASH=$(docker run --rm -h cts -v /srv/cts/conf:/srv/cts/cts/settings 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)
2017-12-26 09:33:47 +01:00
envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql cts
2017-11-29 20:01:17 +01:00
2017-12-26 09:33:47 +01:00
# Create CTS service
cp ${SOURCE_DIR}/etc/init.d/cts /etc/init.d/cts
rc-update add cts
2017-12-26 09:33:47 +01:00
service cts start
2017-11-29 20:01:17 +01:00
2017-12-26 09:33:47 +01:00
# Create nginx app definition
cp ${SOURCE_DIR}/etc/nginx/conf.d/cts.conf /etc/nginx/conf.d/cts.conf
service nginx reload
2017-11-29 20:01:17 +01:00
# Add portal application definition
2017-12-26 09:33:47 +01:00
portal-app-manager cts "https://{host}:8406/" "${CTS_ADMIN_EMAIL}" "${CTS_ADMIN_PWD}"