#!/bin/bash

if [[ -e /usr/bin/lxc-ls ]] && [[ -e /var/lib/lxc/addc/config ]]
then
	lxc-update-config -c /var/lib/lxc/addc/config
fi

if [ -f /usr/share/eole/majauto/eolead ]
then
    # upgrade addc container for ScribeAD
    /usr/share/eole/majauto/eolead
fi

# Remove Samba4 DNS from container nameserver
# https://dev-eole.ac-dijon.fr/issues/28866

if [ -f /usr/lib/eole/eolead.sh ]
then
    . /usr/lib/eole/eolead.sh
    [ -f "${CONTAINER_ROOTFS}"/etc/eole/samba4-vars.conf ] || exit 0
    # ScribeAD
    . "${CONTAINER_ROOTFS}"/etc/eole/samba4-vars.conf
else
    AD_HOST_IP=$(CreoleGet container_ip_addc '')
    [ -n "$AD_HOST_IP" ] || exit 0
    # AmonEcole
    CONTAINER_ROOTFS=""
fi

if [ -f "${CONTAINER_ROOTFS}"/etc/resolv.conf ]
then
    sed -i -e "/${AD_HOST_IP}/d" "${CONTAINER_ROOTFS}"/etc/resolv.conf
fi

exit 0
