48 lines
2.1 KiB
Bash
Executable File
48 lines
2.1 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/crisiscleanup_conf
|
|
chown 108005:108005 /srv/crisiscleanup/crisiscleanup_conf
|
|
lxc-execute crisiscleanup -- tar -cC /srv/crisiscleanup/config . | tar -xC /srv/crisiscleanup/crisiscleanup_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 <crisiscleanup_conf/database.yml >/srv/crisiscleanup/crisiscleanup_conf/database.yml
|
|
cp crisiscleanup_conf/boot.rb /srv/crisiscleanup/crisiscleanup_conf/boot.rb
|
|
cp crisiscleanup_conf/initializers/devise.rb /srv/crisiscleanup/crisiscleanup_conf/initializers/devise.rb
|
|
cp crisiscleanup_conf/environments/production.rb /srv/crisiscleanup/crisiscleanup_conf/environments/production.rb
|
|
|
|
# Populate database
|
|
#envsubst <crisiscleanup_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}"
|