#!/nix/store/r0wrj1l79j267np3z5i657pnprsd74fq-zsh-5.8/bin/zsh -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
    configs+=("${(q)cfg}")
  done < <(find "${configDir}" \( -name '*.yml' -o -name '*.yaml' \) -print0 | sort -rz)
fi
configs+=('/nix/store/mr2s10y1pj1fx594gjx0qlvc704n1j00-uni2work.yml')

cd /var/lib/uniworx

exec -- uniworx ${configs}
