#!/bin/sh
set -ev

# Volumes
FLSMS_DATA="${VOLUMES_DIR}/frontlinesms/flsms_data"

# Configure FrontlineSMS
install -o 108080 -g 108080 -m 750 -d ${FLSMS_DATA}
export FRONTLINESMS_ADMIN_USER="admin"
export FRONTLINESMS_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
export FRONTLINESMS_ADMIN_USER_HASH=$(echo -n "${FRONTLINESMS_ADMIN_USER}" | base64)
export FRONTLINESMS_ADMIN_PWD_HASH=$(echo -n "${FRONTLINESMS_ADMIN_PWD}" | base64)
envsubst <flsms_data/app-settings.properties | install -o 108080 -g 108080 -m 640 /dev/stdin ${FLSMS_DATA}/app-settings.properties

# Register application
vmmgr register-app frontlinesms sms "${FRONTLINESMS_ADMIN_USER}" "${FRONTLINESMS_ADMIN_PWD}"
