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

check_var() {
    if [ -z "${!1}" ]; then
        echo "Error: No ${2} has been specified in the '${1}' variable. ${3}"
        echo "For more information, see the README: https://github.com/imagegenius/docker-immich#variables"
        sleep infinity
    fi
}

if [ -z "${DB_URL}" ]; then
    #         Variable           Variable Summary                Additional Message
    check_var "DB_HOSTNAME"      "PostgreSQL database host"
    check_var "DB_USERNAME"      "PostgreSQL database user"
    check_var "DB_PASSWORD"      "PostgreSQL database password"
    check_var "DB_DATABASE_NAME" "PostgreSQL database name"
fi
if [ -z "${REDIS_SOCKET}" ] && [ -z "${REDIS_URL}" ]; then
    check_var "REDIS_HOSTNAME" "Redis host"
fi

RED='\033[0;31m'
NC='\033[0m'

if [ -n "$IMMICH_PORT" ]; then
    echo -e "${RED}Don't use \"IMMICH_PORT\":${NC} if you want to change the server port use the environment variable \"SERVER_PORT\", if you want to change the machine-learning port, use the environment variable \"MACHINE_LEARNING_PORT\""
    sleep infinity
fi

if [ -n "$IMMICH_HOST" ]; then
    echo -e "${RED}Don't use \"IMMICH_HOST\":${NC} if you want to change the server host use the environment variable \"SERVER_HOST\", if you want to change the machine-learning host, use the environment variable \"MACHINE_LEARNING_HOST\"/"
    sleep infinity
fi
