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
2019-09-27 11:28:00 +02:00
# 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
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 '+/=' )
2019-11-30 22:11:38 +01:00
service lxc-crisiscleanup-postgres start
2019-09-27 11:28:00 +02:00
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 crisiscleanup-postgres -- psql
2018-04-21 22:30:25 +02:00
# Copy existing config files into persistent storage
2019-10-05 16:34:10 +02:00
mkdir -p /srv/crisiscleanup/cc_conf
2019-10-14 07:59:06 +02:00
chown 108080:108080 /srv/crisiscleanup/cc_conf
2019-10-05 16:34:10 +02:00
lxc-execute crisiscleanup -- tar -cC /srv/crisiscleanup/config . | tar -xC /srv/crisiscleanup/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 '+/=' )
2019-10-05 16:34:10 +02:00
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
2018-04-21 22:30:25 +02:00
# Populate database
2019-10-05 16:34:10 +02:00
#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
2018-09-13 18:31:19 +02:00
lxc-execute crisiscleanup -- rake db:schema:load
lxc-execute crisiscleanup -- rake db:seed
2018-09-20 15:45:00 +02:00
# Install config update script
2019-09-27 11:28:00 +02:00
cp 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
2019-11-30 22:11:38 +01:00
service lxc-crisiscleanup-postgres stop
2018-10-28 19:50:35 +01:00
2018-11-03 15:53:51 +01:00
# Register application
2019-02-26 21:12:41 +01:00
vmmgr register-app crisiscleanup cc " ${ CRISISCLEANUP_ADMIN_EMAIL } " " ${ CRISISCLEANUP_ADMIN_PWD } "