Spotter-VM/mifosx/install.sh

53 lines
1.8 KiB
Bash
Executable File

#!/bin/sh
set -ev
cd $(realpath $(dirname "${0}"))/install
# Check prerequisites
[ ! -e /run/openrc/started/mariadb ] && service mariadb start && STOP_MARIADB=1
# Create databases
export MIFOSX_PWD=$(head -c 18 /dev/urandom | base64)
envsubst <createdb.sql | lxc-attach mariadb -- mysql
# Populate database
cat /var/lib/lxc/mifosx/mifosx/tmp/mifospltaform-tenants-first-time-install.sql | lxc-attach mariadb -- mysql mifosplatform-tenants
envsubst <schemapwd.sql | lxc-attach mariadb -- mysql mifosplatform-tenants
# Configure Mifos X
mkdir -p /srv/mifosx/conf
envsubst <srv/mifosx/conf/context.xml >/srv/mifosx/conf/context.xml
cp srv/mifosx/conf/server.xml /srv/mifosx/conf/server.xml
# Install service
cp etc/init.d/mifosx /etc/init.d/mifosx
rc-update -u
# Populate database
service mifosx start
echo `date` '- Waiting for database to be populated. This should take about a minute.'
until grep -q 'Migrating schema `mifostenant-default` to version 5000' /var/log/lxc/mifosx.log; do
sleep 1
done
service mifosx stop
# Fix missing previous_run_status column
echo 'ALTER TABLE `scheduled_email_campaign` ADD `previous_run_status` VARCHAR(10) NULL;' | lxc-attach mariadb -- mysql mifostenant-default
# Update admin account
export MIFOSX_ADMIN_USER=admin
export MIFOSX_ADMIN_EMAIL=admin@example.com
export MIFOSX_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d "+")
export MIFOSX_ADMIN_HASH=$(echo -n "${MIFOSX_ADMIN_PWD}{1}" | sha256sum | awk '{print $1}')
envsubst <adminpwd.sql | lxc-attach mariadb -- mysql mifostenant-default
# Install config update script
cp srv/mifosx/update-conf.sh /srv/mifosx/update-conf.sh
# Stop services required for setup
[ ! -z ${STOP_MARIADB} ] && service mariadb stop
# Register application
vmmgr register-app mifosx "${MIFOSX_ADMIN_USER}" "${MIFOSX_ADMIN_PWD}"
exit 0