Spotter-VM/motech/install.sh

46 lines
2.1 KiB
Bash
Raw Normal View History

2018-01-23 18:18:46 +01:00
#!/bin/sh
2018-10-28 16:04:11 +01:00
set -ev
2018-10-26 15:02:11 +02:00
cd $(realpath $(dirname "${0}"))/install
# Check prerequisites
2018-09-13 21:14:53 +02:00
[ ! -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)
2018-10-25 22:22:36 +02:00
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
2018-01-23 18:18:46 +01:00
# Configure Motech
mkdir -p /srv/motech/conf/config/org.motechproject.motech-platform-email
2018-10-25 22:22:36 +02:00
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
2018-01-23 18:18:46 +01:00
chown -R 8013:8013 /srv/motech/conf
2018-09-13 21:14:53 +02:00
# Install service
2018-10-25 22:22:36 +02:00
cp etc/init.d/motech /etc/init.d/motech
2018-09-13 21:14:53 +02:00
rc-update -u
# 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.'
2018-09-13 21:14:53 +02:00
MOTECH_IP=$(awk '/ motech/ {print $1}' /etc/hosts)
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-04 21:42:26 +02:00
vmmgr update-login motech "${MOTECH_ADMIN_USER}" "${MOTECH_ADMIN_PWD}"
# Install config update script
2018-10-25 22:22:36 +02:00
cp srv/motech/update-conf.sh /srv/motech/update-conf.sh
# Stop services required for build
2018-09-13 21:14:53 +02:00
[ ! -z ${STOP_ACTIVEMQ} ] && service activemq stop
[ ! -z ${STOP_POSTGRES} ] && service postgres stop