#!/usr/bin/with-contenv bash

##############################################################################
# Migration sequence
# Detect if there is a mounted volume on /wazuh-migration and copy the data
# to /var/ossec, finally it will create a flag ".migration-completed" inside
# the mounted volume
##############################################################################

function __colortext()
{
  echo -e " \e[1;$2m$1\e[0m"
}

function echogreen()
{
  echo $(__colortext "$1" "32")
}

function echoyellow()
{
  echo $(__colortext "$1" "33")
}

function echored()
{
  echo $(__colortext "$1" "31")
}

function_entrypoint_scripts() {
  # It will run every .sh script located in entrypoint-scripts folder in lexicographical order
  if [ -d "/entrypoint-scripts/" ]
  then
    for script in `ls /entrypoint-scripts/*.sh | sort -n`; do
      bash "$script"
    done
  fi
}

# run entrypoint scripts
function_entrypoint_scripts

# Start Wazuh
/var/ossec/bin/wazuh-control start
