2018-04-21 22:30:25 +02:00
|
|
|
#!/bin/sh
|
2018-07-15 21:55:35 +02:00
|
|
|
set -e
|
2018-04-21 22:30:25 +02:00
|
|
|
|
2018-09-13 18:31:19 +02:00
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
|
2018-04-21 22:30:25 +02:00
|
|
|
|
|
|
|
# Check prerequisites
|
2018-09-13 20:42:11 +02:00
|
|
|
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
|
2018-04-21 22:30:25 +02:00
|
|
|
|
|
|
|
# Create database
|
|
|
|
export CRISISCLEANUP_PWD=$(head -c 18 /dev/urandom | base64)
|
2018-09-13 18:31:19 +02:00
|
|
|
envsubst <${SOURCE_DIR}/createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
|
2018-04-21 22:30:25 +02:00
|
|
|
|
|
|
|
# Copy existing config files into persistent storage
|
|
|
|
mkdir -p /srv/crisiscleanup/conf
|
|
|
|
chown 8005:8005 /srv/crisiscleanup/conf
|
2018-09-13 18:31:19 +02:00
|
|
|
cp -r /var/lib/lxc/crisiscleanup/crisiscleanup/srv/crisiscleanup/config/. /srv/crisiscleanup/conf
|
2018-04-21 22:30:25 +02:00
|
|
|
|
|
|
|
# Configure CrisisCleanup
|
|
|
|
export CRISISCLEANUP_ADMIN_USER="Admin"
|
|
|
|
export CRISISCLEANUP_ADMIN_EMAIL="admin@example.com"
|
|
|
|
export CRISISCLEANUP_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
|
|
|
envsubst <${SOURCE_DIR}/srv/crisiscleanup/conf/database.yml >/srv/crisiscleanup/conf/database.yml
|
|
|
|
cp ${SOURCE_DIR}/srv/crisiscleanup/conf/boot.rb /srv/crisiscleanup/conf/boot.rb
|
|
|
|
cp ${SOURCE_DIR}/srv/crisiscleanup/conf/initializers/devise.rb /srv/crisiscleanup/conf/initializers/devise.rb
|
|
|
|
cp ${SOURCE_DIR}/srv/crisiscleanup/conf/environments/production.rb /srv/crisiscleanup/conf/environments/production.rb
|
2018-09-04 21:42:26 +02:00
|
|
|
vmmgr update-login crisiscleanup "${CRISISCLEANUP_ADMIN_EMAIL}" "${CRISISCLEANUP_ADMIN_PWD}"
|
2018-04-21 22:30:25 +02:00
|
|
|
|
|
|
|
# Populate database
|
2018-09-18 16:27:42 +02:00
|
|
|
envsubst <${SOURCE_DIR}/srv/crisiscleanup/db/seeds.rb >/var/lib/lxc/crisiscleanup/crisiscleanup/srv/crisiscleanup/db/seeds.rb
|
2018-09-13 18:31:19 +02:00
|
|
|
lxc-execute crisiscleanup -- rake db:schema:load
|
|
|
|
lxc-execute crisiscleanup -- rake db:seed
|
|
|
|
|
|
|
|
# Install service
|
|
|
|
cp ${SOURCE_DIR}/etc/init.d/crisiscleanup /etc/init.d/crisiscleanup
|
|
|
|
rc-update -u
|
2018-07-15 21:55:35 +02:00
|
|
|
|
2018-09-13 18:31:19 +02:00
|
|
|
# Stop services required for setup
|
2018-09-13 20:42:11 +02:00
|
|
|
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
|