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

48 lines
1.9 KiB
Bash
Executable File

#!/bin/sh
set -ev
cd $(realpath $(dirname "${0}"))/install
# Create Postgres instance
mkdir -p /srv/crisiscleanup/postgres_data
chown -R 105432:105432 /srv/crisiscleanup/postgres_data
chmod 700 /srv/crisiscleanup/postgres_data
lxc-execute -n crisiscleanup-postgres -- initdb -D /var/lib/postgresql
# Configure Postgres
cp postgres_data/postgresql.conf /srv/crisiscleanup/postgres_data/postgresql.conf
cp postgres_data/pg_hba.conf /srv/crisiscleanup/postgres_data/pg_hba.conf
# Create database
export CRISISCLEANUP_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
service crisiscleanup-postgres start
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 crisiscleanup-postgres -- psql
# Copy existing config files into persistent storage
mkdir -p /srv/crisiscleanup/cc_conf
chown 108080:108080 /srv/crisiscleanup/cc_conf
lxc-execute crisiscleanup -- tar -cC /srv/crisiscleanup/config . | tar -xC /srv/crisiscleanup/cc_conf
# Configure CrisisCleanup
export CRISISCLEANUP_ADMIN_USER="Admin"
export CRISISCLEANUP_ADMIN_EMAIL="admin@example.com"
export CRISISCLEANUP_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
envsubst <cc_conf/database.yml >/srv/crisiscleanup/cc_conf/database.yml
cp cc_conf/boot.rb /srv/crisiscleanup/cc_conf/boot.rb
cp cc_conf/initializers/devise.rb /srv/crisiscleanup/cc_conf/initializers/devise.rb
cp cc_conf/environments/production.rb /srv/crisiscleanup/cc_conf/environments/production.rb
# Populate database
#envsubst <cc_conf/db/seeds.rb >/var/lib/lxc/crisiscleanup/crisiscleanup/srv/crisiscleanup/db/seeds.rb # TODO bud volat User.create! zvlast nebo vyresit jinak
lxc-execute crisiscleanup -- rake db:schema:load
lxc-execute crisiscleanup -- rake db:seed
# Install config update script
cp update-conf.sh /srv/crisiscleanup/update-conf.sh
# Stop services required for setup
service crisiscleanup-postgres stop
# Register application
vmmgr register-app crisiscleanup cc "${CRISISCLEANUP_ADMIN_EMAIL}" "${CRISISCLEANUP_ADMIN_PWD}"