#!/bin/bash

# shellcheck disable=SC1091
. /usr/lib/eole/ihm.sh

DPL=$(CreoleGet activer_deploiement_automatique "non")
[[ ${DPL} == "non" ]] && exit 0

if [[ "${1}" == "instance" ]]
then
    Question_ouinon "Voulez-vous lancer le déploiement automatique des machines virtuelles ?" "True" "non"
    reponse="$?"
    if [ "$reponse" -eq 1 ] # 1 = répondu N avec Default=non
    then
        exit 0
    fi
fi

if [[ ! -d /var/log/hapy-deploy ]]
then
    mkdir /var/log/hapy-deploy
    chown oneadmin:oneadmin /var/log/hapy-deploy
fi

if ! /usr/share/eole/sbin/deploy-auto "${1}"
then
    echo "Déploiement automatique en erreur, mais continue l'instance !"
fi
