#!/bin/bash

# Script EOP posttemplate

# Copie de la clé flaks en mode conteneur

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

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

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

if [ "$activer_eop" == "oui" ]
then
    # En mode conteneur, il faut copier la clé secrète eop 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 eop 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
