- bind_remove_domain.sh: remove unused code (after end of script)
- bind_change_ip.sh, bind_change_ttl.sh, bind_set_ttl_to_default.sh: reloade zone(s) if changed.
This commit is contained in:
@@ -428,6 +428,16 @@ while IFS='' read -r _line || [[ -n $_line ]] ; do
|
||||
|
||||
if [[ $_line =~ ^[[:space:]]*zone[[:space:]]+ ]]; then
|
||||
_found=true
|
||||
zone="$(echo $_line | awk '{print$2}')"
|
||||
shopt -s extglob
|
||||
if [[ $zone =~ \; ]]; then
|
||||
zone=${zone%%*(\;)}
|
||||
fi
|
||||
if [[ $zone =~ ^\" ]]; then
|
||||
zone=${zone##*(\")}
|
||||
zone=${zone%%*(\")}
|
||||
fi
|
||||
shopt -u extglob
|
||||
fi
|
||||
if $_found ; then
|
||||
if [[ $_line =~ $regex_file ]]; then
|
||||
@@ -454,10 +464,10 @@ while IFS='' read -r _line || [[ -n $_line ]] ; do
|
||||
for _ipv4_address in "${ipv4_addresses_arr[@]}" ; do
|
||||
if $(grep -q -E "IN\s+A\s+$_ipv4_address" "$zone_file") ; then
|
||||
if [ ${#zonefiles_arr[@]} -eq 0 ] ; then
|
||||
zonefiles_arr+=("$zone_file")
|
||||
zonefiles_arr+=("${zone_file}:$zone")
|
||||
else
|
||||
if ! containsElement "$zone_file" "${zonefiles_arr[@]}" ; then
|
||||
zonefiles_arr+=("$zone_file")
|
||||
if ! containsElement "${zone_file}:$zone" "${zonefiles_arr[@]}" ; then
|
||||
zonefiles_arr+=("${zone_file}:$zone")
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@@ -470,10 +480,10 @@ while IFS='' read -r _line || [[ -n $_line ]] ; do
|
||||
for _ipv6_address in "${ipv6_addresses_arr[@]}" ; do
|
||||
if $(grep -q -E "IN\s+AAAA\s+$_ipv6_address" "$zone_file") > /dev/null 2>&1 ; then
|
||||
if [ ${#zonefiles_arr[@]} -eq 0 ] ; then
|
||||
zonefiles_arr+=("$zone_file")
|
||||
zonefiles_arr+=("${zone_file}:$zone")
|
||||
else
|
||||
if ! containsElement "$zone_file" "${zonefiles_arr[@]}" ; then
|
||||
zonefiles_arr+=("$zone_file")
|
||||
if ! containsElement "${zone_file}:$zone" "${zonefiles_arr[@]}" ; then
|
||||
zonefiles_arr+=("${zone_file}:$zone")
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@@ -490,19 +500,17 @@ done < "$ZONES_DECLARATION_FILE"
|
||||
|
||||
echo ""
|
||||
|
||||
for zone_file in ${zonefiles_arr[@]} ; do
|
||||
for _val in ${zonefiles_arr[@]} ; do
|
||||
|
||||
IFS=':' read -a _val_arr <<< "${_val}"
|
||||
|
||||
zone_file="${_val_arr[0]}"
|
||||
zone="${_val_arr[1]}"
|
||||
|
||||
echo -e "\n\tEditing \033[37m\033[1m$zone_file\033[m .."
|
||||
|
||||
_replaced=false
|
||||
|
||||
## - calculate new serial
|
||||
## -
|
||||
declare -i __serial=`grep -e "[0-9]\{10\}" $zone_file | grep serial | awk '{print$1}'`
|
||||
while [ ! $_serial_new -gt $__serial ]; do
|
||||
let _serial_new++
|
||||
done
|
||||
|
||||
if $_set_ipv4 ; then
|
||||
|
||||
for _ipv4_address in "${ipv4_addresses_arr[@]}" ; do
|
||||
@@ -510,7 +518,7 @@ for zone_file in ${zonefiles_arr[@]} ; do
|
||||
|
||||
## - setze neue ttl für ipv4 address
|
||||
## -
|
||||
echononl "\t Set TTL to the zonfile default for IPv4 address $_ipv4_address .."
|
||||
echononl "\t Set default TTL for IPv4 '${_ipv4_address}'.."
|
||||
|
||||
if grep -e "\s*[0-9][0-9]\s*IN\s*A\s*$_ipv4_address" $zone_file > /dev/null 2>&1 ; then
|
||||
perl -i -n -p -e "s/^(.+\s+)[0-9]{2,}\s+(IN\s+A\s+$_ipv4_address)/\1\2/" $zone_file
|
||||
@@ -536,7 +544,7 @@ for zone_file in ${zonefiles_arr[@]} ; do
|
||||
|
||||
## - setze neue ttl für ipv6 address
|
||||
## -
|
||||
echononl "\t Set TTL to the zonfile default for IPv6 address $_ipv6_address .."
|
||||
echononl "\t Set default TTL for IPv6 '${_ipv6_address}'.."
|
||||
|
||||
if grep -e "\s*[0-9][0-9]\s*IN\s*AAAA\s*$_ipv6_address" $zone_file > /dev/null 2>&1 ; then
|
||||
perl -i -n -p -e "s/^(.+\s+)[0-9]{2,}\s+(IN\s+AAAA\s+$_ipv6_address)/\1\2/" $zone_file
|
||||
@@ -554,15 +562,27 @@ for zone_file in ${zonefiles_arr[@]} ; do
|
||||
done
|
||||
fi
|
||||
|
||||
## - setze neue serial
|
||||
## -
|
||||
# - Calculate new serial
|
||||
# -
|
||||
echo ""
|
||||
echononl "\t Calculate new serial"
|
||||
if $_replaced ; then
|
||||
declare -i __serial=`grep -e "[0-9]\{10\}" $zone_file | grep serial | awk '{print$1}'`
|
||||
while [ ! $_serial_new -gt $__serial ]; do
|
||||
let _serial_new++
|
||||
done
|
||||
echo_done
|
||||
else
|
||||
echo_skipped
|
||||
fi
|
||||
|
||||
# - Set new serial
|
||||
# -
|
||||
echononl "\t Increase Serial for zone file \"`basename $zone_file`\""
|
||||
if $_replaced ; then
|
||||
perl -i -n -p -e "s#^(\s*)\s$__serial(.*)#\1 $_serial_new\2#" $zone_file > /dev/null 2>&1
|
||||
if [ "$?" = "0" ]; then
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo_ok
|
||||
_replaced=true
|
||||
else
|
||||
echo_failed
|
||||
error "Increasing Serial for zone file \"`basename $zone_file`\" failed!"
|
||||
@@ -571,6 +591,20 @@ for zone_file in ${zonefiles_arr[@]} ; do
|
||||
echo_skipped
|
||||
fi
|
||||
|
||||
# - Reload Zone
|
||||
# -
|
||||
echononl "\t Reload zone '${zone}'"
|
||||
if $_replaced ; then
|
||||
/usr/sbin/rndc reload $zone > /dev/null 2>&1
|
||||
if [[ $? -gt 0 ]]; then
|
||||
echo_failed
|
||||
else
|
||||
echo_ok
|
||||
fi
|
||||
else
|
||||
echo_skipped
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user