#!/usr/bin/with-contenv bash
# shellcheck shell=bash source=/dev/null

# check if machine learning is set to an external server
[[ "${IMMICH_MACHINE_LEARNING_URL}" != "http://127.0.0.1:3003" ]] && echo "WARN: Disabling the machine learning service as 'IMMICH_MACHINE_LEARNING_URL' is set externally (${IMMICH_MACHINE_LEARNING_URL})!"

# stop machine learning from starting
[[ "${DISABLE_MACHINE_LEARNING}" == "true" || "${IMMICH_MACHINE_LEARNING_URL}" != "http://127.0.0.1:3003" ]] && tail -f /dev/null

export LD_PRELOAD="/usr/lib/$(arch)-linux-gnu/libmimalloc.so.3"
export IMMICH_HOST="${MACHINE_LEARNING_HOST:-"0.0.0.0"}"
export IMMICH_PORT="${MACHINE_LEARNING_PORT:-"3003"}"
export MPLCONFIGDIR="/tmp"
export HF_HOME="/tmp"

exec \
    cd /app/immich/machine-learning s6-setuidgid abc \
        python3 -m immich_ml || exit
