1
0
mirror of https://github.com/pi-hole/pi-hole synced 2025-02-12 08:02:36 +00:00

Fix empty adlists (#5821)

This commit is contained in:
Dominik 2024-11-26 20:09:41 +01:00 committed by GitHub
commit 7d727555e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -358,7 +358,7 @@ gravity_DownloadBlocklists() {
unset sources unset sources
fi fi
local url domain str target compression adlist_type local url domain str target compression adlist_type directory
echo "" echo ""
# Prepare new gravity database # Prepare new gravity database
@ -423,19 +423,24 @@ gravity_DownloadBlocklists() {
saveLocation="${piholeDir}/list.${id}.${domain}.${domainsExtension}" saveLocation="${piholeDir}/list.${id}.${domain}.${domainsExtension}"
activeDomains[$i]="${saveLocation}" activeDomains[$i]="${saveLocation}"
# Check if we can write to the save location file # Check if we can write to the save location file without actually creating
if ! touch "${saveLocation}" 2>/dev/null; then # it (in case it doesn't exist)
# First, check if the directory is writable
directory="$(dirname -- "${saveLocation}")"
if [ ! -w "${directory}" ]; then
echo -e " ${CROSS} Unable to write to ${directory}"
echo " Please run pihole -g as root"
echo ""
continue
fi
# Then, check if the file is writable (if it exists)
if [ -e "${saveLocation}" ] && [ ! -w "${saveLocation}" ]; then
echo -e " ${CROSS} Unable to write to ${saveLocation}" echo -e " ${CROSS} Unable to write to ${saveLocation}"
echo " Please run pihole -g as root" echo " Please run pihole -g as root"
echo "" echo ""
continue continue
fi fi
# Chown the file to the pihole user
# This is necessary for the FTL to be able to update the file
# when gravity is run from the web interface
fix_owner_permissions "${saveLocation}"
echo -e " ${INFO} Target: ${url}" echo -e " ${INFO} Target: ${url}"
local regex check_url local regex check_url
# Check for characters NOT allowed in URLs # Check for characters NOT allowed in URLs
@ -464,6 +469,7 @@ compareLists() {
if ! sha1sum --check --status --strict "${target}.sha1"; then if ! sha1sum --check --status --strict "${target}.sha1"; then
# The list changed upstream, we need to update the checksum # The list changed upstream, we need to update the checksum
sha1sum "${target}" >"${target}.sha1" sha1sum "${target}" >"${target}.sha1"
fix_owner_permissions "${target}.sha1"
echo " ${INFO} List has been updated" echo " ${INFO} List has been updated"
database_adlist_status "${adlistID}" "1" database_adlist_status "${adlistID}" "1"
else else
@ -473,6 +479,7 @@ compareLists() {
else else
# No checksum available, create one for comparing on the next run # No checksum available, create one for comparing on the next run
sha1sum "${target}" >"${target}.sha1" sha1sum "${target}" >"${target}.sha1"
fix_owner_permissions "${target}.sha1"
# We assume here it was changed upstream # We assume here it was changed upstream
database_adlist_status "${adlistID}" "1" database_adlist_status "${adlistID}" "1"
fi fi
@ -734,7 +741,7 @@ gravity_ParseFileIntoDomains() {
-e 's/^.*\s+//g' \ -e 's/^.*\s+//g' \
-e '/^$/d' "${destination}" -e '/^$/d' "${destination}"
chmod 644 "${destination}" fix_owner_permissions "${destination}"
} }
# Report number of entries in a table # Report number of entries in a table