1
0
mirror of https://github.com/vdm-io/dynamic-ip.git synced 2024-12-12 19:07:46 +00:00

improved the DNS zone update method

This commit is contained in:
Llewellyn van der Merwe 2017-07-25 12:04:06 +01:00
parent a623ff9336
commit b8d7b10ea7
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5

View File

@ -210,43 +210,62 @@ function setDNS () {
echo "Done" echo "Done"
echoTweak "Checking local DNS file..." echoTweak "Checking local DNS file..."
# check if the DNS file is found (CENTOS) # check if the DNS file is found (CENTOS)
FILENAME=0 FILEPATH=0
if [ -f "/var/named/${row[1]}.${row[0]}.db" ] if [ -f "/var/named/${row[1]}.${row[0]}.db" ]
then then
FILENAME="/var/named/${row[1]}.${row[0]}.db" FILEPATH="/var/named/${row[1]}.${row[0]}.db"
RELOADNAME="${row[1]}.${row[0]}" FILENAME="${row[1]}.${row[0]}"
elif [ -f "/var/named/${row[0]}.db" ] elif [ -f "/var/named/${row[0]}.db" ]
then then
FILENAME="/var/named/${row[0]}.db" FILEPATH="/var/named/${row[0]}.db"
RELOADNAME="${row[0]}" FILENAME="${row[0]}"
fi fi
# confirm that it was found # confirm that it was found
if [[ "$FILENAME" == 0 ]] if [[ "$FILEPATH" == 0 ]]
then then
echo "not found" echo "not found"
continue continue
fi fi
echo "Done" echo "Done"
# now add the IP A record if needed # now add the IP A record if needed
echoTweak "Update DNS now.." if grep -Fq "${row[2]}" "$FILEPATH"
if grep -Fq "${row[2]}" "$FILENAME"
then then
# IP already set # IP already set
echo "IP (${row[2]}) already set" echoTweak "DNS IP (${row[2]})..."
echo "already set"
else else
# code if not found tmpFile=$(getKey)
echoTweak "${row[1]}" 16 '\040' >> "$FILENAME" # first remove old IPs
echoTweak "1" 8 '\040' >> "$FILENAME" grep -v "^${row[1]}" "$FILEPATH" > "/tmp/vdm_$tmpFile"
echo "IN A ${row[2]}" >> "$FILENAME" # start notice
echoTweak "DNS Adding A Record for IP (${row[2]})"
echo "started"
# add new a record to tmp file
echoTweak "${row[1]}" 16 '\040' >> "/tmp/vdm_$tmpFile"
echoTweak "1" 8 '\040' >> "/tmp/$tmpFile"
echo "IN A ${row[2]}" >> "/tmp/vdm_$tmpFile"
# add new a record to zone file
mv "/tmp/vdm_$tmpFile" "$FILEPATH"
#remove tmp file
# rm "/tmp/vdm_$tmpFile"
# Only reload the rndc if found # Only reload the rndc if found
if [ -f "/etc/rndc.conf" ] if [ -f "/etc/rndc.conf" ]
then then
cd /var/named cd /var/named
rndc reload "$RELOADNAME" IN external 2>/dev/null echoTweak "reload $FILENAME IN external"
rndc reload "$RELOADNAME" IN internal 2>/dev/null rndc reload "$FILENAME" IN external 2>/dev/null
echoTweak "reload $FILENAME IN internal"
rndc reload "$FILENAME" IN internal 2>/dev/null
echoTweak "notify $FILENAME IN external"
rndc notify "$FILENAME" IN external 2>/dev/null
echoTweak "notify $FILENAME IN internal"
rndc notify "$FILENAME" IN internal 2>/dev/null
echoTweak "refresh $FILENAME IN external"
rndc refresh "$FILENAME" IN external 2>/dev/null
echoTweak "refresh $FILENAME IN internal"
rndc refresh "$FILENAME" IN internal 2>/dev/null
cd ~ cd ~
fi fi
echo "Done"
fi fi
fi fi
done done