#!/bin/bash

# Script EOE posttemplate

# Copie de la clé flaks en mode conteneur

# Doit avoir lieu en dernier après l'activation d'eoe (posttemplate/51-eoe)
# et après le renew des clés flask (posttemplate d'eoleflask)

############################################

activer_eoe=$(CreoleGet activer_eoe non)
mode_conteneur_actif=$(CreoleGet mode_conteneur_actif)
path_key="/etc/eole/flask/keys"
key="eoe.key"

if [ "$activer_eoe" == "oui" ]
then
    # En mode conteneur, il faut copier la clé secrète eoe dans le
    # conteneur fichier pour la rendre accessible à controle-vnc
    if [ "$mode_conteneur_actif" = "oui" ]; then
        container_path_web=$(CreoleGet container_path_web)
        container_path_fichier=$(CreoleGet container_path_fichier)
        test -d "$container_path_fichier$path_key" || mkdir -p "$container_path_fichier$path_key"
        cp -f $container_path_web$path_key/$key $container_path_fichier$path_key
    fi
else
    # En mode conteneur, suppression la clé secrète eoe du conteneur fichier
    if [ "$mode_conteneur_actif" = "oui" ]; then
        container_path_fichier=$(CreoleGet container_path_fichier)
        if [ -e "$container_path_fichier$path_key/$key" ];then
            rm -f $container_path_fichier$path_key/$key
        fi
    fi
fi
exit 0
