mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-25 06:10:20 +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
1 changed files with 16 additions and 6 deletions
22
gravity.sh
22
gravity.sh
|
@ -390,12 +390,23 @@ gravity_DownloadBlocklists() {
|
||||||
echo -e "${OVER} ${TICK} ${str}"
|
echo -e "${OVER} ${TICK} ${str}"
|
||||||
fi
|
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 || \
|
rm "${target}" > /dev/null 2>&1 || \
|
||||||
echo -e " ${CROSS} Unable to remove ${target}"
|
echo -e " ${CROSS} Unable to remove ${target}"
|
||||||
|
|
||||||
gravity_Blackbody=true
|
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
|
# Download specified URL and perform checks on HTTP status and file content
|
||||||
gravity_DownloadBlocklistFromUrl() {
|
gravity_DownloadBlocklistFromUrl() {
|
||||||
local url="${1}" cmd_ext="${2}" agent="${3}" adlistID="${4}" saveLocation="${5}" target="${6}"
|
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 [[ "${success}" == true ]]; then
|
||||||
if [[ "${httpCode}" == "304" ]]; then
|
if [[ "${httpCode}" == "304" ]]; then
|
||||||
# Add domains to database table file
|
# Add domains to database table file
|
||||||
#Append ,${arg} to every line and then remove blank lines before import
|
parseList "${adlistID}" "${saveLocation}" "${target}"
|
||||||
sed -e "s/$/,${adlistID}/;/^$/d" "${saveLocation}" >> "${target}"
|
|
||||||
# Check if $patternbuffer is a non-zero length file
|
# Check if $patternbuffer is a non-zero length file
|
||||||
elif [[ -s "${patternBuffer}" ]]; then
|
elif [[ -s "${patternBuffer}" ]]; then
|
||||||
# Determine if blocklist is non-standard and parse as appropriate
|
# Determine if blocklist is non-standard and parse as appropriate
|
||||||
gravity_ParseFileIntoDomains "${patternBuffer}" "${saveLocation}"
|
gravity_ParseFileIntoDomains "${patternBuffer}" "${saveLocation}"
|
||||||
#Append ,${arg} to every line and then remove blank lines before import
|
# Add domains to database table file
|
||||||
sed -e "s/$/,${adlistID}/;/^$/d" "${saveLocation}" >> "${target}"
|
parseList "${adlistID}" "${saveLocation}" "${target}"
|
||||||
else
|
else
|
||||||
# Fall back to previously cached list if $patternBuffer is empty
|
# 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}"
|
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
|
# Determine if cached list has read permission
|
||||||
if [[ -r "${saveLocation}" ]]; then
|
if [[ -r "${saveLocation}" ]]; then
|
||||||
echo -e " ${CROSS} List download failed: ${COL_LIGHT_GREEN}using previously cached list${COL_NC}"
|
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
|
# Add domains to database table file
|
||||||
sed -e "s/$/,${adlistID}/;/^$/d" "${saveLocation}" >> "${target}"
|
parseList "${adlistID}" "${saveLocation}" "${target}"
|
||||||
else
|
else
|
||||||
echo -e " ${CROSS} List download failed: ${COL_LIGHT_RED}no cached list available${COL_NC}"
|
echo -e " ${CROSS} List download failed: ${COL_LIGHT_RED}no cached list available${COL_NC}"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue