From d9288b896ea5bdd6b95d46c77a34746bf7b2cfbc Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 26 Nov 2024 18:01:52 +0100 Subject: [PATCH] Do not touch list files as this creates them. This causes issues down the line in the Heisenberg compensator Signed-off-by: DL6ER --- gravity.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/gravity.sh b/gravity.sh index aebc58cb..6ffac4b0 100755 --- a/gravity.sh +++ b/gravity.sh @@ -358,7 +358,7 @@ gravity_DownloadBlocklists() { unset sources fi - local url domain str target compression adlist_type + local url domain str target compression adlist_type directory echo "" # Prepare new gravity database @@ -423,8 +423,18 @@ gravity_DownloadBlocklists() { saveLocation="${piholeDir}/list.${id}.${domain}.${domainsExtension}" activeDomains[$i]="${saveLocation}" - # Check if we can write to the save location file - if ! touch "${saveLocation}" 2>/dev/null; then + # Check if we can write to the save location file without actually creating + # 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 " Please run pihole -g as root" echo "" @@ -464,6 +474,7 @@ compareLists() { if ! sha1sum --check --status --strict "${target}.sha1"; then # The list changed upstream, we need to update the checksum sha1sum "${target}" >"${target}.sha1" + fix_owner_permissions "${target}.sha1" echo " ${INFO} List has been updated" database_adlist_status "${adlistID}" "1" else @@ -473,6 +484,7 @@ compareLists() { else # No checksum available, create one for comparing on the next run sha1sum "${target}" >"${target}.sha1" + fix_owner_permissions "${target}.sha1" # We assume here it was changed upstream database_adlist_status "${adlistID}" "1" fi