#!/bin/sh

set -e

if [ -f /etc/egzotech/exo-clinic-backend/port ]; then
    EXO_CLINIC_BACKEND_PORT=${EXO_CLINIC_BACKEND_PORT:-$(cat /etc/egzotech/exo-clinic-backend/port)}
fi

if [ ! -z "$EXO_CLINIC_BACKEND_PORT" ]; then
    export OVERRIDE_API_URL=http://localhost:$EXO_CLINIC_BACKEND_PORT/
fi

export OVERRIDE_HOST_API_OPTIONS="$(grep -oh '^[^#]*' /etc/egzotech/exo-clinic/hostenv.d/*)"

EXO_CLINIC_PORT=${EXO_CLINIC_PORT:-$(cat /etc/egzotech/exo-clinic/port)}
exec docker run --rm -t -eOVERRIDE_HOST_API_OPTIONS -eOVERRIDE_API_URL -p $EXO_CLINIC_PORT:80 egzotech/exo-clinic
