#!/bin/bash

#
# Instance automatique
# Montages de deux fichier de log. l'utilisation de BOOT_LOG_FILE_STATUS ce fait dans _wait_for_poff_or_error du script deploy-auto

# shellcheck disable=SC1091
source ./context.sh
source ./00_logging.sh

INST=$(CreoleGet module_instancie non)
FBFILE=/etc/eole/firstboot
export HTTP_PROXY=${PROXY}
export HTTPS_PROXY=${PROXY}
export http_proxy=${PROXY}
export https_proxy=${PROXY}

[[ -e ${FBFILE} ]] && exit 0

if [[ ${INST} == "non" ]]
then
    sleep 5
    lgmsg "MAJAUTO:RUNNING:starting maj-auto"
    set -o pipefail
    Maj-Auto 2>&1 | tee -a "${BOOT_LOG_FILE}" 
    res="${?}"
    if [[ "${res}" -eq 0 ]]
    then
        set +o pipefail
        lgmsg "MAJAUTO:DONE:OK"
        exit 0
    fi
    set +o pipefail
    lgmsg "MAJAUTO:ERROR:Maj-Auto failed"
    exit 1
fi
exit 0
