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

48 lines
1.8 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=$(rake secret)
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 -- RAILS_ENV=production bin/rails db:create db:migrate
# Create admin account
export DECIDIM_ADMIN_EMAIL=admin@example.com
export DECIDIM_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
#lxc-execute decidim -- bin/rails console -e production
#user = Decidim::System::Admin.new(email: "admin@example.org", password: "P8vDKAc3FdEte9Hw", password_confirmation: "P8vDKAc3FdEte9Hw")
#user.save!
# 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}"