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

50 lines
2.3 KiB
Bash
Executable File

#!/bin/sh
set -ev
# Volumes
POSTGRES_DATA="${VOLUMES_DIR}/decidim/postgres_data"
DECIDIM_CONF="${VOLUMES_DIR}/decidim/decidim_conf"
DECIDIM_DATA="${VOLUMES_DIR}/decidim/decidim_data"
DECIDIM_LAYER="${LAYERS_DIR}/decidim_0.23.1-210106"
# Create Postgres instance
install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}
spoc-container exec decidim-postgres -- initdb -D /var/lib/postgresql
# 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
# Create database
export DECIDIM_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
spoc-container start decidim-postgres
envsubst <createdb.sql | spoc-container exec decidim-postgres -- psql
# Copy existing config files into persistent storage
cp -rp ${DECIDIM_LAYER}/srv/decidim-app/config ${DECIDIM_CONF}
# Configure Decidim
install -o 108080 -g 108080 -m 700 -d ${DECIDIM_DATA}/migrate
install -o 108080 -g 108080 -m 700 -d ${DECIDIM_DATA}/storage
install -o 108080 -g 108080 -m 700 -d ${DECIDIM_DATA}/uploads
export DECIDIM_SECRET=$(spoc-container exec -u 8080 -g 8080 decidim -- sh -c 'cd /srv/decidim-app; bin/rake secret')
install -o 108080 -g 108080 -m 640 decidim_conf/environments/production.rb ${DECIDIM_CONF}/environments/production.rb
install -o 108080 -g 108080 -m 640 decidim_conf/initializers/decidim.rb ${DECIDIM_CONF}/initializers/decidim.rb
envsubst <decidim_conf/application.yml | install -o 108080 -g 108080 -m 640 /dev/stdin ${DECIDIM_CONF}/application.yml
# Populate database
spoc-container exec -u 8080 -g 8080 decidim -- sh -c 'cd /srv/decidim-app; bin/rails decidim:upgrade'
spoc-container exec -u 8080 -g 8080 decidim -- sh -c 'cd /srv/decidim-app; bin/rails generate delayed_job:active_record'
spoc-container exec -u 8080 -g 8080 decidim -- sh -c 'cd /srv/decidim-app; bin/rails db:migrate'
# Create admin account
export DECIDIM_ADMIN_EMAIL="admin@example.com"
export DECIDIM_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
envsubst <adminpwd.rb | spoc-container exec -u 8080 -g 8080 decidim -- sh -c 'cd /srv/decidim-app; bin/rails console -e production'
# Stop services required for setup
spoc-container stop decidim-postgres
# Register application
vmmgr register-app decidim decidim "${DECIDIM_ADMIN_EMAIL}" "${DECIDIM_ADMIN_PWD}"