Spotter-VM/lxc-apps/sahana-demo/install.sh

44 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
set -ev
# Create Postgres instance
mkdir -p /srv/sahana-demo/postgres_data
chown -R 105432:105432 /srv/sahana-demo/postgres_data
chmod 700 /srv/sahana-demo/postgres_data
lxc-execute -n sahana-demo-postgres -- initdb -D /var/lib/postgresql
# Configure Postgres
cp postgres_data/postgresql.conf /srv/sahana-demo/postgres_data/postgresql.conf
cp postgres_data/pg_hba.conf /srv/sahana-demo/postgres_data/pg_hba.conf
# Create PostgreSQL user and database
export SAHANADEMO_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
service sahana-demo-postgres start
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 sahana-demo-postgres -- psql
# Prepare persistent directory structure
mkdir -p /srv/sahana-demo/sahana_conf /srv/sahana-demo/sahana_data/databases /srv/sahana-demo/sahana_data/uploads /srv/sahana-demo/sahana_data/default
chown -R 108080:108080 /srv/sahana-demo/sahana_conf /srv/sahana-demo/sahana_data
lxc-execute sahana-demo -- tar -cC /srv/web2py/applications/eden/models . | tar -xC /srv/sahana-demo/sahana_conf
lxc-execute sahana-demo -- tar -cC /srv/web2py/applications/eden/modules/templates/default . | tar -xC /srv/sahana-demo/sahana_data/default
# Configure Sahana
export SAHANADEMO_HMAC=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
export SAHANADEMO_ADMIN_USER=admin@example.com
export SAHANADEMO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
envsubst <srv/sahana-demo/conf/000_config.py >/srv/sahana-demo/sahana_conf/000_config.py
envsubst <masterUsers.csv >/srv/sahana-demo/sahana_data/default/users/masterUsers.csv
chown -R 108080:108080 /srv/sahana/sahana_conf /srv/sahana/sahana_data
# Populate database
lxc-execute -u 8080 -g 8080 sahana-demo -- sh -c 'cd /srv/web2py; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py'
# Install config update script
cp update-conf.sh /srv/sahana-demo/update-conf.sh
# Stop services required for setup
service sahana-demo-postgres stop
# Register application
vmmgr register-app sahana-demo sahana-demo "${SAHANADEMO_ADMIN_USER}" "${SAHANADEMO_ADMIN_PWD}"