🚀 Refactor DNS configuration scripts 💻
Some checks failed
release-tag / release-image (push) Failing after 40s

rootfs/usr/local/etc/docker/functions/entrypoint.sh
rootfs/usr/local/etc/docker/init.d/02-named.sh
This commit is contained in:
casjay
2025-11-30 15:59:48 -05:00
parent 2a18d54235
commit 9f401d3c23
2 changed files with 12 additions and 8 deletions

View File

@@ -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 <<EOF >>"$DNS_ZONE_FILE"
if ! grep -sq "$HOSTNAME" "$DNS_ZONE_FILE"; then
cat <<EOF >>"$DNS_ZONE_FILE"
# ********** begin $HOSTNAME **********
zone "$HOSTNAME" {
type master;
@@ -353,6 +354,7 @@ zone "$HOSTNAME" {
# ********** end $HOSTNAME **********
EOF
fi
cat <<EOF | tee "$VAR_DIR/primary/$HOSTNAME.zone" &>/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 <<EOF >>"$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 <<EOF >>"$DNS_ZONE_FILE"
# ********** begin $domain_name **********
zone "$domain_name" {
@@ -398,7 +400,8 @@ zone "$domain_name" {
EOF
else
cat <<EOF >>"$DNS_ZONE_FILE"
if ! grep -qs "$domain_name" "$DNS_ZONE_FILE"; then
cat <<EOF >>"$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