Spotter-VM/motech/install.sh

46 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
set -ev
cd $(realpath $(dirname "${0}"))/install
# Check prerequisites
[ ! -e /run/openrc/started/activemq ] && service activemq start && STOP_ACTIVEMQ=1
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
# Create database
export MOTECH_PWD=$(head -c 18 /dev/urandom | base64)
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
# Configure Motech
mkdir -p /srv/motech/conf/config/org.motechproject.motech-platform-email
envsubst <srv/motech/conf/config/bootstrap.properties >/srv/motech/conf/config/bootstrap.properties
cp srv/motech/conf/config-locations.properties /srv/motech/conf/config-locations.properties
cp srv/motech/conf/config/motech-settings.properties /srv/motech/conf/config/motech-settings.properties
cp srv/motech/conf/config/org.motechproject.motech-platform-email/motech-email.properties /srv/motech/conf/config/org.motechproject.motech-platform-email/motech-email.properties
chown -R 8013:8013 /srv/motech/conf
# Install service
cp etc/init.d/motech /etc/init.d/motech
rc-update -u
# Populate database and create admin account
lxc-start motech
until curl -s "http://motech:8080/module/server/startup/" | grep -q adminLogin; do
sleep 1
done
export MOTECH_ADMIN_USER="admin"
export MOTECH_ADMIN_EMAIL="admin@example.com"
export MOTECH_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
curl -H "Content-Type: application/json" -X POST -d "{\"adminLogin\":\"${MOTECH_ADMIN_USER}\",\"adminEmail\":\"${MOTECH_ADMIN_EMAIL}\",\"adminPassword\":\"${MOTECH_ADMIN_PWD}\",\"adminConfirmPassword\":\"${MOTECH_ADMIN_PWD}\",\"language\":\"cs\",\"providerName\":\"\",\"providerUrl\":\"\",\"schedulerUrl\":\"\"}" http://motech:8080/module/server/startup/
lxc-stop motech
# Install config update script
cp srv/motech/update-conf.sh /srv/motech/update-conf.sh
# Stop services required for build
[ ! -z ${STOP_ACTIVEMQ} ] && service activemq stop
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
# Register application
vmmgr register-app motech "${MOTECH_ADMIN_USER}" "${MOTECH_ADMIN_PWD}"