Simplify code

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2019-05-04 13:15:30 +02:00
parent 3aa838bbe4
commit 6ba58896d2
No known key found for this signature in database
GPG key ID: 00135ACBD90B28DD

View file

@ -103,7 +103,7 @@ if [[ -n "${str:-}" ]]; then
fi fi
scanDatabaseTable() { scanDatabaseTable() {
local domain table type querystr result local domain table type querystr result table_prev
domain="${1}" domain="${1}"
table="${2}" table="${2}"
type="${3:-}" type="${3:-}"
@ -119,35 +119,29 @@ scanDatabaseTable() {
# Send prepared query to gravity database # Send prepared query to gravity database
result="$(sqlite3 "${gravityDBfile}" "${querystr}")" 2> /dev/null result="$(sqlite3 "${gravityDBfile}" "${querystr}")" 2> /dev/null
if [[ -n "${result}" ]]; then if [[ -z "${result}" ]]; then
# Prepend listname (separated by a colon) if we found at least one result # Return early when we have no results
# and output result
results="$(sed "s/^/${table}:/g;" <<< "${result}")"
else
# Output empty string as the database query didn't return any result
return return
fi fi
mapfile -t results <<< "${results}"
if [[ -n "${results[*]}" ]]; then
wbMatch=true wbMatch=true
# Loop through each result in order to print unique file title once mapfile -t results <<< "${result}"
# Loop through each result
for result in "${results[@]}"; do for result in "${results[@]}"; do
fileName="${result%%:*}"
if [[ -n "${blockpage}" ]]; then if [[ -n "${blockpage}" ]]; then
echo "π ${result}" echo "π ${result}"
exit 0 exit 0
elif [[ -n "${exact}" ]]; then elif [[ -n "${exact}" ]]; then
echo " ${matchType^} found in ${COL_BOLD}${fileName^}${COL_NC}" echo " ${matchType^} found in ${COL_BOLD}${table^}${COL_NC}"
else else
# Only print filename title once per file # Only print table name once
if [[ ! "${fileName}" == "${fileName_prev:-}" ]]; then if [[ ! "${table}" == "${table_prev:-}" ]]; then
echo " ${matchType^} found in ${COL_BOLD}${fileName^}${COL_NC}" echo " ${matchType^} found in ${COL_BOLD}${table^}${COL_NC}"
fileName_prev="${fileName}" table_prev="${table}"
fi fi
echo " ${result#*:}" echo " ${result}"
fi fi
done done
fi
} }
# Scan Whitelist and Blacklist # Scan Whitelist and Blacklist