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

46 lines
1.8 KiB
Bash
Executable File

#!/bin/sh
set -ev
# Create Postgres instance
mkdir -p /srv/decidim/postgres_data
chown -R 105432:105432 /srv/decidim/postgres_data
chmod 700 /srv/decidim/postgres_data
lxc-execute -n decidim-postgres -- initdb -D /var/lib/postgresql
# Configure Postgres
cp postgres_data/postgresql.conf /srv/decidim/postgres_data/postgresql.conf
cp postgres_data/pg_hba.conf /srv/decidim/postgres_data/pg_hba.conf
# Create database
export DECIDIM_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
service lxc-decidim-postgres start
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 decidim-postgres -- psql
# Copy existing config files into persistent storage
lxchelper extract decidim /srv/decidim-app/config /srv/decidim/decidim_conf
# Configure Decidim
export DECIDIM_SECRET=$(lxc-execute decidim -- rake secret)
mkdir -p /srv/decidim/decidim_data/storage /srv/decidim/decidim_data/uploads
chown 108080:108080 /srv/decidim/decidim_data/storage /srv/decidim/decidim_data/uploads
cp decidim_conf/environments/production.rb /srv/decidim/decidim_conf/environments/production.rb
cp decidim_conf/initializers/decidim.rb /srv/decidim/decidim_conf/initializers/decidim.rb
envsubst <decidim_conf/application.yml >/srv/decidim/decidim_conf/application.yml
# Populate database
lxc-execute 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 | lxc-execute decidim -- sh -c 'cd /srv/decidim-app; bin/rails console -e production'
# Install config update script
cp update-conf.sh /srv/decidim/update-conf.sh
# Stop services required for setup
service lxc-decidim-postgres stop
# Register application
vmmgr register-app decidim decidim "${DECIDIM_ADMIN_EMAIL}" "${DECIDIM_ADMIN_PWD}"