Update gravity.sh

fix the `if statement` that doesn't seem to work for neither of alpine's ash / bash - applying some workaround with the `stat` command

Signed-off-by: Karol Kania <44871508+karolkania@users.noreply.github.com>
This commit is contained in:
Karol Kania 2025-02-28 12:52:07 +01:00 committed by GitHub
parent 567bb724b1
commit a9650ae287
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -541,14 +541,18 @@ gravity_DownloadBlocklists() {
# it (in case it doesn't exist)
# First, check if the directory is writable
directory="$(dirname -- "${saveLocation}")"
if [ ! -w "${directory}" ]; then
directory_permissions=$(stat -c %a ${directory})
# echo "directory_permissions: ${directory_permissions}"
if [ $directory_permissions -lt 700 ]; 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
saveLocation_permissions=$(stat -c %a ${saveLocation})
# echo "saveLocation_permissions: ${saveLocation_permissions}"
if [ -e "${saveLocation}" ] && [ ${saveLocation_permissions} -lt 600 ]; then
echo -e " ${CROSS} Unable to write to ${saveLocation}"
echo " Please run pihole -g as root"
echo ""