#!/usr/bin/env bash log_file="$(mktemp)" only_check_domains=false print_warnings=true if [[ "$(basename $0)" = "check_domain_on_webserver.sh" ]] ; then only_check_domains=true elif [[ "$(basename $0)" = "show_domain_on_webserver.sh" ]] ; then only_check_domains=true print_warnings=false fi # ------------- # - Variable settings # ------------- # ------------- # --- Some functions # ------------- clean_up() { # Perform program exit housekeeping rm -f $log_file exit $1 } # - Check if a given array (parameter 2) contains a given string (parameter 1) # - containsElement () { local e for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done return 1 } stringContain() { [ -z "${2##*$1*}" ] && [ -z "$1" -o -n "$2" ] } # - Remove leading/trailling whitespaces # - trim() { local var="$*" var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters echo -n "$var" } 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 "" if [[ -n "$*" ]] ; then echo -e " [ \033[31m\033[1mFatal\033[m ]: $*" echo "" fi echo -e " \033[31m\033[1mScript will be interrupted.\033[m\033[m" echo "" clean_up 1 } error(){ echo "" echo -e " [ \033[31m\033[1mFehler\033[m ]: $*" echo "" } warn (){ echo "" echo -e " [ \033[33m\033[1mWarning\033[m ]: $*" echo "" } info (){ echo "" echo -e " [ \033[32m\033[1mInfo\033[m ]: $*" echo "" } echo_done() { echo -e "\033[80G[ \033[32mdone\033[m ]" } echo_ok() { echo -e "\033[80G[ \033[32mok\033[m ]" } echo_warning() { echo -e "\033[80G[ \033[33m\033[1mwarn\033[m ]" } echo_failed(){ echo -e "\033[80G[ \033[1;31mfailed\033[m ]" } echo_skipped() { echo -e "\033[80G[ \033[37mskipped\033[m ]" } trap clean_up SIGHUP SIGINT SIGTERM # ------------- # - Some checks # ------------- # - Is 'systemd' supported on this system # - if [ "X`which systemd`" = "X" ]; then systemd_exists=false else systemd_exists=true fi [[ -n "$*" ]] && _domains="$*" # - # - grep -i -d skip -h -E "^\s*include\s+.*\.conf" $_apache_vhost_base_dir | awk '{print$2}' # - # - Try to find apache vhost configuration directory # - if [[ -d "/usr/local/apache2/conf/vhosts" ]]; then if [[ -d "/usr/local/apache2/conf/vhosts/0" ]]; then _apache_vhost_dir="/usr/local/apache2/conf/vhosts/0" else _apache_vhost_dir="/usr/local/apache2/conf/vhosts" fi elif [[ -d "/etc/apache2/sites-available" ]]; then _apache_vhost_dir="/etc/apache2/sites-available" fi clear echo "" echo "" echo -e "\033[32m--\033[m" echo "" echo "Insert domain(s), you wish to delete database, webspace and webserver configurations for.." echo "" echo " Multi domains are supported - give a blank separated list" echo "" echo "" domains= if [ -z "$_domains" ]; then echononl "Domain: " read domains while [ "X$domains" = "X" ] ; do echo -e "\n\t\033[33m\033[1mEingabe erforderlich.\033[m\n" echononl "Domain: " read domains done else echononl "Domain [${_domains}]: " read domains if [[ "X$domains" = "X" ]]; then domains=$_domains fi fi declare -a domain_req_for_del_arr declare -a domain_marked_for_del_arr for _domain in $domains ; do domain_req_for_del_arr+=("$_domain") done echo "" echo "" echo -e "\033[32m--\033[m" echo "" echo "Insert Apache VHost directory.." echo "" echo "" apache_vhost_dir= if [ -z "$_apache_vhost_dir" ]; then echononl "Apache VHost directory: " read apache_vhost_dir while [[ "X$apache_vhost_dir" = "X" ]] ; do echo -e "\n\t\033[33m\033[1mEingabe erforderlich.\033[m\n" echononl "Apache VHost directory: " read apache_vhost_dir done else echononl "Apache VHost directory [${_apache_vhost_dir}]: " read apache_vhost_dir if [[ "X$apache_vhost_dir" = "X" ]] ; then apache_vhost_dir="$_apache_vhost_dir" fi fi echo "" echo "" echo -e "\033[32m--\033[m" echo "" echo -n " Domain(s)............................: " declare -i counter=1 for _domain in "${domain_req_for_del_arr[@]}" ; do if [[ $counter -eq 1 ]] ; then echo "$_domain" else echo " $_domain" fi counter=$((counter+1)) done unset counter echo "" echo " Apache Vhosts Directory..............: $apache_vhost_dir" echo "" echo "" warn "To continue with te above Setting type uppercase 'YES'." echo -n "Continue: " read OK echo "" if [[ "$OK" != "YES" ]] ; then fatal "Abort by user request - Answer as not 'YES'" fi # ----- # - Gathering global settings # ----- # - Check if mod_php is installed. # - mod_php_installed=false if $(httpd -M | grep -q -E "php[5-9]?_module" 2>/dev/null) ; then mod_php_installed=true if $(apachectl status | grep -q "PHP/" 2>/dev/null) ; then MOD_PHP_VERSION="$(trim $(apachectl status | grep "PHP/" | cut -d '/' -f2))" else MOD_PHP_VERSION=" UNKNOWN" warn "'mod_php' ist running, but i cannot dermin the PHP Version.\n 'apachectl status' does not work on this server." fi fi #declare -a _all_vhost_files_arr #declare -a _all_document_root_dirs_arr #while IFS='' read -r -d '' filename ; do # if ! containsElement "$(realpath $filename)" "${_all_vhost_files_arr[@]}" ; then # _all_vhost_files_arr+=("$(realpath $filename)") # fi #done < <(find $apache_vhost_dir -mindepth 1 -maxdepth 1 -type f -print0) # #for _vhost_file in ${_all_vhost_files_arr[@]} ; do # _doc_root="$(grep -E "\s*DocumentRoot\s+" $_vhost_file 2> /dev/null \ # | awk '{print$2}' | sed 's/"//g' | sed 's/\/$//' | sort -u )" # if [[ -n "${_doc_root}" ]]; then # _all_document_root_dirs_arr+=("${_doc_root}:${_vhost_file}") # fi #done # - Associative Array(s) # - declare -A vhost_file_domain_arr # - Non associative Array(s) # - declare -a vhost_file_req_for_del_arr declare -a vhost_file_marked_for_del_arr declare -a no_vhost_config_found declare -a docroot_req_for_del_arr declare -a docroot_marked_for_del_arr declare -a database_req_for_del_arr declare -a database_marked_for_del_arr declare -a hostname_in_use_arr declare -a msg_exclude_vhost_file_from_del_arr declare -a msg_exclude_doc_root_from_del_arr declare -a msg_exclude_domain_from_del_arr for domain in "${domain_req_for_del_arr[@]}" ; do echo "" echo -e "\033[32mGoing to inspect domain \033[1m${domain}\033[m:" # - Empty domain concerning arrays # - hostname_arr=() vhost_file_arr=() symlink_file_arr=() activ_file_arr=() inactiv_file_arr=() documentroot_arr=() database_arr=() msg_missing_database_arr=() msg_hostname_in_use_arr=() php_version_arr=() php_version_active_arr=() # ----- # - Get Vhost configuration for current domain # ----- _vhost_files="$(grep -l -d skip -E "^\s*(ServerName|ServerAlias)\s+.*${domain}" $apache_vhost_dir/* 2> /dev/null)" if [[ -z "$_vhost_files" ]]; then error "No VHost Configuration found for domain \033[37m\033[1m${domain}\033[m." # - Delete current domain from array 'domain_req_for_del_arr' # - no_vhost_config_found+=("${domain}") continue fi echo "" for _vhost_file in $_vhost_files ; do _basename_vhost_file="$(basename $_vhost_file)" containsElement "$_basename_vhost_file" "${vhost_file_arr[@]}" && continue vhost_file_arr+=("$_basename_vhost_file") if [[ -z "${vhost_file_domain_arr["$domain"]}" ]] ; then vhost_file_domain_arr["$domain"]="$_basename_vhost_file" else vhost_file_domain_arr["$domain"]="${vhost_file_domain_arr["$domain"]}:$_basename_vhost_file" fi if ! containsElement "$_basename_vhost_file" "${vhost_file_req_for_del_arr[@]}" ; then vhost_file_req_for_del_arr+=("$_basename_vhost_file") fi if [[ "${_vhost_file##*.}" = "conf" ]]; then if [[ -L "$_vhost_file" ]] ; then symlink_file_arr+=("$_basename_vhost_file") _vhost_file="$(realpath $_vhost_file)" activ_file_arr+=("$(basename $(realpath $_vhost_file))") # - If this file was (wrongly) written befor into array 'inactiv_file_arr' (see below) # - we will delete it from array here. # - if containsElement "$_basename_vhost_file" "${inactiv_file_arr[@]}" ; then new_array=() for value in "${inactiv_file_arr[@]}" ; do [[ $value != "$_basename_vhost_file" ]] && new_array+=($value) done inactiv_file_arr=("${new_array[@]}") unset new_array fi else activ_file_arr+=("$_basename_vhost_file") fi else # - If an activ configuration file will be added here. We # - correct it some loops later (see above) # - inactiv_file_arr+=("$_basename_vhost_file") fi # ----- # - Get hostnames of current vhost configuration file # ----- # - Get Server Name # - _server_names=$(grep -i -E "^\s*ServerName" $_vhost_file | sed -e "s/ServerName//" | sed "s/^\s*//" | sed "s/\s*$//" | sort -u) if [[ -n "$_server_names" ]] ; then for _server_name in $_server_names ; do if [[ ${#hostname_arr[@]} -eq 0 ]] ; then hostname_arr+=("$_server_name") else containsElement "$_server_name" "${hostname_arr[@]}" && continue hostname_arr+=("$_server_name") fi done fi # - Get Server Aliase # - _server_aliases=$(grep -i -E "^\s*ServerAlias" $_vhost_file | sed -e "s/ServerAlias//" | sed "s/^\s*//" | sed "s/\s*$//" | sort -u) if [[ -n "$_server_aliases" ]] ; then for _server_alias in $_server_aliases ; do if [[ ${#hostname_arr[@]} -eq 0 ]] ; then hostname_arr+=("$_server_alias") else containsElement "$_server_alias" "${hostname_arr[@]}" && continue hostname_arr+=("$_server_alias") fi done fi # - Are there any hostnames NOT concerning to domains, which are requested # - to delete? # - __msg="" for hostname in ${hostname_arr[@]} ; do _matched_domain=false for _other_domain in ${domain_req_for_del_arr[@]} ; do if [[ "$hostname" =~ ${_other_domain}$ ]] ; then _matched_domain=true break fi done if ! $_matched_domain ; then _tld="${hostname##*.}" _tmp_str="${hostname%.*}" _maindomain="${_tmp_str##*.}" if ! containsElement "$_basename_vhost_file:${hostname}:${_maindomain}.${_tld}" "${hostname_in_use_arr[@]}" ; then __msg="The Vhost configuration file \033[37m\033[1m$_basename_vhost_file\033[m contains also hostname \033[33m${hostname}\033[m. But the concerning domain \033[33m${_maindomain}.${_tld}\033[m is not requested for deletion." msg_hostname_in_use_arr[${#msg_hostname_in_use_arr[@]}]="$__msg" hostname_in_use_arr+=("$_basename_vhost_file:${hostname}:${_maindomain}.${_tld}") fi fi done # ----- # - Get documetroot of current VHost configuration file # ---- _documentroot=$(grep -E "^\s*DocumentRoot" $_vhost_file 2> /dev/null | awk '{print$2}' | sed 's/"//g' | sed 's/\/$//' | sort -u) if ! containsElement "$_documentroot" "${documentroot_arr[@]}" ; then documentroot_arr+=("$_documentroot") if ! containsElement "$_documentroot" "${docroot_req_for_del_arr[@]}" ; then docroot_req_for_del_arr+=("$_documentroot") fi fi done # for _vhost_file in $_vhost_files # --- # - Get databases # --- for _doc_root in "${documentroot_arr[@]}" ; do file_to_check="$(dirname $_doc_root)/db.inc.php" file_to_check_mediawiki="$(dirname $_doc_root)/htdocs/LocalSettings.php" _found=false if [[ -r "$file_to_check_mediawiki" ]] && [[ ! -d "$file_to_check_mediawiki" ]] ; then db_search_string='\$wgDBname' #db_search_string='\$wgEnableUserEmail' _found=false if grep -i -q "$db_search_string" $file_to_check_mediawiki > /dev/null 2>&1 ; then database="$(grep -i "$db_search_string" $file_to_check_mediawiki 2> /dev/null \ | awk -F '=' '{print$2}' \ | awk -F ';' '{print$1}'\ | tail -1)" # - Remove leading whitespace characters database="${database#"${database%%[![:space:]]*}"}" # - Remove trailing whitespace characters database="${database%"${database##*[![:space:]]}"}" # - Remove leading single quote database="${database#"${database%%[!\']*}"}" # - Remove trailing single quote database="${database%"${database##*[!\']}"}" # - Remove leading double quote database="${database#"${database%%[!\"]*}"}" # - Remove trailing double quote database="${database%"${database##*[!\"]}"}" _found=true fi elif [[ -r "$file_to_check" ]] && [[ ! -d "$file_to_check" ]]; then db_search_strings='\$db_name \$mysql_db' _found=false for _string in $db_search_strings ; do if grep -i -q -E "^\s*$_string" $file_to_check > /dev/null 2>&1 ; then database="$(grep -i -E "^\s*$_string" $file_to_check 2> /dev/null | awk -F '=' '{print$2}' | tail -1 )" # - Remove leading whitespace characters database="${database#"${database%%[![:space:]]*}"}" # - Remove trailing whitespace characters database="${database%"${database##*[![:space:]]}"}" # - Rmove trailing semicolon characters database="${database%"${database##*[!;]}"}" # - Remove trailing whitespace characters database="${database#"${database%%[!\']*}"}" # - Remove trailing inverted comma characters database="${database%"${database##*[!\']}"}" _found=true break fi done if ! $_found ; then file_to_check="${_doc_root}/includes/config.inc.php" if [[ -f "$file_to_check" ]]; then if grep -i -q -E "^\s*define\('DB_DATABASE'" $file_to_check > /dev/null 2>&1 ; then database="$(grep -i -m 1 -E "^\s*define\('DB_DATABASE'" $file_to_check 2> /dev/null \ | awk -F ',' '{print$2}' \ | awk -F ')' '{print$1}' \ | tail -1 )" # - Remove leading whitespace characters database="${database#"${database%%[![:space:]]*}"}" # - Remove trailing whitespace characters database="${database%"${database##*[![:space:]]}"}" # - Remove leading single quote database="${database#"${database%%[!\']*}"}" # - Remove trailing single quote database="${database%"${database##*[!\']}"}" # - Remove leading double quote database="${database#"${database%%[!\"]*}"}" # - Remove trailing double quote database="${database%"${database##*[!\"]}"}" _found=true fi fi fi fi if $_found ; then database_arr+=("${database}:${_doc_root}") database_req_for_del_arr+=("${database}") else __msg="No database found for documentroot directory ${_doc_root}" msg_missing_database_arr+=("$__msg") fi done # ----- # - Get PHP version of current vhost configuration file # ----- for _file in ${vhost_file_arr[@]} ; do _php_engine="" _php_version="" CUR_IFS=$IFS IFS='' if grep -q -E "^\s*(ProxyPassMatch|SetHandler).*php-[5-9]\.[0-9]+-" $apache_vhost_dir/$_file 2> /dev/null ; then _php_engine="PHP FPM/FastCGI" if grep -q -E "^\s*(SetHandler).*php-[5-9]\.[0-9]+-" $apache_vhost_dir/$_file 2> /dev/null ; then _php_fpm_socket="$(grep -E "^\s*(SetHandler).*php-[5-9]\.[0-9]+-" $apache_vhost_dir/$_file 2> /dev/null \ | head -1 | cut -d ':' -f3 | cut -d'|' -f1)" else _php_fpm_socket= fi if [[ -S "$_php_fpm_socket" ]] ; then _php_version="$(exec /usr/local/php-$(echo "$_php_fpm_socket" | grep -o -E "[5-9]\.[0-9]")/bin/php-cgi -v \ | head -1 | awk '{print$2}')" else _php_version=" UNKNOWN" fi elif grep -d skip -q -E "^\s*FCGIWrapper\s+.*\.php" $apache_vhost_dir/$_file 2> /dev/null ; then _php_engine="PHP CGI/FastCGI" _fcgid_file="$(grep -E "^\s*FCGIWrapper\s+.*\.php" $apache_vhost_dir/$_file 2> /dev/null \ | head -1 | awk '{print$2}')" if [[ -f "$_fcgid_file" ]] ; then _php_version="$($(grep "exec" $_fcgid_file | awk '{print$2}') -v | head -1 | awk '{print$2}')" [[ -z "$_php_version" ]] && _php_version="unknown Version" else _php_version=" UNKNOWN" fi elif $mod_php_installed ; then #_php_engine="Apache 2.0 Handler" _php_engine="Apache Handler" _php_version="$MOD_PHP_VERSION" else _php_engine="No PHP assigned" fi if ! containsElement "$_file:${_php_engine}:$_php_version" "${php_version_arr[@]}" ; then php_version_arr+=("$_file:${_php_engine}:$_php_version") fi if containsElement "$_file" "${activ_file_arr[@]}" ; then php_version_active_arr+=("$_file:${_php_engine}:$_php_version") fi IFS=$CUR_IFS done # ----- # - Summary current domain # ----- #echo -e " \033[32mSummary domain \033[1m${domain}\033[m:\n" echo " VHost files:" for _file in ${vhost_file_arr[@]} ; do echo -n " $_file" if containsElement "$_file" "${symlink_file_arr[@]}" ; then echo " (Symlink)" elif containsElement "$_file" "${activ_file_arr[@]}" ; then echo " (active)" else echo " (inactive)" fi done echo "" CUR_IFS=$IFS IFS='' echo " PHP Versions (active):" for _val in ${php_version_active_arr[@]} ; do IFS=':' read -a _val_arr <<< "$_val" echo -e " ${_val_arr[0]}:\033[55G\033[33m${_val_arr[1]} ${_val_arr[2]}\033[m" done echo "" echo " PHP Versions (all):" for _val in ${php_version_arr[@]} ; do IFS=':' read -a _val_arr <<< "$_val" echo -e " ${_val_arr[0]}:\033[55G${_val_arr[1]} ${_val_arr[2]}" done echo "" IFS=$CUR_IFS echo " Hostnames: " for _hostname in ${hostname_arr[@]} ; do echo " $_hostname" done echo "" echo " DocumentRoot directories: " for _doc_root in ${documentroot_arr[@]} ; do echo " $_doc_root" done echo "" echo " Database(s):" for _val in "${database_arr[@]}" ; do IFS=':' read -a _val_arr <<< "$_val" echo " ${_val_arr[0]} - ${_val_arr[1]}" done echo "" if $print_warnings ; then # ----- # - Warnings current documentroot # ----- CUR_IFS=$IFS IFS='' msg="" declare -i _counter=1 if [[ ${#msg_hostname_in_use_arr[@]} -gt 0 ]] ; then for _msg in ${msg_hostname_in_use_arr[@]} ; do if [[ $_counter -eq 1 ]]; then msg="$_msg" else msg="$msg\n\n $_msg" fi _counter=$((_counter+1)) done warn "$msg" fi IFS=$CUR_IFS # - !! must be placed outside domain-loop # - #if [[ ${#documentroot_in_use_arr[@]} -gt 0 ]] ; then # for _val in ${documentroot_in_use_arr[@]} ; do # IFS=':' read -a _val_arr <<< "${_val}" # echo "${_val_arr[0]} is also in use at VHost configuration file ${_val_arr[1]}!" # done #fi # ----- # - Warnings current database(s) # ----- CUR_IFS=$IFS IFS='' msg="" declare -i _counter=1 if [[ ${#msg_missing_database_arr[@]} -gt 0 ]] ; then for _msg in ${msg_missing_database_arr[@]} ; do if [[ $_counter -eq 1 ]]; then msg="$_msg" else msg="$msg\n\n $_msg" fi _counter=$((_counter+1)) done warn "$msg" fi IFS=$CUR_IFS fi # if $print_warnings done if $only_check_domains ; then rm -f $log_file echo "" clean_up fi echo "" echo -e "\033[32m------\033[m" echo -e "Summary VHost Configuration files" echo -e "\033[32m------\033[m" # ========== # - Vhost configuration files # ========== for _vhost_file in ${vhost_file_req_for_del_arr[@]}; do _found=false for _val in ${hostname_in_use_arr[@]} ; do IFS=':' read -a _val_arr <<< "${_val}" if [[ "${_val_arr[0]}" = "$_vhost_file" ]] ; then _found=true __msg="The VHost configuration file \033[37m\033[1m${_vhost_file}\033[m is also used at least by domain \033[33m${_val_arr[1]}\033[m. But that domain isn't marked for deletion." msg_exclude_vhost_file_from_del_arr[${#msg_exclude_vhost_file_from_del_arr[@]}]="$__msg" break fi done if ! $_found ; then vhost_file_marked_for_del_arr+=("$_vhost_file") fi done # - VHost configuration files requested for deletion # - echo "" echo " VHost configuration files requested for deletion" if [[ ${#vhost_file_req_for_del_arr[@]} -gt 0 ]]; then for _vhost_file in ${vhost_file_req_for_del_arr[@]} ; do echo " $_vhost_file" done else echo -e " *** \033[33mNo VHost configuration files are requested for deletion\033[m ***" fi # - VHost configurtion files marked for deletion # - echo "" echo " VHost configuration files marked for deletion" if [[ ${#vhost_file_marked_for_del_arr[@]} -gt 0 ]]; then for _vhost_file in ${vhost_file_marked_for_del_arr[@]} ; do echo " $_vhost_file" done else echo -e " *** \033[33mNo VHost configuration files are marked for deletion\033[m ***" fi # ----- # - Warn about VHost configurtion files not be marked for deletion. # ----- CUR_IFS=$IFS IFS='' msg="" declare -i _counter=1 if [[ ${#msg_exclude_vhost_file_from_del_arr[@]} -gt 0 ]] ; then for _msg in ${msg_exclude_vhost_file_from_del_arr[@]} ; do if [[ $_counter -eq 1 ]]; then msg="$_msg" else msg="$msg\n\n $_msg" fi _counter=$((_counter+1)) done warn "$msg" fi IFS=$CUR_IFS echo "" echo -e "\033[32m------\033[m" echo -e "Summary DocumentRoot directories" echo -e "\033[32m------\033[m" # ========== # - DocumentRoot directories # ========== # - Check for DocumetRoot directories that are in use by VHost configuration files NOT # - marked for deletion. If found, do also NOT mark that DocumentRoot directory for # - deletion. # - for _doc_root in ${docroot_req_for_del_arr[@]} ; do _tmp_files="$(grep -l -d skip -E "\s*DocumentRoot\s+\"?${_doc_root}" $apache_vhost_dir/* 2> /dev/null)" _not_in_use_by_others=true for _tmp_file in $_tmp_files ; do if ! containsElement "$(basename $_tmp_file)" "${vhost_file_marked_for_del_arr[@]}" ; then _not_in_use_by_others=false __msg="The DocumentRoot directory \033[37m\033[1m${_doc_root}\033[m is also used by vhost configuration file \033[33m${_tmp_file}\033[m. But this file isn't marked for deletion." msg_exclude_doc_root_from_del_arr[${#msg_exclude_doc_root_from_del_arr[@]}]="$__msg" break fi done if $_not_in_use_by_others ; then if ! containsElement "$_doc_root" "${docroot_marked_for_del_arr[@]}" ; then docroot_marked_for_del_arr+=("${_doc_root}") fi fi done # - DocumentRoot directories requested for deletion # - echo "" echo " DocumentRoot directories requested for deletion" if [[ ${#docroot_req_for_del_arr[@]} -gt 0 ]]; then for _doc_root in ${docroot_req_for_del_arr[@]} ; do echo " $_doc_root" done else echo -e " *** \033[33mNo DocumentRoot directories are requested for deletion\033[m ***" fi # - DocumentRoot directories marked for deletion # - echo "" echo " DocumentRoot directories marked for deletion" if [[ ${#docroot_marked_for_del_arr[@]} -gt 0 ]]; then for _doc_root in ${docroot_marked_for_del_arr[@]} ; do echo " $_doc_root" done else echo -e " *** \033[33mNo DocumentRoot directories are marked for deletion\033[m ***" fi # ----- # - Warn about DocumentRoot directories that connot be deleted it is referenced # - by vhost configuration files NOT marked for deletion. # ----- CUR_IFS=$IFS IFS='' msg="" declare -i _counter=1 if [[ ${#msg_exclude_doc_root_from_del_arr[@]} -gt 0 ]] ; then for _msg in ${msg_exclude_doc_root_from_del_arr[@]} ; do if [[ $_counter -eq 1 ]]; then msg="$_msg" else msg="$msg\n\n $_msg" fi _counter=$((_counter+1)) done warn "$msg" fi IFS=$CUR_IFS echo "" echo -e "\033[32m\033[1m------\033[m" echo -e "Summary Domains" echo -e "\033[32m\033[1m------\033[m" # ========== # - Domains # ========== # - Check if domain can savely be marked for deletion. That is, if no remaining # - VHost configuration files contains hostname concerning that domain # - for domain in "${domain_req_for_del_arr[@]}" ; do if containsElement "$domain" "${no_vhost_config_found[@]}" ; then __msg="No VHost configuration present for domain \033[37m\033[1m${domain}\033[m. The domain is not marked for deletion." msg_exclude_domain_from_del_arr[${#msg_exclude_domain_from_del_arr[@]}]="$__msg" continue fi _not_found=false IFS=':' read -a _val_arr <<< "${vhost_file_domain_arr["$domain"]}" for _vhost_file in "${_val_arr[@]}" ; do if ! containsElement "$_vhost_file" "${vhost_file_marked_for_del_arr[@]}" ; then _not_found=true fi done if $_not_found ; then __msg="At least VHost configuration File \033[33m${_vhost_file}\033[m for domain \033[37m\033[1m${domain}\033[m is excluded from deletion. So also the domain itself will not marked for deletion." msg_exclude_domain_from_del_arr[${#msg_exclude_domain_from_del_arr[@]}]="$__msg" else domain_marked_for_del_arr+=("$domain") fi done # - Domain(s) files requested for deletion # - echo "" echo " Domain(s) requested for deletion" if [[ ${#domain_req_for_del_arr[@]} -gt 0 ]]; then for _domain in "${domain_req_for_del_arr[@]}" ; do echo " $_domain" done else echo -e " *** \033[33mNo Domain is requested for deletion\033[m ***" fi # - Domain(s) marked for deletion # - echo "" echo " Domain(s) marked for deletion" if [[ ${#domain_marked_for_del_arr[@]} -gt 0 ]]; then for _domain in "${domain_marked_for_del_arr[@]}" ; do echo " $_domain" done else echo -e " *** \033[33mNo Domain is marked for deletion\033[m ***" fi # ----- # - Warn about Domains, which will not be marked for deletion. # ----- CUR_IFS=$IFS IFS='' msg="" declare -i _counter=1 if [[ ${#msg_exclude_domain_from_del_arr[@]} -gt 0 ]] ; then for _msg in ${msg_exclude_domain_from_del_arr[@]} ; do if [[ $_counter -eq 1 ]]; then msg="$_msg" else msg="$msg\n\n $_msg" fi _counter=$((_counter+1)) done warn "$msg" fi IFS=$CUR_IFS rm -f $log_file echo "" clean_up