From 9f401d3c23fa850276e79f57f6afe7eebe782b01 Mon Sep 17 00:00:00 2001 From: casjay Date: Sun, 30 Nov 2025 15:59:48 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Refactor=20DNS=20configuration?= =?UTF-8?q?=20scripts=20=F0=9F=92=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rootfs/usr/local/etc/docker/functions/entrypoint.sh rootfs/usr/local/etc/docker/init.d/02-named.sh --- .../usr/local/etc/docker/functions/entrypoint.sh | 4 ++-- rootfs/usr/local/etc/docker/init.d/02-named.sh | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/rootfs/usr/local/etc/docker/functions/entrypoint.sh b/rootfs/usr/local/etc/docker/functions/entrypoint.sh index 4a2f6c5..3780b13 100644 --- a/rootfs/usr/local/etc/docker/functions/entrypoint.sh +++ b/rootfs/usr/local/etc/docker/functions/entrypoint.sh @@ -642,8 +642,8 @@ __create_service_user() { [ -d "$(dirname "$log_file")" ] || mkdir -p "$(dirname "$log_file")" 2>/dev/null # Validate that we have at least a user or group to create if [ -z "$create_user" ] && [ -z "$create_group" ]; then - echo "Error: No user or group specified to create" >&2 - return 1 + echo "No user or group specified to create" >&2 + return 0 fi # Validate user/group name format (alphanumeric, underscore, hyphen; must start with letter or underscore) if [ -n "$create_user" ] && ! echo "$create_user" | grep -qE '^[a-z_][a-z0-9_-]*$'; then diff --git a/rootfs/usr/local/etc/docker/init.d/02-named.sh b/rootfs/usr/local/etc/docker/init.d/02-named.sh index 29be218..2b34d9f 100755 --- a/rootfs/usr/local/etc/docker/init.d/02-named.sh +++ b/rootfs/usr/local/etc/docker/init.d/02-named.sh @@ -20,7 +20,7 @@ # - - - - - - - - - - - - - - - - - - - - - - - - - # shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - -set -e +#set -e # - - - - - - - - - - - - - - - - - - - - - - - - - # run trap command on exit trap 'retVal=$?; echo "❌ Fatal error occurred: Exit code $retVal at line $LINENO in command: $BASH_COMMAND"; kill -TERM 1' ERR @@ -341,7 +341,8 @@ __pre_execute() { zone_files="$(find "$DATA_DIR/zones/" -type f 2>/dev/null | wc -l)" if [ $zone_files = 0 ] && [ ! -f "$VAR_DIR/primary/$HOSTNAME.zone" ]; then file_name="$VAR_DIR/primary/$HOSTNAME.zone" - cat <>"$DNS_ZONE_FILE" + if ! grep -sq "$HOSTNAME" "$DNS_ZONE_FILE"; then + cat <>"$DNS_ZONE_FILE" # ********** begin $HOSTNAME ********** zone "$HOSTNAME" { type master; @@ -353,6 +354,7 @@ zone "$HOSTNAME" { # ********** end $HOSTNAME ********** EOF + fi cat </dev/null ; config for $HOSTNAME @@ -368,7 +370,7 @@ EOF file_name="$(basename "$dns_file")" domain_name="$(grep -Rs '\$ORIGIN' "$dns_file" | awk '{print $NF}' | sed 's|.$||g')" if [ -f "$dns_file" ]; then - if [ -n "$domain_name" ] && ! grep -qs "$domain_name" "$NAMED_CONFIG_FILE"; then + if [ -n "$domain_name" ] && ! grep -qs "$domain_name" "$DNS_ZONE_FILE"; then if [ "$DNS_TYPE" = "secondary" ]; then [ -f "$VAR_DIR/secondary/$file_name" ] || echo "" >"$VAR_DIR/secondary/$file_name" cat <>"$DNS_ZONE_FILE" @@ -383,7 +385,7 @@ zone "$domain_name" { EOF else cp -Rf "$dns_file" "$VAR_DIR/primary/$file_name" - if [ -n "$DNS_SERVER_SECONDARY" ]; then + if [ -n "$DNS_SERVER_SECONDARY" ] && ! grep -qs "$domain_name" "$DNS_ZONE_FILE"; then cat <>"$DNS_ZONE_FILE" # ********** begin $domain_name ********** zone "$domain_name" { @@ -398,7 +400,8 @@ zone "$domain_name" { EOF else - cat <>"$DNS_ZONE_FILE" + if ! grep -qs "$domain_name" "$DNS_ZONE_FILE"; then + cat <>"$DNS_ZONE_FILE" # ********** begin $domain_name ********** zone "$domain_name" { type master; @@ -410,9 +413,10 @@ zone "$domain_name" { # ********** end $domain_name ********** EOF + fi fi fi - grep -qs "$domain_name" "$DNS_ZONE_FILE" && echo "Added $domain_name to $DNS_ZONE_FILE" + grep -qs "$domain_name" "$DNS_ZONE_FILE" && echo "Added $domain_name to $DNS_ZONE_FILE" || true fi fi done