bind/OLD_Versions/bind_reload_all_zones.sh
2017-08-04 00:15:29 +02:00

156 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
## --- Variables (default Values)
## ---
## - file, where zone definitions live..
## -
_CONF_FILE=/etc/bind/named.conf.local
## ---
## --- End: Variables (default Values)
## --- some functions
## ---
echononl(){
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
echo -e -n "$*\\c" 1>&2
else
echo -e -n "$*" 1>&2
fi
rm /tmp/shprompt$$
}
fatal(){
echo ""
echo -e "[ \033[31m\033[1mError\033[m ]: $*"
echo ""
echo -e "\t\033[31m\033[1mScript is canceled\033[m\033[m"
echo ""
exit 1
}
warn (){
echo ""
echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*"
echo ""
}
info (){
echo ""
echo -e "\t[ \033[33m\033[1mInfo\033[m ]: $*"
echo ""
}
ok (){
echo ""
echo -e "\t[ \033[36m\033[1mOk\033[m ]: $*"
echo ""
}
error(){
echo ""
echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*"
echo ""
}
echo_ok() {
echo -e "\033[75G[ \033[32mok\033[m ]"
}
echo_failed(){
echo -e "\033[75G[ \033[1;31mfailed\033[m ]"
}
echo_skipped() {
echo -e "\033[75G[ \033[33m\033[1mskipped\033[m ]"
}
## ---
## --- END: functions
echo ""
echo -e "\033[32m--\033[m"
echo ""
echo " Enter filename containing the zone definitions"
echo ""
echo ""
CONF_FILE=
echononl "Filename containing the zone definitions [$_CONF_FILE]: "
read CONF_FILE
if [ "X$CONF_FILE" = "X" ]; then
CONF_FILE=$_CONF_FILE
fi
if [ ! -f "$CONF_FILE" ]; then
fatal File not found: $CONF_FILE
fi
clear
echo ""
echo ""
echo -e "\033[21G\033[32mReload all (master) Zones\033[m"
echo ""
echo ""
echo "File containing zone definitions..: $CONF_FILE"
echo ""
OK=
while [ "$OK" != "yes" -o "$OK" != "no" ] ; do
echononl "Parameters ok? [yes/no]: "
read OK
## - To lower case
OK=${OK,,}
if [ "X$OK" = "X" ]; then
echo -e "\n\t\033[33m\033[1mAn entry is required!\033[m\n"
OK=""
continue
fi
if [ "$OK" = "yes" -o "$OK" = "no" ] ; then
break
else
OK=""
continue
fi
echo -e "\n\t\033[33m\033[1mWrong entry!\033[m\n"
done
[[ $OK = "yes" ]] || fatal Repeat execution with different parameters
echo ""
## - Read Zonefile line by line
## -
## - || [[ -n $line ]] prevents the last line from being ignored if it doesn't end with a \n
## -
declare -i number=0
regex_master="type[[:space:]]+master"
while IFS='' read -r line || [[ -n "$line" ]] ; do
if [[ $line =~ ^\s*zone ]]; then
zone=`echo $line | awk '{print$2}'`
shopt -s extglob
if [[ $zone =~ ^\" ]]; then
zone=${zone##*(\")}
zone=${zone%%*(\")}
fi
shopt -u extglob
fi
if [[ $line =~ $regex_master ]]; then
echononl "\tReload Zone \"$zone\""
/usr/sbin/rndc reload $zone > /dev/null 2>&1
if [ "$?" = "0" ]; then
echo_ok
let number="$number+1"
sleep 1
else
echo_failed
fi
fi
done < $CONF_FILE
[[ $number -eq 0 ]] && info "No Zonedefinition (master) found in file $CONF_FILE ."
info $number Zones reloaded.
echo
exit