#!/bin/bash

. /usr/lib/eole/ihm.sh
CONTAINER_NAME="addc"
CONTAINER_PATH="/var/lib/lxc/$CONTAINER_NAME"

if [ "$1" = "instance" ]; then
    if [ -d $CONTAINER_PATH ]; then
        echo "Le conteneur $CONTAINER_NAME est présent"
    else
        /usr/share/eole/sbin/eolead
        [ $? -ne 0 ] && exit 1
        keytool -delete -alias eole-ad -keystore /etc/ssl/certs/java/cacerts -storepass changeit >/dev/null
        keytool -import -trustcacerts -keystore /etc/ssl/certs/java/cacerts -storepass changeit -noprompt -alias eole-ad -file $CONTAINER_PATH/rootfs/var/lib/samba/private/tls/ca.pem
    fi
elif [ ! -d $CONTAINER_PATH ]; then
    echo
    EchoRouge "Le conteneur $CONTAINER_NAME n'existe pas"
    echo "Il est nécessaire de relancer la procédure d'instanciation"
    echo
    exit 1
fi

exit 0
