#!/bin/bash
# Override the default /etc/apt/apt.conf.d directory with $DIB_APT_CONF_DIR

if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
    set -x
fi
set -eu
set -o pipefail

# exit directly if DIB_APT_CONF_DIR is not defined properly
if [ -z "${DIB_APT_CONF_DIR:-}" ] ; then
    echo "DIB_APT_CONF_DIR is not set - no apt.conf.d will be copied in"
    exit 0
elif [ ! -d "$DIB_APT_CONF_DIR" ] ; then
    echo "$DIB_APT_CONF_DIR is not a valid apt.conf.d directory."
    echo "You should assign a proper apt.conf.d directory in DIB_APT_CONF_DIR"
    exit 1
fi

# copy the apt.conf to cloudimg
sudo cp -L -f -R $DIB_APT_CONF_DIR $TMP_MOUNT_PATH/etc/apt
