mirror of
https://github.com/pi-hole/pi-hole
synced 2024-12-22 14:58:08 +00:00
Fix issue with missing newline at the end of adlists (#3144)
* Also display non-fatal warnings during the database importing. Previously, we have only show warnings when there were also errors (errors are always fatal). Signed-off-by: DL6ER <dl6er@dl6er.de> * Ensure there is always a newline on the last line. Signed-off-by: DL6ER <dl6er@dl6er.de> * Stickler linting Signed-off-by: Dan Schaper <dan.schaper@pi-hole.net> * Move sed command into subroutine to avoid code duplication. Signed-off-by: DL6ER <dl6er@dl6er.de> * Also unify comments. Signed-off-by: DL6ER <dl6er@dl6er.de> * Also unify comments. Signed-off-by: DL6ER <dl6er@dl6er.de> Co-authored-by: Dan Schaper <dan@glacialmagma.com>
This commit is contained in:
parent
85c15a7167
commit
839fe32042
22
gravity.sh
22
gravity.sh
@ -390,12 +390,23 @@ gravity_DownloadBlocklists() {
|
||||
echo -e "${OVER} ${TICK} ${str}"
|
||||
fi
|
||||
|
||||
if [[ "${status}" -eq 0 && -n "${output}" ]]; then
|
||||
echo -e " Encountered non-critical SQL warnings. Please check the suitability of the list you're using!\\nSQL warnings:\\n${output}\\n"
|
||||
fi
|
||||
|
||||
rm "${target}" > /dev/null 2>&1 || \
|
||||
echo -e " ${CROSS} Unable to remove ${target}"
|
||||
|
||||
gravity_Blackbody=true
|
||||
}
|
||||
|
||||
parseList() {
|
||||
local adlistID="${1}" src="${2}" target="${3}"
|
||||
#Append ,${arg} to every line and then remove blank lines before import
|
||||
# /.$/a\\ ensures there is a newline on the last line
|
||||
sed -e "s/$/,${adlistID}/;/^$/d;/.$/a\\" "${src}" >> "${target}"
|
||||
}
|
||||
|
||||
# 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}"
|
||||
@ -481,14 +492,13 @@ gravity_DownloadBlocklistFromUrl() {
|
||||
if [[ "${success}" == true ]]; then
|
||||
if [[ "${httpCode}" == "304" ]]; then
|
||||
# Add domains to database table file
|
||||
#Append ,${arg} to every line and then remove blank lines before import
|
||||
sed -e "s/$/,${adlistID}/;/^$/d" "${saveLocation}" >> "${target}"
|
||||
parseList "${adlistID}" "${saveLocation}" "${target}"
|
||||
# Check if $patternbuffer is a non-zero length file
|
||||
elif [[ -s "${patternBuffer}" ]]; then
|
||||
# Determine if blocklist is non-standard and parse as appropriate
|
||||
gravity_ParseFileIntoDomains "${patternBuffer}" "${saveLocation}"
|
||||
#Append ,${arg} to every line and then remove blank lines before import
|
||||
sed -e "s/$/,${adlistID}/;/^$/d" "${saveLocation}" >> "${target}"
|
||||
# Add domains to database table file
|
||||
parseList "${adlistID}" "${saveLocation}" "${target}"
|
||||
else
|
||||
# Fall back to previously cached list if $patternBuffer is empty
|
||||
echo -e " ${INFO} Received empty file: ${COL_LIGHT_GREEN}using previously cached list${COL_NC}"
|
||||
@ -497,8 +507,8 @@ gravity_DownloadBlocklistFromUrl() {
|
||||
# Determine if cached list has read permission
|
||||
if [[ -r "${saveLocation}" ]]; then
|
||||
echo -e " ${CROSS} List download failed: ${COL_LIGHT_GREEN}using previously cached list${COL_NC}"
|
||||
#Append ,${arg} to every line and then remove blank lines before import
|
||||
sed -e "s/$/,${adlistID}/;/^$/d" "${saveLocation}" >> "${target}"
|
||||
# Add domains to database table file
|
||||
parseList "${adlistID}" "${saveLocation}" "${target}"
|
||||
else
|
||||
echo -e " ${CROSS} List download failed: ${COL_LIGHT_RED}no cached list available${COL_NC}"
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user