#!/bin/bash

SAMBA4_VARS=$(CreoleGet container_path_domaine)/etc/eole/samba4-vars.conf

if [ ! -f "${SAMBA4_VARS}" ]
then
    # Template is disabled => samba is disabled
    exit 0
fi
export FORCEPTY=yes

# hack pour ne pas creer admin
if [ -f /usr/share/eole/backend/creation-prof.py ] && [ "$(CreoleGet mode_conteneur_actif)" = "oui" ]; then
    DIR=$(CreoleGet container_path_domaine)/usr/share/eole/backend/
    FILE=$DIR/creation-prof.py
    mkdir -p $DIR
    touch $FILE
fi
CreoleRun "/usr/share/eole/samba/samba_configure $1" domaine
[ ! -z $FILE ] && rm -f $FILE
if [ "$1" = "instance" ];then
    CreoleCat -t smb-ad.conf
    if [ "$(CreoleGet ad_server_role)" = "controleur de domaine" ]; then
        service_name=samba-ad-dc
    else
        service_name=smbd
    fi
    CreoleService $service_name restart -c domaine
fi
exit 0
