#!/bin/sh set -ev cd $(realpath $(dirname "${0}"))/install # 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 # Create database export CTS_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=') service cts-postgres start envsubst /srv/cts/cts_conf/spotter.py touch /srv/cts/cts_conf/__init__.py # Populate database lxc-execute cts -- manage.py migrate # Create admin account export CTS_ADMIN_EMAIL=admin@example.com export CTS_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=') export CTS_ADMIN_HASH=$(lxc-execute cts -- python -c "from django.contrib.auth.hashers import make_password; print make_password('${CTS_ADMIN_PWD}')") export CTS_ADMIN_SECRET=$(head -c 12 /dev/urandom | sha256sum | cut -c1-13) envsubst