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

# Directories
SCRIPTS_DIR="/custom-cont-init.d"

# Make sure custom init directory exists and has files in it
if [[ -e "${SCRIPTS_DIR}" ]] && [[ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]]; then
    echo -e " Loader       : Custom files found, loading them ..."
    for SCRIPT in "${SCRIPTS_DIR}"/*; do
        NAME="$(basename "${SCRIPT}")"
        if [[ -f "${SCRIPT}" ]]; then
            echo -e " Loader       : Executing ..."
            /bin/bash "${SCRIPT}"
            echo -e " Loader       : ${NAME}: Exited $?"
        elif [[ ! -f "${SCRIPT}" ]]; then
            echo -e " Loader       : ${NAME}: Not a valid file"
        fi
    done
else
    echo -e " Loader       : No custom files found, skipping..."
fi
