- Fix error on deleting user from table mysql.user.

- Remove unused (commented) code.
This commit is contained in:
Christoph 2017-08-13 19:22:29 +02:00
parent 2e3a89908a
commit a185a2d96f

View File

@ -479,7 +479,6 @@ fi
# -----
# - Gathering global settings
# -----
@ -499,22 +498,6 @@ if $(httpd -M | grep -q -E "php[5-9]?_module" 2>/dev/null) ; then
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
@ -1147,30 +1130,6 @@ for _doc_root in ${docroot_req_for_del_arr[@]} ; do
fi
done
#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
# -
@ -1662,27 +1621,6 @@ if [[ ${#docroot_marked_for_del_arr[@]} -gt 0 ]]; then
for _doc_root in ${docroot_marked_for_del_arr[@]} ; do
_dir_to_remove="$(dirname $_doc_root)"
# if [[ -h "$_dir_to_remove" ]]; then
#
# _symlink="$_dir_to_remove"
# _dir_to_remove="$(realpath $_dir_to_remove)"
#
# echo "" >> $main_log
# echo "# - Delete Symlink '${_symlink}'" >> $main_log
# echo "# -" >> $main_log
# echo "rm \"${_symlink}\"" >> $main_log
#
# echononl " Delete Symlink '${_symlink}'"
# rm "${_symlink}" > $tmp_log_file 2>&1
# if [[ $? -eq 0 ]]; then
# echo_ok
# else
# echo_failed
# error "$(cat $tmp_log_file)"
# echo "Error: $(cat $tmp_log_file)" >> $main_log
# fi
#
# fi
if [[ -e "${_delete_dir}/$(basename $_dir_to_remove)" ]] ; then
echo "" >> $main_log
@ -1714,29 +1652,6 @@ if [[ ${#docroot_marked_for_del_arr[@]} -gt 0 ]]; then
echo "Error: $(cat $tmp_log_file)" >> $main_log
fi
# if $(grep -q "$_dir_to_remove" $(apachectl configtest) 2> /dev/null) ; then
#
# error "Directory \033[1m$_dir_to_remove\033[m is used by another Website. So, moving
# directory \033[1m$(basename $_dir_to_remove)\033[m back to \033[1m$(dirname $_dir_to_remove)\033[m."
#
# echo "" >> $main_log
# echo "Error: Directory '$_dir_to_remove' is used by another Website." >> $main_log
#
# echo "" >> $main_log
# echo "# - Moving directory '$(basename $_dir_to_remove)' back to '$(dirname $_dir_to_remove)'" >> $main_log
# echo "# -" >> $main_log
# echo "mv \"${_delete_dir}/$(basename $_dir_to_remove)\" \"$(dirname $_dir_to_remove)\"" >> $main_log
# echononl " Moving directory \033[1m$(basename $_dir_to_remove)\033[m back."
# mv "${_delete_dir}/$(basename $_dir_to_remove)" "$(dirname $_dir_to_remove)" > $tmp_log_file 2>&1
# if [[ $? -eq 0 ]]; then
# echo_ok
# else
# echo_failed
# error "$(cat $tmp_log_file)"
# echo "Error: $(cat $tmp_log_file)" >> $main_log
# fi
#
# fi
done
fi
else
@ -1865,20 +1780,16 @@ if [[ ${#database_marked_for_del_arr[@]} -gt 0 ]]; then
# - - user's name is the same as the database name
# - - user does not appear in table mysql.db
# -
_count_user_tbl_user=$(mysql $MYSQL_CREDENTIAL_ARGS -N -s -A -e "USE mysql; SELECT count(User) from user WHERE User = '${_val_arr[0]}'" )
echononl " Drop User '${_val_arr[0]}' from table 'mysql.user'"
_count_user_tbl_db=$(mysql $MYSQL_CREDENTIAL_ARGS -N -s -A -e "USE mysql; SELECT count(User) from db WHERE User = '${_val_arr[0]}'" )
if [[ $? -eq 0 ]] && [[ $_count_user_tbl_user -eq 1 ]]; then
echononl " Drop User '${_val_arr[0]}' from table 'mysql.user'"
_count_user_tbl_db=$(mysql $MYSQL_CREDENTIAL_ARGS -N -s -A -e "USE mysql; SELECT count(User) from db WHERE User = '${_val_arr[0]}'")
if [[ $? -eq 0 ]] && [[ $_count_user_tbl_db -eq 0 ]]; then
if [[ $? -eq 0 ]] && [[ $_count_user_tbl_db -eq 0 ]]; then
echo "" >> $main_log
echo "# - Drop User '${_val_arr[0]}' from table 'mysql.user'" >> $main_log
echo "# -" >> $main_log
echo "mysql $MYSQL_CREDENTIAL_ARGS -N -s -A -e \"USE mysql; DELETE FROM user WHERE User = '${_val_arr[0]}'\"" >> $main_log
echononl " Drop User '${_val_arr[0]}' from table 'mysql.user'"
mysql $MYSQL_CREDENTIAL_ARGS -N -s -A -e "USE mysql; DELETE FROM user WHERE User = '${_val_arr[0]}'" > $tmp_log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
@ -1888,10 +1799,9 @@ if [[ ${#database_marked_for_del_arr[@]} -gt 0 ]]; then
echo "Error: $(cat $tmp_log_file)" >> $main_log
fi
else
echo_skipped
else
fi # if [[ $? -eq 0 ]] && [[ $_count_user_tbl_db -eq 0 ]]
echo_skipped
fi # if [[ $? -eq 0 ]] && [[ $_count_user_tbl_user -eq 1 ]]; then