Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/pi-hole/pi-hole.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDL6ER <dl6er@dl6er.de>2022-01-30 12:36:20 +0300
committerDL6ER <dl6er@dl6er.de>2022-01-30 12:36:20 +0300
commit534f9a63bf0db0493d929d3737f48712ef99a495 (patch)
treecadac0bbb8c71abdc76806c2bf988b29b99e6518 /gravity.sh
parentf0f5cc52d9bd7bb542a9735bdcb489152da05826 (diff)
Copy database tables earlier into the new gravity database to avoid foreign key contraint violations when adding gravity entries refering to an empty adlist table
Signed-off-by: DL6ER <dl6er@dl6er.de>
Diffstat (limited to 'gravity.sh')
-rwxr-xr-xgravity.sh47
1 files changed, 28 insertions, 19 deletions
diff --git a/gravity.sh b/gravity.sh
index ad0ba9a0..ac2fca1b 100755
--- a/gravity.sh
+++ b/gravity.sh
@@ -85,7 +85,7 @@ generate_gravity_database() {
# Copy data from old to new database file and swap them
gravity_swap_databases() {
- local str copyGravity
+ local str copyGravity oldAvail
str="Building tree"
echo -ne " ${INFO} ${str}..."
@@ -102,22 +102,6 @@ gravity_swap_databases() {
str="Swapping databases"
echo -ne " ${INFO} ${str}..."
- # Gravity copying SQL script
- copyGravity="$(cat "${gravityDBcopy}")"
- if [[ "${gravityDBfile}" != "${gravityDBfile_default}" ]]; then
- # Replace default gravity script location by custom location
- copyGravity="${copyGravity//"${gravityDBfile_default}"/"${gravityDBfile}"}"
- fi
-
- output=$( { sqlite3 "${gravityTEMPfile}" <<< "${copyGravity}"; } 2>&1 )
- status="$?"
-
- if [[ "${status}" -ne 0 ]]; then
- echo -e "\\n ${CROSS} Unable to copy data from ${gravityDBfile} to ${gravityTEMPfile}\\n ${output}"
- return 1
- fi
- echo -e "${OVER} ${TICK} ${str}"
-
# Swap databases and remove or conditionally rename old database
# Number of available blocks on disk
availableBlocks=$(stat -f --format "%a" "${gravityDIR}")
@@ -125,13 +109,19 @@ gravity_swap_databases() {
gravityBlocks=$(stat --format "%b" ${gravityDBfile})
# Only keep the old database if available disk space is at least twice the size of the existing gravity.db.
# Better be safe than sorry...
+ oldAvail=false
if [ "${availableBlocks}" -gt "$((gravityBlocks * 2))" ] && [ -f "${gravityDBfile}" ]; then
- echo -e " ${TICK} The old database remains available."
+ oldAvail=true
mv "${gravityDBfile}" "${gravityOLDfile}"
else
rm "${gravityDBfile}"
fi
mv "${gravityTEMPfile}" "${gravityDBfile}"
+ echo -e "${OVER} ${TICK} ${str}"
+
+ if [ oldAvail ]; then
+ echo -e " ${TICK} The old database remains available."
+ fi
}
# Update timestamp when the gravity table was last updated successfully
@@ -475,9 +465,28 @@ gravity_DownloadBlocklists() {
echo ""
done
+ str="Creating new gravity databases"
+ echo -ne " ${INFO} ${str}..."
+
+ # Gravity copying SQL script
+ copyGravity="$(cat "${gravityDBcopy}")"
+ if [[ "${gravityDBfile}" != "${gravityDBfile_default}" ]]; then
+ # Replace default gravity script location by custom location
+ copyGravity="${copyGravity//"${gravityDBfile_default}"/"${gravityDBfile}"}"
+ fi
+
+ output=$( { pihole-FTL sqlite3 "${gravityTEMPfile}" <<< "${copyGravity}"; } 2>&1 )
+ status="$?"
+
+ if [[ "${status}" -ne 0 ]]; then
+ echo -e "\\n ${CROSS} Unable to copy data from ${gravityDBfile} to ${gravityTEMPfile}\\n ${output}"
+ return 1
+ fi
+ echo -e "${OVER} ${TICK} ${str}"
+
str="Storing downloaded domains in new gravity database"
echo -ne " ${INFO} ${str}..."
- output=$( { printf ".timeout 30000\\n.mode csv\\n.import \"%s\" gravity\\n" "${target}" | sqlite3 "${gravityTEMPfile}"; } 2>&1 )
+ output=$( { printf ".timeout 30000\\n.mode csv\\n.import \"%s\" gravity\\n" "${target}" | pihole-FTL sqlite3 "${gravityTEMPfile}"; } 2>&1 )
status="$?"
if [[ "${status}" -ne 0 ]]; then