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

51 lines
2.2 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
export TEMPLATE=${TEMPLATE:-"default"}
# Check prerequisites
2018-09-14 08:42:37 +02:00
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
# Create PostgreSQL user and database
2019-06-05 18:55:15 +02:00
export SAHANADEMO_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
2018-10-25 22:22:36 +02:00
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
# Prepare persistent directory structure
mkdir -p /srv/sahana-demo/conf /srv/sahana-demo/data/databases /srv/sahana-demo/data/uploads /srv/sahana-demo/data/${TEMPLATE}
chown -R 8001:8001 /srv/sahana-demo/conf /srv/sahana-demo/data
2018-10-28 13:29:01 +01:00
cp -rp /var/lib/lxc/shared/sahana/srv/web2py/applications/eden/models/. /srv/sahana-demo/conf
cp -rp /var/lib/lxc/shared/sahana/srv/web2py/applications/eden/modules/templates/${TEMPLATE}/. /srv/sahana-demo/data/${TEMPLATE}
# 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 '+/=')
2018-10-25 22:22:36 +02:00
envsubst <srv/sahana-demo/conf/000_config.py >/srv/sahana-demo/conf/000_config.py
2018-10-31 18:02:22 +01:00
if [ ${TEMPLATE} == "default" ]; then
envsubst <masterUsers.csv >/srv/sahana-demo/data/default/users/masterUsers.csv
else
mkdir -p /var/lib/lxc/sahana-demo/sahana-demo/srv/web2py/applications/eden/modules/templates/default/users
envsubst <masterUsers.csv >/var/lib/lxc/sahana-demo/sahana-demo/srv/web2py/applications/eden/modules/templates/default/users/masterUsers.csv
chown -R 8001:8001 /var/lib/lxc/sahana-demo/sahana-demo/srv/web2py
fi
2018-09-14 08:53:27 +02:00
# Replace template in LXC container mount definition
2018-09-14 08:42:37 +02:00
sed -i "s/default/${TEMPLATE}/g" /var/lib/lxc/sahana-demo/config
# 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 service
2018-10-25 22:22:36 +02:00
envsubst <etc/init.d/sahana-demo >/etc/init.d/sahana-demo
2018-09-14 08:42:37 +02:00
chmod +x /etc/init.d/sahana-demo
# Install config update script
2018-10-25 22:22:36 +02:00
cp srv/sahana-demo/update-conf.sh /srv/sahana-demo/update-conf.sh
# Stop services required for build
2018-09-14 08:42:37 +02:00
[ ! -z ${STOP_POSTGRES} ] && service 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}"