- bind_change_ip.sh: Remove unused and commented code.

- bind_reload_all_zones.sh, bind_disable_ipv6.sh, bind_enable_ipv6.sh: Redesign of the code. Add support for configuration file.
-
This commit is contained in:
2017-08-02 14:08:23 +02:00
parent 52e2476dd4
commit 5a4eab9261
4 changed files with 871 additions and 179 deletions

View File

@@ -1,18 +1,25 @@
#!/usr/bin/env bash
## --- Variables (default Values)
## ---
## - file, where zone definitions live..
## -
_CONF_FILE=/etc/bind/named.conf.local
working_dir="$(dirname $(realpath $0))"
conf_file="${working_dir}/conf/bind.conf"
## ---
## --- End: Variables (default Values)
log_file="$(mktemp)"
## --- some functions
## ---
#---------------------------------------
#-----------------------------
# Base Function(s)
#-----------------------------
#---------------------------------------
clean_up() {
# Perform program exit housekeeping
rm $log_file
exit $1
}
echononl(){
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
@@ -29,7 +36,7 @@ fatal(){
echo ""
echo -e "\t\033[31m\033[1mScript is canceled\033[m\033[m"
echo ""
exit 1
clean_up 1
}
warn (){
@@ -66,25 +73,99 @@ echo_skipped() {
echo -e "\033[75G[ \033[33m\033[1mskipped\033[m ]"
}
## ---
## --- END: functions
trap clean_up SIGHUP SIGINT SIGTERM
#---------------------------------------
#-----------------------------
# Setting Defaults
#-----------------------------
#---------------------------------------
DEFAULT_CONF_FILE_DIR="/etc/bind"
#---------------------------------------
#-----------------------------
# Load default values from bind.conf
#
# Overwrites the settings above
#
#-----------------------------
#---------------------------------------
#clear
echo ""
echo ""
echononl " Loading default Configuration values from $(basename ${conf_file}).."
if [[ ! -f "$conf_file" ]]; then
echo_skipped
else
source "${conf_file}" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
fatal "$(cat $log_file)"
fi
fi
[[ -n "$CONF_FILE_DIR" ]] && DEFAULT_CONF_FILE_DIR="$CONF_FILE_DIR"
if [[ -n "$ZONES_DECLARATION_FILE" ]] ; then
DEFAULT_ZONES_DECLARATION_FILE="$ZONES_DECLARATION_FILE"
else
DEFAULT_ZONES_DECLARATION_FILE="${CONF_FILE_DIR}/named.conf.local"
fi
echo ""
echo "Insert directory containing the bind configuration files."
echo ""
CONF_FILE_DIR=""
if [[ -n "$DEFAULT_CONF_FILE_DIR" ]] ; then
echononl "Bind Configuration Directory [${DEFAULT_CONF_FILE_DIR}]: "
read CONF_FILE_DIR
if [[ "X$CONF_FILE_DIR" = "X" ]]; then
CONF_FILE_DIR="$DEFAULT_CONF_FILE_DIR"
fi
else
echononl "Bind Configuration Directory: "
read CONF_FILE_DIR
while [ "X$CONF_FILE_DIR" = "X" ] ; do
echo -e "\n\t\033[33m\033[1mSetting 'Bind Configuration Directory' is required!\033[m\n"
echononl "Bind Configuration Directory: "
read CONF_FILE_DIR
done
fi
[[ -n "$ZONES_DECLARATION_FILE" ]] || DEFAULT_ZONES_DECLARATION_FILE="${CONF_FILE_DIR}/named.conf.local"
echo ""
echo -e "\033[32m--\033[m"
echo ""
echo " Enter filename containing the zone definitions"
echo "Insert zones declaration file."
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
ZONES_DECLARATION_FILE=""
if [[ -n "$DEFAULT_ZONES_DECLARATION_FILE" ]] ; then
echononl "Zones Declaration File [${DEFAULT_ZONES_DECLARATION_FILE}]: "
read ZONES_DECLARATION_FILE
if [[ "X$ZONES_DECLARATION_FILE" = "X" ]]; then
ZONES_DECLARATION_FILE="$DEFAULT_ZONES_DECLARATION_FILE"
fi
else
echononl "Zones Declaration File: "
read ZONES_DECLARATION_FILE
while [ "X$ZONES_DECLARATION_FILE" = "X" ] ; do
echo -e "\n\t\033[33m\033[1mSetting 'Zones Declaration File' is required!\033[m\n"
echononl "Zones Declaration File: "
read ZONES_DECLARATION_FILE
done
fi
if [ ! -f "$CONF_FILE" ]; then
fatal File not found: $CONF_FILE
fi
clear
echo ""
@@ -93,7 +174,8 @@ echo -e "\033[21G\033[32mReload all (master) Zones\033[m"
echo ""
echo ""
echo "File containing zone definitions..: $CONF_FILE"
echo "Bind Configuration Directory......: $CONF_FILE_DIR"
echo "Zones Declaration File............: $ZONES_DECLARATION_FILE"
echo ""
OK=
@@ -145,11 +227,11 @@ while IFS='' read -r line || [[ -n "$line" ]] ; do
echo_failed
fi
fi
done < $CONF_FILE
done < $ZONES_DECLARATION_FILE
[[ $number -eq 0 ]] && info "No Zonedefinition (master) found in file $CONF_FILE ."
[[ $number -eq 0 ]] && info "No Zonedefinition (master) found in file $ZONES_DECLARATION_FILE ."
info $number Zones reloaded.
echo
exit
clean_up 0