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

53 lines
2.3 KiB
Bash
Raw Normal View History

2018-02-06 19:05:38 +01:00
#!/bin/sh
2018-10-28 16:04:11 +01:00
set -ev
2019-10-05 16:10:29 +02:00
# Create Postgres instance
mkdir -p /srv/sambro/postgres_data
chown -R 105432:105432 /srv/sambro/postgres_data
chmod 700 /srv/sambro/postgres_data
lxc-execute -n sambro-postgres -- initdb -D /var/lib/postgresql
# Configure Postgres
cp postgres_data/postgresql.conf /srv/sambro/postgres_data/postgresql.conf
cp postgres_data/pg_hba.conf /srv/sambro/postgres_data/pg_hba.conf
# Create PostgreSQL user and database
2019-06-05 18:55:15 +02:00
export SAMBRO_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
2019-11-30 22:11:38 +01:00
service lxc-sambro-postgres start
2019-10-05 16:10:29 +02:00
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 sambro-postgres -- psql
2018-01-28 09:13:30 +01:00
# Prepare persistent directory structure
mkdir -p /srv/sambro/sahana_data/databases /srv/sambro/sahana_data/uploads
2020-03-22 19:50:18 +01:00
chown -R 108080:108080 /srv/sambro/sahana_data
lxchelper extract sambro /srv/web2py/applications/eden/models /srv/sambro/sahana_conf
lxchelper extract sambro /srv/web2py/applications/eden/modules/templates/SAMBRO /srv/sambro/sahana_data/SAMBRO
2018-01-28 09:13:30 +01:00
# Configure SAMBRO
2019-06-05 18:55:15 +02:00
export SAMBRO_HMAC=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
export SAMBRO_ADMIN_USER=admin@example.com
2019-06-05 18:55:15 +02:00
export SAMBRO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
2019-10-05 16:10:29 +02:00
envsubst <sahana_conf/000_config.py >/srv/sambro/sahana_conf/000_config.py
2020-03-22 19:50:18 +01:00
envsubst <masterUsers.csv >/srv/sambro/sahana_data/masterUsers.csv
2019-10-05 16:10:29 +02:00
cp sahana_conf/00_settings.py /srv/sambro/sahana_conf/00_settings.py
cp sahana_data/SAMBRO/config.py /srv/sambro/sahana_data/SAMBRO/config.py
chown -R 108080:108080 /srv/sambro/sahana_conf /srv/sambro/sahana_data
# Populate database
lxc-execute -u 8080 -g 8080 sambro -- 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
2018-01-28 09:13:30 +01:00
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/' /srv/sambro/conf/000_config.py
sed -i 's/settings.base.debug = True/settings.base.debug = False/' /srv/sambro/conf/000_config.py
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sambro/conf/000_config.py
fi
# Install config update script
2019-10-05 16:10:29 +02:00
cp update-conf.sh /srv/sambro/update-conf.sh
2019-10-05 16:10:29 +02:00
# Stop services required for setup
2019-11-30 22:11:38 +01:00
service lxc-sambro-postgres stop
2018-10-28 19:50:35 +01:00
# Register application
2019-02-26 21:12:41 +01:00
vmmgr register-app sambro sambro "${SAMBRO_ADMIN_USER}" "${SAMBRO_ADMIN_PWD}"