From 3b7f2f788daab492722d8448502ad9b1271e687b Mon Sep 17 00:00:00 2001 From: Gregory Colpart Date: Tue, 1 Sep 2015 02:05:59 +0200 Subject: [PATCH] Fix bug : when serial is greater than date, do $serial++ --- scripts/bind-add-ng.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/bind-add-ng.sh b/scripts/bind-add-ng.sh index 5b3a770..7ab6ad6 100755 --- a/scripts/bind-add-ng.sh +++ b/scripts/bind-add-ng.sh @@ -72,7 +72,10 @@ inc_and_reload () { zonefile="$BINDROOT/db.$domain" - sed -i "s/^\([ \t]*\)[0-9]\{10\}\([ \t]*; serial\)/\1`date "+%Y%m%d%H"`\2/" \ + # Set the date for serial (only if greater than actual serial) + serial=$(grep -E '^[ \t]*[0-9]{10}[ \t]*; serial' $zonefile | sed "s/^[ \t]*\([0-9]\{10\}\)[ \t]*; serial/\1/") + if [ `date "+%Y%m%d%H"` -gt $serial ]; then serial=$(date "+%Y%m%d%H"); else serial=$(( $serial + 1 )); fi + sed -i "s/^\([ \t]*\)[0-9]\{10\}\([ \t]*; serial\)/\1$serial\2/" \ $zonefile if stderr=$(named-checkzone $domain $zonefile 2>&1); then rndc reload