Spotter-VM/motech.sh

46 lines
2.3 KiB
Bash
Raw Permalink Normal View History

2018-01-23 18:18:46 +01:00
#!/bin/sh
set -e
SOURCE_DIR=$(realpath $(dirname "${0}"))/motech
# Check prerequisites
2018-01-26 21:58:29 +01:00
docker image ls | grep -q activemq || $(realpath $(dirname "${0}"))/activemq.sh
2018-02-03 13:19:24 +01:00
docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh
2018-01-26 21:58:29 +01:00
docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh
service postgres start
2018-01-23 18:18:46 +01:00
# Build Docker container
docker build -t motech ${SOURCE_DIR}
cp ${SOURCE_DIR}/etc/init.d/motech /etc/init.d/motech
rc-update -u
# Create database
export MOTECH_PWD=$(head -c 18 /dev/urandom | base64)
2018-01-23 18:18:46 +01:00
envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql
# Configure Motech
mkdir -p /srv/motech/conf/config/org.motechproject.motech-platform-email
envsubst <${SOURCE_DIR}/srv/motech/conf/config/bootstrap.properties >/srv/motech/conf/config/bootstrap.properties
cp ${SOURCE_DIR}/srv/motech/conf/config-locations.properties /srv/motech/conf/config-locations.properties
cp ${SOURCE_DIR}/srv/motech/conf/config/motech-settings.properties /srv/motech/conf/config/motech-settings.properties
cp ${SOURCE_DIR}/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
# Populate database and create admin account
2018-01-23 18:18:46 +01:00
service motech start
echo `date` '- Waiting for database to be populated. This should take about a minute.'
MOTECH_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' motech)
2018-04-24 23:37:18 +02:00
until curl -s "http://${MOTECH_IP}:8080/module/server/startup/" | grep -q adminLogin; do
2018-01-23 18:18:46 +01:00
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)
2018-04-24 23:37:18 +02:00
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_IP}:8080/module/server/startup/
service motech stop
2018-09-03 17:24:48 +02:00
vm-appmgr update-login motech "${MOTECH_ADMIN_USER}" "${MOTECH_ADMIN_PWD}"
# Stop services required for build
service activemq stop
service postgres stop