Merge pull request #3646 from yubiuser/tweak/compression
Check for compression only once and print result
This commit is contained in:
commit
4bef49e2eb
27
gravity.sh
27
gravity.sh
|
@ -336,7 +336,7 @@ gravity_DownloadBlocklists() {
|
|||
return 1
|
||||
fi
|
||||
|
||||
local url domain agent cmd_ext str target
|
||||
local url domain agent cmd_ext str target compression
|
||||
echo ""
|
||||
|
||||
# Prepare new gravity database
|
||||
|
@ -355,6 +355,16 @@ gravity_DownloadBlocklists() {
|
|||
|
||||
target="$(mktemp -p "/tmp" --suffix=".gravity")"
|
||||
|
||||
# Use compression to reduce the amount of data that is transfered
|
||||
# between the Pi-hole and the ad list provider. Use this feature
|
||||
# only if it is supported by the locally available version of curl
|
||||
if curl -V | grep -q "Features:.* libz"; then
|
||||
compression="--compressed"
|
||||
echo -e " ${INFO} Using libz compression\n"
|
||||
else
|
||||
compression=""
|
||||
echo -e " ${INFO} Libz compression not available\n"
|
||||
fi
|
||||
# Loop through $sources and download each one
|
||||
for ((i = 0; i < "${#sources[@]}"; i++)); do
|
||||
url="${sources[$i]}"
|
||||
|
@ -381,7 +391,7 @@ gravity_DownloadBlocklists() {
|
|||
if [[ "${url}" =~ ${regex} ]]; then
|
||||
echo -e " ${CROSS} Invalid Target"
|
||||
else
|
||||
gravity_DownloadBlocklistFromUrl "${url}" "${cmd_ext}" "${agent}" "${sourceIDs[$i]}" "${saveLocation}" "${target}"
|
||||
gravity_DownloadBlocklistFromUrl "${url}" "${cmd_ext}" "${agent}" "${sourceIDs[$i]}" "${saveLocation}" "${target}" "${compression}"
|
||||
fi
|
||||
echo ""
|
||||
done
|
||||
|
@ -456,8 +466,8 @@ parseList() {
|
|||
|
||||
# Download specified URL and perform checks on HTTP status and file content
|
||||
gravity_DownloadBlocklistFromUrl() {
|
||||
local url="${1}" cmd_ext="${2}" agent="${3}" adlistID="${4}" saveLocation="${5}" target="${6}"
|
||||
local heisenbergCompensator="" patternBuffer str httpCode success="" compression
|
||||
local url="${1}" cmd_ext="${2}" agent="${3}" adlistID="${4}" saveLocation="${5}" target="${6}" compression="${7}"
|
||||
local heisenbergCompensator="" patternBuffer str httpCode success=""
|
||||
|
||||
# Create temp file to store content on disk instead of RAM
|
||||
patternBuffer=$(mktemp -p "/tmp" --suffix=".phgpb")
|
||||
|
@ -506,15 +516,6 @@ gravity_DownloadBlocklistFromUrl() {
|
|||
cmd_ext="--resolve $domain:$port:$ip $cmd_ext"
|
||||
fi
|
||||
|
||||
# Use compression to reduce the amount of data that is transfered
|
||||
# between the Pi-hole and the ad list provider. Use this feature
|
||||
# only if it is supported by the locally available version of curl
|
||||
if curl -V | grep -q "Features:.* libz"; then
|
||||
compression="--compressed"
|
||||
else
|
||||
compression=""
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
httpCode=$(curl -s -L ${compression} ${cmd_ext} ${heisenbergCompensator} -w "%{http_code}" -A "${agent}" "${url}" -o "${patternBuffer}" 2> /dev/null)
|
||||
|
||||
|
|
Loading…
Reference in New Issue