Spotter-VM/lxc-apps/crisiscleanup/install.sh

45 lines
2.0 KiB
Bash
Raw Normal View History

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
2020-03-16 19:21:08 +01:00
# Volumes
POSTGRES_DATA="${VOLUMES_DIR}/crisiscleanup/postgres_data"
CC_CONF="${VOLUMES_DIR}/crisiscleanup/cc_conf"
CC_LAYER="${LAYERS_DIR}/crisiscleanup_2.2.0-200313"
2020-03-16 19:21:08 +01:00
2019-09-27 11:28:00 +02:00
# Create Postgres instance
2020-03-16 19:21:08 +01:00
install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}
spoc-container exec crisiscleanup-postgres -- initdb -D /var/lib/postgresql
2019-09-27 11:28:00 +02:00
# Configure Postgres
install -o 105432 -g 105432 -m 600 postgres_data/postgresql.conf ${POSTGRES_DATA}/postgresql.conf
install -o 105432 -g 105432 -m 600 postgres_data/pg_hba.conf ${POSTGRES_DATA}/pg_hba.conf
2018-04-21 22:30:25 +02:00
# Create database
2019-06-05 18:55:15 +02:00
export CRISISCLEANUP_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
2020-03-16 19:21:08 +01:00
spoc-container start crisiscleanup-postgres
envsubst <createdb.sql | spoc-container exec crisiscleanup-postgres -- psql
2018-04-21 22:30:25 +02:00
# Copy existing config files into persistent storage
cp -rp ${CC_LAYER}/srv/crisiscleanup/config ${CC_CONF}
2018-04-21 22:30:25 +02:00
# Configure CrisisCleanup
export CRISISCLEANUP_ADMIN_USER="Admin"
export CRISISCLEANUP_ADMIN_EMAIL="admin@example.com"
2019-06-05 18:55:15 +02:00
export CRISISCLEANUP_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
2020-03-16 20:53:27 +01:00
export CRISISCLEANUP_SECRET=$(spoc-container exec crisiscleanup -- rake secret)
envsubst <cc_conf/database.yml | install -o 108080 -g 108080 -m 600 /dev/stdin ${CC_CONF}/database.yml
envsubst <cc_conf/secrets.yml | install -o 108080 -g 108080 -m 600 /dev/stdin ${CC_CONF}/secrets.yml
install -o 108080 -g 108080 -m 640 cc_conf/boot.rb ${CC_CONF}/boot.rb
install -o 108080 -g 108080 -m 640 cc_conf/initializers/devise.rb ${CC_CONF}/initializers/devise.rb
install -o 108080 -g 108080 -m 640 cc_conf/environments/production.rb ${CC_CONF}/environments/production.rb
2018-04-21 22:30:25 +02:00
# Populate database
2020-03-16 19:21:08 +01:00
spoc-container exec crisiscleanup -- rake db:schema:load
envsubst <adminpwd.rb | spoc-container exec crisiscleanup -- sh -c 'cd /srv/crisiscleanup; bin/rails console -e production'
2018-09-13 18:31:19 +02:00
# Stop services required for setup
2020-03-16 19:21:08 +01:00
spoc-container stop crisiscleanup-postgres
2018-10-28 19:50:35 +01:00
# Register application
2019-02-26 21:12:41 +01:00
vmmgr register-app crisiscleanup cc "${CRISISCLEANUP_ADMIN_EMAIL}" "${CRISISCLEANUP_ADMIN_PWD}"