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

46 lines
2.1 KiB
Bash
Raw Normal View History

#!/bin/sh
2018-10-28 16:04:11 +01:00
set -ev
2018-10-26 15:02:11 +02:00
cd $(realpath $(dirname "${0}"))/install
2019-10-05 16:01:55 +02:00
# 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
2019-06-05 18:55:15 +02:00
export SAHANADEMO_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
2019-10-05 16:01:55 +02:00
service sahana-demo-postgres start
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 sahana-demo-postgres -- psql
# Prepare persistent directory structure
2019-10-05 16:01:55 +02:00
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 108001:108001 /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
2019-06-05 18:55:15 +02:00
export SAHANADEMO_HMAC=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
export SAHANADEMO_ADMIN_USER=admin@example.com
2019-06-05 18:55:15 +02:00
export SAHANADEMO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
2019-10-05 16:01:55 +02:00
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 108001:108001 /srv/sahana/sahana_conf /srv/sahana/sahana_data
2018-09-14 08:42:37 +02:00
# Populate database
2018-10-28 13:29:01 +01:00
lxc-execute -u 8001 -g 8001 sahana-demo -- sh -c 'cd /srv/web2py; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py'
2018-09-14 08:42:37 +02:00
# Install config update script
2019-10-05 16:01:55 +02:00
cp update-conf.sh /srv/sahana-demo/update-conf.sh
2019-10-05 16:01:55 +02:00
# Stop services required for setup
service sahana-demo-postgres stop
2018-10-28 19:50:35 +01:00
# Register application
2019-02-26 21:12:41 +01:00
vmmgr register-app sahana-demo sahana-demo "${SAHANADEMO_ADMIN_USER}" "${SAHANADEMO_ADMIN_PWD}"