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

57 lines
2.4 KiB
Bash
Executable File

#!/bin/sh
set -ev
cd $(realpath $(dirname "${0}"))/install
# Create Postgres instance
mkdir -p /srv/sahana/postgres_data
chown -R 105432:105432 /srv/sahana/postgres_data
chmod 700 /srv/sahana/postgres_data
lxc-execute -n sahana-postgres -- initdb -D /var/lib/postgresql
# Configure Postgres
cp postgres_data/postgresql.conf /srv/sahana/postgres_data/postgresql.conf
cp postgres_data/pg_hba.conf /srv/sahana/postgres_data/pg_hba.conf
# Create PostgreSQL user and database
export SAHANA_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
service sahana-postgres start
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 sahana-postgres -- psql
# Prepare persistent directory structure
mkdir -p /srv/sahana/sahana_conf /srv/sahana/sahana_data/databases /srv/sahana/sahana_data/uploads
chown -R 108080:108080 /srv/sahana/sahana_conf
lxc-execute sahana -- tar -cC /srv/web2py/applications/eden/models . | tar -xC /srv/sahana/sahana_conf
# Copy Spotter template
cp -r sahana_data/Spotter /srv/sahana/sahana_data/
chown -R 108080:108080 /srv/sahana/sahana_data
# Configure Sahana
export SAHANA_HMAC=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
export SAHANA_ADMIN_USER=admin@example.com
export SAHANA_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
envsubst <sahana_conf/000_config.py >/srv/sahana/sahana_conf/000_config.py
envsubst <sahana_data/Spotter/masterUsers.csv >/srv/sahana/sahana_data/Spotter/masterUsers.csv
cp sahana_conf/00_settings.py /srv/sahana/sahana_conf/00_settings.py
chown -R 108080:108080 /srv/sahana/sahana_conf /srv/sahana/sahana_data
# Populate database
lxc-execute -u 8080 -g 8080 sahana -- sh -c 'cd /srv/web2py; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py'
# Set "production values" (increases performance) only if the DEBUG environment variable is not set
if [ ${DEBUG:-0} -eq 0 ]; then
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/' /srv/sahana/sahana_conf/000_config.py
sed -i 's/settings.base.debug = True/settings.base.debug = False/' /srv/sahana/sahana_conf/000_config.py
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sahana/sahana_conf/000_config.py
fi
# Install config update script
cp update-conf.sh /srv/sahana/update-conf.sh
# Stop services required for setup
service sahana-postgres stop
# Register application
vmmgr register-app sahana sahana "${SAHANA_ADMIN_USER}" "${SAHANA_ADMIN_PWD}"