#!/usr/bin/env bash

EPHEMERAL_ROOT="/ephemeral"
TMP_ROOT="/tmp"

makeFolderIfNotExist() {
    if [ ! -d "$1" ]; then
      mkdir -p "$1" || exit 1
    fi
}

makeLinkedFolder() {
    ROOT="$1"
    TARGET="$2"
    if [ ! -d "$TARGET" ]; then
      if [ -d "$ROOT" ]; then
        REAL_PATH="$ROOT/$TARGET"
        makeFolderIfNotExist "$REAL_PATH" || exit 1
        makeFolderIfNotExist $(dirname "$TARGET")
        ln -s "$REAL_PATH" "$TARGET" || exit 1
      else
        makeFolderIfNotExist "$TARGET" || exit 1
      fi
    fi
}

makeLinkedFolder "$EPHEMERAL_ROOT" "{{ folders.logFolder }}" || exit 1
makeLinkedFolder "$EPHEMERAL_ROOT" "{{ folders.data }}" || exit 1

makeLinkedFolder "$TMP_ROOT" "{{ folders.temp }}" || exit 1

{{ folders.bin }}/start.sh
