2018-04-21 22:30:25 +02:00
|
|
|
#!/bin/sh
|
2018-10-28 16:04:11 +01:00
|
|
|
set -ev
|
2018-04-21 22:30:25 +02:00
|
|
|
|
2018-10-26 15:02:11 +02:00
|
|
|
cd $(realpath $(dirname "${0}"))/install
|
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-10-25 22:22:36 +02:00
|
|
|
envsubst <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)
|
2018-10-25 22:22:36 +02:00
|
|
|
envsubst <srv/crisiscleanup/conf/database.yml >/srv/crisiscleanup/conf/database.yml
|
|
|
|
cp srv/crisiscleanup/conf/boot.rb /srv/crisiscleanup/conf/boot.rb
|
|
|
|
cp srv/crisiscleanup/conf/initializers/devise.rb /srv/crisiscleanup/conf/initializers/devise.rb
|
|
|
|
cp srv/crisiscleanup/conf/environments/production.rb /srv/crisiscleanup/conf/environments/production.rb
|
2018-04-21 22:30:25 +02:00
|
|
|
|
|
|
|
# Populate database
|
2018-10-25 22:22:36 +02:00
|
|
|
envsubst <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
|
2018-10-25 22:22:36 +02:00
|
|
|
cp etc/init.d/crisiscleanup /etc/init.d/crisiscleanup
|
2018-09-13 18:31:19 +02:00
|
|
|
rc-update -u
|
2018-07-15 21:55:35 +02:00
|
|
|
|
2018-09-20 15:45:00 +02:00
|
|
|
# Install config update script
|
2018-10-25 22:22:36 +02:00
|
|
|
cp srv/crisiscleanup/update-conf.sh /srv/crisiscleanup/update-conf.sh
|
2018-09-20 15:45:00 +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
|
2018-10-28 19:50:35 +01:00
|
|
|
|
2018-11-03 15:53:51 +01:00
|
|
|
# Register application
|
|
|
|
vmmgr register-app crisiscleanup "${CRISISCLEANUP_ADMIN_EMAIL}" "${CRISISCLEANUP_ADMIN_PWD}"
|