#!/bin/bash # dib-lint: disable=safe_sudo if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then set -x fi set -eu set -o pipefail # NOTE(dtantsur): this a copy of code from img-functions. We need it because it # runs too late when the image is already built. # Finalise resolv.conf # # NOTE(ianw): the /etc/resolv.conf.ORIG file is an # external interface; elements might put a resolv.conf they # want in the final image into this file. # # In create_base() we replaced/created the initial resolv.conf # inside the image with a copy of the "outside" version so that # resolving during the build will work. # # If that file has been replace with a symlink (resolvconf package # can do this), or marked immutable, then don't restore the # original version, just leave it alone. if [ -L $TMP_MOUNT_PATH/etc/resolv.conf ] || \ lsattr $TMP_MOUNT_PATH/etc/resolv.conf | grep '^....i' >/dev/null ; then # We're keeping the contents of resolv.conf set in the elements, # so remove the old saved file sudo rm -f $TMP_MOUNT_PATH/etc/resolv.conf.ORIG else # Remove the resolv.conf we created and put the original (or # perhaps modified) version back. sudo rm -f $TMP_MOUNT_PATH/etc/resolv.conf # Note that we use -L and -f to test here as test (and bash [[) # return false with -e if the link target does not exist. if [ -L $TMP_MOUNT_PATH/etc/resolv.conf.ORIG ] || [ -f $TMP_MOUNT_PATH/etc/resolv.conf.ORIG ] ; then sudo mv $TMP_MOUNT_PATH/etc/resolv.conf.ORIG $TMP_MOUNT_PATH/etc/resolv.conf fi fi