From 79d5cbfb1a611b02db3f25d2b4b7d08afd7894f3 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Wed, 7 May 2025 11:08:33 +0200 Subject: [PATCH] test alpine dns --- ct/create_lxc.sh | 21 +++++++++++++++++++++ misc/alpine-install.func | 21 --------------------- misc/build.func | 1 + 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/ct/create_lxc.sh b/ct/create_lxc.sh index c715358..5759b15 100644 --- a/ct/create_lxc.sh +++ b/ct/create_lxc.sh @@ -255,6 +255,27 @@ grep -q "root:100000:65536" /etc/subgid || echo "root:100000:65536" >>/etc/subgi PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}}) [[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=(-rootfs "$CONTAINER_STORAGE:${PCT_DISK_SIZE:-8}") +if [ "$UDHCPC_FIX" == "yes" ]; then + CT_ROOT="/var/lib/lxc/${CTID}/rootfs" + CONFIG_FILE="$CT_ROOT/etc/udhcpc/udhcpc.conf" + + if [ -f "$CONFIG_FILE" ]; then + msg_info "Patching udhcpc.conf for Alpine DNS override" + sed -i '/^#*RESOLV_CONF="/d' "$CONFIG_FILE" + 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" + msg_ok "Patched udhcpc.conf (RESOLV_CONF=\"no\")" + else + msg_error "udhcpc.conf not found in $CONFIG_FILE" + fi +fi + msg_info "Creating LXC Container" if ! pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" "${PCT_OPTIONS[@]}" &>/dev/null; then msg_error "Container creation failed. Checking if template is corrupted." diff --git a/misc/alpine-install.func b/misc/alpine-install.func index 261082a..7d9194a 100644 --- a/misc/alpine-install.func +++ b/misc/alpine-install.func @@ -98,27 +98,6 @@ msg_error() { # This function sets up the Container OS by generating the locale, setting the timezone, and checking the network connection setting_up_container() { msg_info "Setting up Container OS" - - # 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" - - # 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" - fi - while [ $i -gt 0 ]; do if [ "$(ip addr show | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d'/' -f1)" != "" ]; then break diff --git a/misc/build.func b/misc/build.func index 62c5ac5..cecbf47 100644 --- a/misc/build.func +++ b/misc/build.func @@ -652,6 +652,7 @@ advanced_settings() { else UDHCPC_FIX="no" fi + export UDHCPC_FIX if MAC1=$(whiptail --backtitle "[dev] Proxmox VE Helper Scripts" --inputbox "Set a MAC Address(leave blank for generated MAC)" 8 58 --title "MAC ADDRESS" 3>&1 1>&2 2>&3); then if [ -z "$MAC1" ]; then