handle_domain_on_webserver.sh: support multiple vhost directories.
This commit is contained in:
parent
485d47158d
commit
b1e360c93d
@ -330,6 +330,8 @@ else
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
index_subdir_apache_vhost_dir="$(expr ${#apache_vhost_dir} + 1)"
|
||||||
|
|
||||||
if [[ "$(basename $apache_vhost_dir)" = 'sites-enabled' ]]; then
|
if [[ "$(basename $apache_vhost_dir)" = 'sites-enabled' ]]; then
|
||||||
apache_vhost_base_dir="$(dirname $apache_vhost_dir)/sites-available"
|
apache_vhost_base_dir="$(dirname $apache_vhost_dir)/sites-available"
|
||||||
elif [[ "$(basename $apache_vhost_dir)" =~ vhost ]]; then
|
elif [[ "$(basename $apache_vhost_dir)" =~ vhost ]]; then
|
||||||
@ -338,6 +340,61 @@ elif [[ "$(basename $(dirname $apache_vhost_dir))" =~ vhost ]]; then
|
|||||||
apache_vhost_base_dir="$(dirname $apache_vhost_dir)"
|
apache_vhost_base_dir="$(dirname $apache_vhost_dir)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
declare -i _num=1
|
||||||
|
while IFS='' read -r -d '' fq_name ; do
|
||||||
|
dirname="$(basename "$fq_name")"
|
||||||
|
[[ "$dirname" = "DELETED" ]] && continue
|
||||||
|
[[ "$dirname" = "BAK" ]] && continue
|
||||||
|
[[ "$dirname" =~ ^Moved ]] && continue
|
||||||
|
if [[ $_num -eq 1 ]]; then
|
||||||
|
_apache_additional_vhost_dirs="$(basename "$dirname")"
|
||||||
|
else
|
||||||
|
_apache_additional_vhost_dirs="$_apache_additional_vhost_dirs $(basename "$dirname")"
|
||||||
|
fi
|
||||||
|
((_num++))
|
||||||
|
done < <(find $apache_vhost_dir -mindepth 1 -maxdepth 1 -type d -print0)
|
||||||
|
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[32m--\033[m"
|
||||||
|
echo ""
|
||||||
|
echo "If there are additional apache vhost directories, enter them here .."
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[33m\033[1mNotice\033[m:"
|
||||||
|
echo -e " only first level subdiirectories of \033[1m$apache_vhost_dir\033[m"
|
||||||
|
echo -e " are posible values."
|
||||||
|
echo ""
|
||||||
|
echo "Blank seperated list of directories"
|
||||||
|
echo ""
|
||||||
|
apache_additional_vhost_dirs=
|
||||||
|
if [ -z "$_apache_additional_vhost_dirs" ]; then
|
||||||
|
echononl "Apache VHost directory: "
|
||||||
|
read apache_additional_vhost_dirs
|
||||||
|
while [[ "X$apache_additional_vhost_dirs" = "X" ]] ; do
|
||||||
|
echo -e "\n\t\033[33m\033[1mEingabe erforderlich.\033[m\n"
|
||||||
|
echononl "Apache VHost directory: "
|
||||||
|
read apache_additional_vhost_dirs
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echononl "Apache VHost directory [${_apache_additional_vhost_dirs}]: "
|
||||||
|
read apache_additional_vhost_dirs
|
||||||
|
if [[ "X$apache_additional_vhost_dirs" = "X" ]] ; then
|
||||||
|
apache_additional_vhost_dirs="$_apache_additional_vhost_dirs"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
declare -a apache_additional_vhost_dir_arr=()
|
||||||
|
for _dir in $apache_additional_vhost_dirs ; do
|
||||||
|
if [[ -d "${apache_vhost_dir}/$_dir" ]] ; then
|
||||||
|
apache_additional_vhost_dir_arr+=("$_dir")
|
||||||
|
else
|
||||||
|
warn "$_dir is not a subdirectory of ${apache_vhost_dir}.\n\n \033[33m\033[1mIgnoring directory $_dir\033[m.."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "\033[32m--\033[m"
|
echo -e "\033[32m--\033[m"
|
||||||
@ -380,6 +437,14 @@ done
|
|||||||
unset counter
|
unset counter
|
||||||
echo ""
|
echo ""
|
||||||
echo -e " Apache Vhosts Directory................: \033[1m$apache_vhost_dir\033[m"
|
echo -e " Apache Vhosts Directory................: \033[1m$apache_vhost_dir\033[m"
|
||||||
|
if [[ ${#apache_additional_vhost_dir_arr[@]} -gt 0 ]] ; then
|
||||||
|
echo -en " Additional VHost Directories...........:\033[1m"
|
||||||
|
for _dir in ${apache_additional_vhost_dir_arr[@]} ; do
|
||||||
|
echo -n " $_dir"
|
||||||
|
done
|
||||||
|
echo -e "\033[m"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
echo -e " Base Directory Apache Websites.........: \033[1m$apache_web_base_dir\033[m"
|
echo -e " Base Directory Apache Websites.........: \033[1m$apache_web_base_dir\033[m"
|
||||||
|
|
||||||
if $delete_mode ; then
|
if $delete_mode ; then
|
||||||
@ -559,6 +624,19 @@ for domain in "${domain_req_for_del_arr[@]}" ; do
|
|||||||
# -----
|
# -----
|
||||||
|
|
||||||
_vhost_files="$(grep -l -d skip -E "^\s*(ServerName|ServerAlias)\s+.*${domain}" $apache_vhost_dir/* 2> /dev/null)"
|
_vhost_files="$(grep -l -d skip -E "^\s*(ServerName|ServerAlias)\s+.*${domain}" $apache_vhost_dir/* 2> /dev/null)"
|
||||||
|
|
||||||
|
if [[ ${#apache_additional_vhost_dirs[@]} -gt 0 ]] ; then
|
||||||
|
for _dir in ${apache_additional_vhost_dirs[@]} ; do
|
||||||
|
if [[ -z "$_vhost_files" ]]; then
|
||||||
|
_vhost_files="$(grep -l -d skip -E "^\s*(ServerName|ServerAlias)\s+.*${domain}" \
|
||||||
|
${apache_vhost_dir}/${_dir}/* 2> /dev/null)"
|
||||||
|
else
|
||||||
|
_vhost_files="$_vhost_files $(grep -l -d skip -E "^\s*(ServerName|ServerAlias)\s+.*${domain}" \
|
||||||
|
${apache_vhost_dir}/${_dir}/* 2> /dev/null)"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -z "$_vhost_files" ]]; then
|
if [[ -z "$_vhost_files" ]]; then
|
||||||
error "No VHost Configuration found for domain \033[37m\033[1m${domain}\033[m."
|
error "No VHost Configuration found for domain \033[37m\033[1m${domain}\033[m."
|
||||||
|
|
||||||
@ -572,7 +650,8 @@ for domain in "${domain_req_for_del_arr[@]}" ; do
|
|||||||
|
|
||||||
for _vhost_file in $_vhost_files ; do
|
for _vhost_file in $_vhost_files ; do
|
||||||
|
|
||||||
_basename_vhost_file="$(basename $_vhost_file)"
|
#_basename_vhost_file="$(basename $_vhost_file)"
|
||||||
|
_basename_vhost_file="${_vhost_file:$index_subdir_apache_vhost_dir}"
|
||||||
|
|
||||||
containsElement "$_basename_vhost_file" "${vhost_file_arr[@]}" && continue
|
containsElement "$_basename_vhost_file" "${vhost_file_arr[@]}" && continue
|
||||||
vhost_file_arr+=("$_basename_vhost_file")
|
vhost_file_arr+=("$_basename_vhost_file")
|
||||||
@ -1308,9 +1387,7 @@ for _vhost_file in ${vhost_file_req_for_del_arr[@]}; do
|
|||||||
if ! $_found ; then
|
if ! $_found ; then
|
||||||
vhost_file_marked_for_del_arr+=("$_vhost_file")
|
vhost_file_marked_for_del_arr+=("$_vhost_file")
|
||||||
_dehydrated_name="$(grep ServerName $(realpath ${apache_vhost_dir})/$_vhost_file | awk '{print$2}' | sort -u)"
|
_dehydrated_name="$(grep ServerName $(realpath ${apache_vhost_dir})/$_vhost_file | awk '{print$2}' | sort -u)"
|
||||||
echo ""
|
|
||||||
echo "$_vhost_file - $dehydrated_domains_file - $_dehydrated_name"
|
|
||||||
echo ""
|
|
||||||
if [[ -n "$_dehydrated_name" ]] \
|
if [[ -n "$_dehydrated_name" ]] \
|
||||||
&& grep -q -E "^\s*$_dehydrated_name" $dehydrated_domains_file 2> /dev/null ; then
|
&& grep -q -E "^\s*$_dehydrated_name" $dehydrated_domains_file 2> /dev/null ; then
|
||||||
if ! containsElement "$_dehydrated_name" "${dehydrated_name_req_for_del_arr[@]}" ; then
|
if ! containsElement "$_dehydrated_name" "${dehydrated_name_req_for_del_arr[@]}" ; then
|
||||||
@ -1403,6 +1480,14 @@ while IFS='' read -r -d '' filename ; do
|
|||||||
fi
|
fi
|
||||||
done < <(find $apache_vhost_dir -mindepth 1 -maxdepth 1 -type f -print0)
|
done < <(find $apache_vhost_dir -mindepth 1 -maxdepth 1 -type f -print0)
|
||||||
|
|
||||||
|
for _dir in ${apache_additional_vhost_dirs[@]} ; do
|
||||||
|
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}/$_dir -mindepth 1 -maxdepth 1 -type f -print0)
|
||||||
|
done
|
||||||
|
|
||||||
for _vhost_file in ${_all_vhost_files_arr[@]} ; do
|
for _vhost_file in ${_all_vhost_files_arr[@]} ; do
|
||||||
_doc_root="$(grep -E "\s*DocumentRoot\s+" $_vhost_file 2> /dev/null \
|
_doc_root="$(grep -E "\s*DocumentRoot\s+" $_vhost_file 2> /dev/null \
|
||||||
| awk '{print$2}' | sed 's/"//g' | sed 's/\/$//' | sort -u )"
|
| awk '{print$2}' | sed 's/"//g' | sed 's/\/$//' | sort -u )"
|
||||||
@ -1418,12 +1503,24 @@ for _doc_root in ${docroot_req_for_del_arr[@]} ; do
|
|||||||
for _val in ${_all_document_root_dirs_arr[@]} ; do
|
for _val in ${_all_document_root_dirs_arr[@]} ; do
|
||||||
IFS=':' read -a _val_arr <<< "$_val"
|
IFS=':' read -a _val_arr <<< "$_val"
|
||||||
if [[ "${_val_arr[0]}" = "$_realpath_doc_root" ]] ; then
|
if [[ "${_val_arr[0]}" = "$_realpath_doc_root" ]] ; then
|
||||||
if ! containsElement "$(basename ${_val_arr[1]})" "${vhost_file_marked_for_del_arr[@]}" ; then
|
|
||||||
|
__tmp_vhost_file=${_val_arr[1]}
|
||||||
|
__realpath_apache_vhost_dir="$(realpath "$apache_vhost_dir")"
|
||||||
|
__index_subdir_realpath_apache_vhost_dir="$(expr ${#__realpath_apache_vhost_dir} + 1)"
|
||||||
|
__vhost_file="${__tmp_vhost_file:$__index_subdir_realpath_apache_vhost_dir}"
|
||||||
|
|
||||||
|
if ! containsElement "$__vhost_file" "${vhost_file_marked_for_del_arr[@]}" ; then
|
||||||
_not_in_use_by_others=false
|
_not_in_use_by_others=false
|
||||||
|
|
||||||
__msg="The DocumentRoot directory \033[1m${_doc_root}\033[m is also used
|
__msg="The DocumentRoot directory \033[1m${_doc_root}\033[m is also used
|
||||||
by vhost configuration file \033[1m$(basename ${_val_arr[1]})\033[m. But this file
|
by vhost configuration file
|
||||||
isn't marked for deletion. So also the DocumentRoot will not marked for deletion."
|
|
||||||
|
\033[1m$__vhost_file\033[m
|
||||||
|
|
||||||
|
But this file isn't marked for deletion.
|
||||||
|
|
||||||
|
So also the DocumentRoot will not marked for deletion."
|
||||||
|
|
||||||
msg_exclude_doc_root_from_del_arr[${#msg_exclude_doc_root_from_del_arr[@]}]="$__msg"
|
msg_exclude_doc_root_from_del_arr[${#msg_exclude_doc_root_from_del_arr[@]}]="$__msg"
|
||||||
|
|
||||||
break
|
break
|
||||||
@ -1512,8 +1609,14 @@ if [[ ${#database_req_for_del_arr[@]} -gt 0 ]]; then
|
|||||||
_tmp_arr+=("${_val_arr[0]}")
|
_tmp_arr+=("${_val_arr[0]}")
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
__msg="Database \033[1m${_val_arr[0]}\033[m is in use by DocumentRoot directory \033[1m${_val_arr[1]}\033[m,
|
__msg="Database \033[1m${_val_arr[0]}\033[m is in use by DocumentRoot directory
|
||||||
but this directory is NOT marked for deletion. So also the database is not marked for deletion"
|
|
||||||
|
\033[1m${_val_arr[1]}\033[m,
|
||||||
|
|
||||||
|
but this directory is NOT marked for deletion.
|
||||||
|
|
||||||
|
So also the database is not marked for deletion"
|
||||||
|
|
||||||
msg_exclude_db_from_del_arr[${#msg_exclude_db_from_del_arr[@]}]="$__msg"
|
msg_exclude_db_from_del_arr[${#msg_exclude_db_from_del_arr[@]}]="$__msg"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user