- 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:
Christoph 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

View File

@ -539,16 +539,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
@ -575,10 +575,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
@ -591,10 +591,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
@ -620,19 +620,17 @@ echo ""
#clean_up 0
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
@ -642,13 +640,10 @@ for zone_file in ${zonefiles_arr[@]} ; do
## -
echononl "\t Set new TTL ($TTL) for IPv4 address $_ipv4_address .."
if grep -e "$TTL\s*IN\s*A\s*$_ipv4_address" $zone_file > /dev/null 2>&1 ; then
if $(grep -q -E "\s+$TTL\s+IN\s+As+$_ipv4_address" $zone_file 2> /dev/null) ; then
echo_skipped
elif grep -e "\s\{1,\}[0-9]\{2,5\}\s\{1,\}IN\s\{1,\}A\s\{1,\}$_ipv4_address" $zone_file > /dev/null 2>&1 ; then
echo_skipped
warn "Another TTL is already set for that IP-Address in file \"`basename $zone_file`\""
else
perl -i -n -p -e "s#IN\s+A\s+$_ipv4_address#$TTL IN A $_ipv4_address#" $zone_file > /dev/null 2>&1
perl -i -n -p -e "s#([0-9]{2,5}\s+)?IN\s+A\s+$_ipv4_address#$TTL IN A $_ipv4_address#" $zone_file > /dev/null 2>&1
if [ "$?" = "0" ]; then
echo_ok
_replaced=true
@ -681,13 +676,10 @@ for zone_file in ${zonefiles_arr[@]} ; do
## -
echononl "\t Set new TTL ($TTL) for IPv6 address $_ipv6_address .."
if grep -e "$TTL\s*IN\s*AAAA\s*$_ipv6_address" $zone_file > /dev/null 2>&1 ; then
if $(grep -q -E "\s+$TTL\s+IN\s+AAAA\s+$_ipv6_address" $zone_file 2> /dev/null) ; then
echo_skipped
elif grep -e "\s\{1,\}[0-9]\{2,5\}\s\{1,\}IN\s\{1,\}AAAA\s\{1,\}$_ipv6_address" $zone_file > /dev/null 2>&1 ; then
echo_skipped
warn "Another TTL is already set for that IP-Address in file \"`basename $zone_file`\""
else
perl -i -n -p -e "s#IN\s+AAAA\s+$_ipv6_address#$TTL IN AAAA $_ipv6_address#" $zone_file > /dev/null 2>&1
perl -i -n -p -e "s#([0-9]{2,5}\s+)?IN\s+AAAA\s+$_ipv6_address#$TTL IN AAAA $_ipv6_address#" $zone_file > /dev/null 2>&1
if [ "$?" = "0" ]; then
echo_ok
_replaced=true
@ -710,15 +702,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=false
else
echo_failed
error "Increasing Serial for zone file \"`basename $zone_file`\" failed!"
@ -727,6 +731,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

View File

@ -548,76 +548,3 @@ fi
$LOGGING && echo ""
clean_up 0
echo ""
echo ""
echo -e "\033[32m--\033[m"
echo ""
echo ""
## - Read list of zonefiles
## -
while IFS='' read -r -d '' zone_file ; do
declare -i _serial_new=`date +%Y%m%d01`
filename=$(basename "$zone_file")
zone="${filename%.*}"
echo ""
echo -e "\tlooking at $zone_file.."
## - 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
echononl "\t Changing SOA Record.."
if ! grep -E "^.*IN\s+SOA\s+${_soa_nameserver}\.\s+${_soa_admin}\.\s+\(" > /dev/null 2>&1 $zone_file ; then
perl -i -n -p -e "s/^(.*IN\s+SOA).*$/\1 ${_soa_nameserver}. ${_soa_admin}. \(/" $zone_file
if [ "$?" = "0" ]; then
echo_ok
else
echo_failed
fi
else
echo_skipped
continue
fi
## - Set new serial
## -
echononl "\t Renew serial.."
perl -i -n -p -e "s#^(\s*) $__serial(.*)#\1 $_serial_new\2#" $zone_file
if [ "$?" = "0" ]; then
echo_ok
else
echo_failed
fi
## - Reload Zone
## -
echononl "\t Reload Zone $zone.."
/usr/sbin/rndc reload $zone > /dev/null 2>&1
if [ "$?" = "0" ]; then
echo_ok
else
echo_failed
fi
sleep 1
done < <(find $_zone_files_dir -mindepth 1 -maxdepth 1 -type f -print0)
echo ""
clean_up 0

View File

@ -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