58 lines
2.7 KiB
Bash
Executable File
58 lines
2.7 KiB
Bash
Executable File
#!/bin/sh
|
|
set -ev
|
|
|
|
cd $(realpath $(dirname "${0}"))/install
|
|
|
|
# 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
|
|
export SAMBRO_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
|
service sambro-postgres start
|
|
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 sambro-postgres -- psql
|
|
|
|
# Prepare persistent directory structure
|
|
mkdir -p /srv/sambro/sahana_conf /srv/sambro/sahana_data/databases /srv/sambro/sahana_data/uploads /srv/sambro/sahana_data/SAMBRO
|
|
chown -R 108080:108080 /srv/sambro/sahana_conf /srv/sambro/sahana_data
|
|
lxc-execute sambro -- tar -cC /srv/web2py/applications/eden/models . | tar -xC /srv/sambro/sahana_conf
|
|
lxc-execute sambro -- tar -cC /srv/web2py/applications/eden/modules/templates/SAMBRO . | tar -xC /srv/sambro/sahana_data/SAMBRO
|
|
|
|
# Configure SAMBRO
|
|
export SAMBRO_HMAC=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
|
export SAMBRO_ADMIN_USER=admin@example.com
|
|
export SAMBRO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
|
|
envsubst <sahana_conf/000_config.py >/srv/sambro/sahana_conf/000_config.py
|
|
# TODO:
|
|
#mkdir -p /var/lib/lxc/sambro/sambro/srv/web2py/applications/eden/modules/templates/default/users
|
|
#envsubst <masterUsers.csv >/var/lib/lxc/sambro/sambro/srv/web2py/applications/eden/modules/templates/default/users/masterUsers.csv
|
|
#chown -R 8080:8080 /var/lib/lxc/sambro/sambro/srv/web2py
|
|
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
|
|
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
|
|
cp update-conf.sh /srv/sambro/update-conf.sh
|
|
|
|
# Stop services required for setup
|
|
service sambro-postgres stop
|
|
|
|
# Register application
|
|
vmmgr register-app sambro sambro "${SAMBRO_ADMIN_USER}" "${SAMBRO_ADMIN_PWD}"
|