From 10c418ef470ce1d089093ca858b91cd9d2a76951 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Wed, 7 May 2025 09:27:54 +0200 Subject: [PATCH] Update alpine-install.func --- misc/alpine-install.func | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/misc/alpine-install.func b/misc/alpine-install.func index 7ee7cbe..df6d80c 100644 --- a/misc/alpine-install.func +++ b/misc/alpine-install.func @@ -98,26 +98,24 @@ msg_error() { setting_up_container() { msg_info "Setting up Container OS" - # Apply udhcpc.conf DNS override patch if Alpine + # Check if a non-default DNS is configured in /etc/resolv.conf + DNS=$(grep '^nameserver' /etc/resolv.conf | awk '{print $2}' | head -n1) CONFIG_FILE="/etc/udhcpc/udhcpc.conf" - # Extract any configured DNS server from /etc/network/interfaces - CUSTOM_DNS=$(grep -E '^ *dns-nameservers' /etc/network/interfaces 2>/dev/null | awk '{print $2}') - - # Only patch if DNS is set and not 'host' - if [ -n "$CUSTOM_DNS" ] && [ "$CUSTOM_DNS" != "host" ]; then + # Patch only if DNS is set and not 127.0.0.1 + if [ -n "$DNS" ] && [ "$DNS" != "127.0.0.1" ]; then # Remove all RESOLV_CONF= lines (active or commented) sed -i '/^#*RESOLV_CONF="/d' "$CONFIG_FILE" # Rebuild file with single correct entry after header awk ' - /^# Do not overwrite \/etc\/resolv\.conf/ { - print - print "RESOLV_CONF=\"no\"" - next - } - { print } - ' "$CONFIG_FILE" >"${CONFIG_FILE}.tmp" && mv "${CONFIG_FILE}.tmp" "$CONFIG_FILE" + /^# Do not overwrite \/etc\/resolv\.conf/ { + print + print "RESOLV_CONF=\"no\"" + next + } + { print } + ' "$CONFIG_FILE" >"${CONFIG_FILE}.tmp" && mv "${CONFIG_FILE}.tmp" "$CONFIG_FILE" fi while [ $i -gt 0 ]; do