#!/bin/bash -x

mkdir -p /config/jvb

if [[ -z $JVB_AUTH_PASSWORD ]]; then
    echo 'FATAL ERROR: JVB auth password must be set'
    exit 1
fi

OLD_JVB_AUTH_PASSWORD=passw0rd
if [[ "$JVB_AUTH_PASSWORD" == "$OLD_JVB_AUTH_PASSWORD" ]]; then
    echo 'FATAL ERROR: JVB auth password must be changed, check the README'
    exit 1
fi

export MUC_NICKNAME=$(uuidgen)

envsubst < /defaults/jvb/sip-communicator.properties > /config/jvb/sip-communicator.properties

cp /defaults/jvb/logging.properties /config/jvb

chown -R jvb:jitsi /config/jvb
