#!/bin/bash
# Starts Stelo Replicator (settings in .env). Run it as root: it creates the data folders under MOUNTDIR
# on the first start. Unless .env or the shell sets TZ, the containers get the host's time zone.
MOUNTDIR=${MOUNTDIR:-$(sed -n 's/^MOUNTDIR=//p' .env 2>/dev/null | tail -n 1 | tr -d "\"'")}
MOUNTDIR=${MOUNTDIR:-/mnt}
mkdir -p "$MOUNTDIR"/stelo/sqdr "$MOUNTDIR"/stelo/sqdrplus "$MOUNTDIR"/stelo/backups \
         "$MOUNTDIR"/data/home "$MOUNTDIR"/data/db2 "$MOUNTDIR"/logs/db2 \
         "$MOUNTDIR"/data/database "$MOUNTDIR"/data/hadr \
  || { echo "Could not create the data folders under $MOUNTDIR: run compose-start.sh as root" >&2; exit 1; }
if [ -z "${TZ:-}" ] && ! grep -qs '^TZ=.' .env; then
  TZ=$(timedatectl show --property=Timezone 2>/dev/null | awk -F= '{print $2}')
  if [ -n "$TZ" ]; then export TZ; else unset TZ; fi
fi
docker compose up -d
