#!/bin/bash

set -e

. /usr/lib/eole/ihm.sh
. /usr/lib/eole/samba4.sh

SAMBA4_VARS=/etc/eole/samba4-vars.conf

if [ -f "${SAMBA4_VARS}" ]
then
    . "${SAMBA4_VARS}"
else
    # Template is disabled => samba is disabled
    exit 0
fi

case "$1" in
    instance)
	if [ -e "${AD_INSTANCE_LOCK_FILE}" ]
	then
	    EchoOrange "L’Active Directory est déjà initialisé"
	    exit 0
	fi
	samba_instance
	;;
    reconfigure)
	if [ ! -e "${AD_INSTANCE_LOCK_FILE}" ]
	then
	    EchoRouge "Vous devez exécuter instance pour peupler l’Active Directory"
	    exit 1
	fi
	samba_reconfigure
	;;
    *)
	EchoRouge "Paramètre inconnu: ${1}"
	exit 1
	;;
esac
