- 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:
2017-08-02 12:31:18 +02:00
parent af94d5de33
commit 52e2476dd4
4 changed files with 166 additions and 158 deletions

View File

@@ -70,6 +70,9 @@ error(){
echo_ok() {
echo -e "\033[75G[ \033[32mok\033[m ]"
}
echo_done() {
echo -e "\033[75G[ \033[32mok\033[m ]"
}
echo_failed(){
echo -e "\033[75G[ \033[1;31mfailed\033[m ]"
}
@@ -643,16 +646,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
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
@@ -678,10 +681,10 @@ while IFS='' read -r _line || [[ -n $_line ]] ; do
if $(grep -q -e "$IPv4_ADDRESS_OLD" "$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
@@ -690,10 +693,10 @@ while IFS='' read -r _line || [[ -n $_line ]] ; do
if $_set_ipv6 ; then
if $(grep -q -e "$IPv6_ADDRESS_OLD" "$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
@@ -711,16 +714,16 @@ 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 "\tEditing \033[1m$zone_file\033[m .."
## - 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
_replaced=false
## - setze neue ipv4 adresse
## -
@@ -781,15 +784,27 @@ for zone_file in ${zonefiles_arr[@]} ; do
fi
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
echo_ok
_replaced=true
else
echo_failed
error "Increasing Serial for zone file \"`basename $zone_file`\" failed!"
@@ -798,6 +813,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
echo
done