From 831afc5a860e31bc3bf92a3ffd408737435e3673 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Wed, 7 May 2025 11:13:13 +0200 Subject: [PATCH] Update create_lxc.sh --- ct/create_lxc.sh | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/ct/create_lxc.sh b/ct/create_lxc.sh index 5759b15..b8609b9 100644 --- a/ct/create_lxc.sh +++ b/ct/create_lxc.sh @@ -255,27 +255,6 @@ 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." @@ -300,4 +279,24 @@ if ! pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" "${PCT_OPTIONS[ exit 209 fi fi +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_ok "LXC Container ${BL}$CTID${CL} ${GN}was successfully created."