Dont use bash keywords/programs as variable names

This commit is contained in:
Adam Warner 2022-08-01 18:38:15 +01:00
parent aa0a9e2976
commit 6c7a28a7b5
No known key found for this signature in database
GPG key ID: 872950F3ECF2B173

View file

@ -139,9 +139,9 @@ update_gravity_timestamp() {
# Import domains from file and store them in the specified database table # Import domains from file and store them in the specified database table
database_table_from_file() { database_table_from_file() {
# Define locals # Define locals
local table source backup_path backup_file tmpFile type local table src backup_path backup_file tmpFile list_type
table="${1}" table="${1}"
source="${2}" src="${2}"
backup_path="${piholeDir}/migration_backup" backup_path="${piholeDir}/migration_backup"
backup_file="${backup_path}/$(basename "${2}")" backup_file="${backup_path}/$(basename "${2}")"
tmpFile="$(mktemp -p "/tmp" --suffix=".gravity")" tmpFile="$(mktemp -p "/tmp" --suffix=".gravity")"
@ -155,13 +155,13 @@ database_table_from_file() {
# Special handling for domains to be imported into the common domainlist table # Special handling for domains to be imported into the common domainlist table
if [[ "${table}" == "whitelist" ]]; then if [[ "${table}" == "whitelist" ]]; then
type="0" list_type="0"
table="domainlist" table="domainlist"
elif [[ "${table}" == "blacklist" ]]; then elif [[ "${table}" == "blacklist" ]]; then
type="1" list_type="1"
table="domainlist" table="domainlist"
elif [[ "${table}" == "regex" ]]; then elif [[ "${table}" == "regex" ]]; then
type="3" list_type="3"
table="domainlist" table="domainlist"
fi fi
@ -174,9 +174,9 @@ database_table_from_file() {
rowid+=1 rowid+=1
fi fi
# Loop over all domains in ${source} file # Loop over all domains in ${src} file
# Read file line by line # Read file line by line
grep -v '^ *#' < "${source}" | while IFS= read -r domain grep -v '^ *#' < "${src}" | while IFS= read -r domain
do do
# Only add non-empty lines # Only add non-empty lines
if [[ -n "${domain}" ]]; then if [[ -n "${domain}" ]]; then
@ -185,10 +185,10 @@ database_table_from_file() {
echo "${rowid},\"${domain}\",${timestamp}" >> "${tmpFile}" echo "${rowid},\"${domain}\",${timestamp}" >> "${tmpFile}"
elif [[ "${table}" == "adlist" ]]; then elif [[ "${table}" == "adlist" ]]; then
# Adlist table format # Adlist table format
echo "${rowid},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${source}\",,0,0,0" >> "${tmpFile}" echo "${rowid},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${src}\",,0,0,0" >> "${tmpFile}"
else else
# White-, black-, and regexlist table format # White-, black-, and regexlist table format
echo "${rowid},${type},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${source}\"" >> "${tmpFile}" echo "${rowid},${list_type},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${src}\"" >> "${tmpFile}"
fi fi
rowid+=1 rowid+=1
fi fi
@ -201,14 +201,14 @@ database_table_from_file() {
status="$?" status="$?"
if [[ "${status}" -ne 0 ]]; then if [[ "${status}" -ne 0 ]]; then
echo -e "\\n ${CROSS} Unable to fill table ${table}${type} in database ${gravityDBfile}\\n ${output}" echo -e "\\n ${CROSS} Unable to fill table ${table}${list_type} in database ${gravityDBfile}\\n ${output}"
gravity_Cleanup "error" gravity_Cleanup "error"
fi fi
# Move source file to backup directory, create directory if not existing # Move source file to backup directory, create directory if not existing
mkdir -p "${backup_path}" mkdir -p "${backup_path}"
mv "${source}" "${backup_file}" 2> /dev/null || \ mv "${src}" "${backup_file}" 2> /dev/null || \
echo -e " ${CROSS} Unable to backup ${source} to ${backup_path}" echo -e " ${CROSS} Unable to backup ${src} to ${backup_path}"
# Delete tmpFile # Delete tmpFile
rm "${tmpFile}" > /dev/null 2>&1 || \ rm "${tmpFile}" > /dev/null 2>&1 || \