From af7ada0e2b94bb70f52df8f67f42cbc773c56fd1 Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 13 Aug 2017 19:26:39 +0200 Subject: [PATCH] Add possibility to change ZONE_FILE_MASTER_DIR if script acts in interactive mode. Some further minor changes. --- bind_remove_domain_on_master.sh | 50 ++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/bind_remove_domain_on_master.sh b/bind_remove_domain_on_master.sh index 5f10edd..b5555f4 100755 --- a/bind_remove_domain_on_master.sh +++ b/bind_remove_domain_on_master.sh @@ -329,6 +329,31 @@ if $LOGGING ; then done fi + echo "" + echo -e "\033[32m--\033[m" + + echo "" + echo "Insert the directory, where your master zone-files resides." + echo "" + echo "" + ZONE_FILE_MASTER_DIR="" + if [[ -n "$DEFAULT_ZONE_FILE_MASTER_DIR" ]] ; then + echononl "Zone File Directory (master) [${DEFAULT_ZONE_FILE_MASTER_DIR}]: " + read ZONE_FILE_MASTER_DIR + if [[ "X$ZONE_FILE_MASTER_DIR" = "X" ]]; then + ZONE_FILE_MASTER_DIR="$DEFAULT_ZONE_FILE_MASTER_DIR" + fi + else + echononl "Zone File Directory (master): " + read ZONE_FILE_MASTER_DIR + while [ "X$ZONE_FILE_MASTER_DIR" = "X" ] ; do + echo -e "\n\t\033[33m\033[1mSetting 'Zone File Directory (master)' is required!\033[m\n" + echononl "Zone File Directory (master): " + read ZONE_FILE_MASTER_DIR + done + fi + + echo "" echo "" @@ -338,6 +363,7 @@ if $LOGGING ; then echo "" echo -e "\tBind Configuration Directory........: $CONF_FILE_DIR" echo -e "\tZones Declaration File..............: $ZONES_DECLARATION_FILE" + echo -e "\tZone File Directory (master)........: $ZONE_FILE_MASTER_DIR" echo "" info "Remove Domain \033[37m\033[1m${DOMAIN_REQUESTED_TO_REMOVE}\033[m.." @@ -383,16 +409,22 @@ fi backup_date=$(date +%Y-%m-%d-%H%M) echononl " Backup '$ZONES_DECLARATION_FILE'.." -cp -a "$ZONES_DECLARATION_FILE" "${ZONES_DECLARATION_FILE}.$backup_date" > $log_file 2>&1 -if [[ $? -gt 0 ]]; then - echo_failed - error "$(cat $log_file)" +if [[ -f "${ZONES_DECLARATION_FILE}.$backup_date" ]] ; then + echo_skipped else - echo_ok + cp -a "$ZONES_DECLARATION_FILE" "${ZONES_DECLARATION_FILE}.$backup_date" > $log_file 2>&1 + if [[ $? -gt 0 ]]; then + echo_failed + error "$(cat $log_file)" + else + echo_ok + fi fi -if [[ -d "$ZONE_FILE_MASTER_DIR" ]] ; then - echononl " Backup directory '${ZONE_FILE_MASTER_DIR}'.." +echononl " Backup directory '${ZONE_FILE_MASTER_DIR}'.." +if [[ -d ${ZONE_FILE_MASTER_DIR}.${backup_date} ]] ; then + echo_skipped +else cp -a "${ZONE_FILE_MASTER_DIR}" "${ZONE_FILE_MASTER_DIR}.${backup_date}" > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok @@ -452,6 +484,10 @@ while IFS='' read -r _line || [[ -n $_line ]] ; do done < "$ZONES_DECLARATION_FILE" +if $_found ; then + fatal "Configuration for zone '${DOMAIN_REQUESTED_TO_REMOVE}' was found, but cannot be deleted." +fi + $LOGGING && echo "" echononl " Delete zone declaration for domain '${DOMAIN_REQUESTED_TO_REMOVE}'" sed -i "${_first_line},${_last_line}d" "$ZONES_DECLARATION_FILE" > $log_file 2>&1