#!/bin/bash -xe

cTime=$(date -Is)

# export LOGDEST=/var/log/uniworx/${cTime}.log # kubernetes prefers log via stdout

# typeset -a configs

configDir=${CONFIG_DIR-/cfg}
# configs=()
# if [[ -d "${configDir}" ]]; then
#   while IFS= read -d $'\0' cfg; do
#     # IMPORTANT: The paths to the settings-yaml-files should not contain spaces, otherwise this might fail runtime!
#     configs+=("${cfg}")
#   done < <(find "${configDir}" \( -name '*.yml' -o -name '*.yaml' \) -print0 | sort -rz)
# fi

cd /var/lib/uniworx

# exec -- uniworx ${configs}
# find "${configDir}" \( -name '*.yml' -o -name '*.yaml' \) -print0 | sort -rz | xargs -0 exec -- uniworx
find "${configDir}" \( -name '*.yml' -o -name '*.yaml' \) -print0 | sort -rz | xargs -0 uniworx