Spotter-VM/sahana/install.sh
Disassembler ce325cf3d0
Squashed commit of the following:
- Bump basic OS to Alpine 3.9
 - Restructure repo and add layer versioning
 - Use JSON for all metadata
 - Merge abuild branch (but without abuild)
2019-02-26 20:24:02 +01:00

52 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
set -ev
cd $(realpath $(dirname "${0}"))/install
# Check prerequisites
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
# Create PostgreSQL user and database
export SAHANA_PWD=$(head -c 18 /dev/urandom | base64)
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
# Prepare persistent directory structure
mkdir -p /srv/sahana/conf /srv/sahana/data/databases /srv/sahana/data/uploads
chown -R 8001:8001 /srv/sahana/conf
cp -rp /var/lib/lxc/shared/sahana/srv/web2py/applications/eden/models/. /srv/sahana/conf
# Copy Spotter template
cp -r srv/sahana/data/Spotter /srv/sahana/data/
chown -R 8001:8001 /srv/sahana/data
# Configure Sahana
export SAHANA_HMAC=$(head -c 18 /dev/urandom | base64)
export SAHANA_ADMIN_USER=admin@example.com
export SAHANA_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
envsubst <srv/sahana/conf/000_config.py >/srv/sahana/conf/000_config.py
envsubst <srv/sahana/data/Spotter/masterUsers.csv >/srv/sahana/data/Spotter/masterUsers.csv
cp srv/sahana/conf/00_settings.py /srv/sahana/conf/00_settings.py
# Populate database
lxc-execute -u 8001 -g 8001 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/conf/000_config.py
sed -i 's/settings.base.debug = True/settings.base.debug = False/' /srv/sahana/conf/000_config.py
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sahana/conf/000_config.py
fi
# Install service
cp etc/init.d/sahana /etc/init.d/sahana
rc-update -u
# Install config update script
cp srv/sahana/update-conf.sh /srv/sahana/update-conf.sh
# Stop services required for build
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
# Register application
vmmgr register-app sahana "${SAHANA_ADMIN_USER}" "${SAHANA_ADMIN_PWD}"