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

48 lines
1.9 KiB
Bash
Raw Normal View History

2019-11-15 18:00:26 +01:00
#!/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 decidim-postgres start
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 decidim-postgres -- psql
# Copy existing config files into persistent storage
mkdir -p /srv/decidim/decidim_conf
chown 108080:108080 /srv/decidim/decidim_conf
lxc-execute decidim -- tar -cC /srv/decidim-app/config . | tar -xC /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
2019-11-15 18:00:26 +01:00
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'
2019-11-15 18:00:26 +01:00
# 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'
2019-11-15 18:00:26 +01:00
# Install config update script
cp update-conf.sh /srv/decidim/update-conf.sh
# Stop services required for setup
service decidim-postgres stop
# Register application
vmmgr register-app decidim decidim "${DECIDIM_ADMIN_EMAIL}" "${DECIDIM_ADMIN_PWD}"