#!/bin/bash

force=$2


if [ -x /usr/bin/CreoleGet ]; then
    ldap_installed="$(CreoleGet openldap_installed oui)"
    if [ $ldap_installed = 'non' ] && [ ! $force ]; then
        exit 0
    fi
fi

set -e

# shellcheck disable=SC1091,SC1090
. /etc/eole/gposcript.conf

# shellcheck disable=SC1091,SC1090
. /etc/eole/samba4-vars.conf

# shellcheck disable=SC1091,SC1090
. /usr/lib/eole/samba4.sh

GPO_NAME="eole_script"
if [ "$GPOSCRIPT" -eq 0 ]; then
    # forcer le ré-import de la GPO eole_script
    touch /var/tmp/gpo-script/update_eole_script
    if samba_import_gpo "$GPO_NAME" "/usr/share/eole/gpo/${GPO_NAME}/" "${BASEDN}"
    then
        echo "* Import GPO $GPO_NAME : OK"
    else
        echo "* Import GPO $GPO_NAME : Erreur ($?)"
    fi
else
    if ! samba_delete_gpo "$GPO_NAME"
    then
        echo "Delete '$GPO_NAME' Erreur"
        # j'ignore si elle a déjà été supprimée !
    else
        echo "Delete '$GPO_NAME' OK"
    fi
fi
