Spotter-VM/crisiscleanup/setup.sh

42 lines
1.6 KiB
Bash
Raw Normal View History

2018-04-21 22:30:25 +02:00
#!/bin/sh
set -e
2018-04-21 22:30:25 +02:00
2018-10-25 22:22:36 +02:00
cd $(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-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-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-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
# 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-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