Spotter-VM/cts/install.sh

49 lines
1.6 KiB
Bash
Raw Normal View History

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
# 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-10-25 22:22:36 +02:00
envsubst <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)
2018-10-25 22:22:36 +02:00
envsubst <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-10-25 22:22:36 +02:00
envsubst <adminpwd.sql | lxc-attach -u 5432 -g 5432 postgres -- psql cts
2018-09-13 19:27:23 +02:00
# Install service
2018-10-25 22:22:36 +02:00
cp etc/init.d/cts /etc/init.d/cts
2018-09-13 19:27:23 +02:00
rc-update -u
# Install config update script
2018-10-25 22:22:36 +02:00
cp 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
2018-10-28 19:50:35 +01:00
# Register application
2019-02-26 21:12:41 +01:00
vmmgr register-app cts cts "${CTS_ADMIN_EMAIL}" "${CTS_ADMIN_PWD}"