From 661158b42df9568d7070b3502e941c07c668c926 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Fri, 19 Mar 2021 15:43:58 +0100 Subject: [PATCH] Copy resolv.conf handling from diskimage-builder The copy in finalise_base runs too late for us, leaving a stale resolv.conf around (usually copied from the build environment). Change-Id: I4b89119b8e2eded72973fa12879b1419542ba984 --- .../cleanup.d/98-prepare-resolve-conf | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 dib/ironic-ramdisk-base/cleanup.d/98-prepare-resolve-conf diff --git a/dib/ironic-ramdisk-base/cleanup.d/98-prepare-resolve-conf b/dib/ironic-ramdisk-base/cleanup.d/98-prepare-resolve-conf new file mode 100755 index 0000000..7e3cb62 --- /dev/null +++ b/dib/ironic-ramdisk-base/cleanup.d/98-prepare-resolve-conf @@ -0,0 +1,42 @@ +#!/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 +