From 621e9ebb2fec9bd3155277be86de5ef7bf92d833 Mon Sep 17 00:00:00 2001 From: Justin Reichardt Date: Tue, 3 Aug 2021 15:06:17 -0500 Subject: [PATCH] Retain adlistings if nothing new is pulled This way if either you have no internet or all of your listing no longer exist you will not lose everything --- src/removeadhosts.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/removeadhosts.sh b/src/removeadhosts.sh index 8df9231..7e82314 100755 --- a/src/removeadhosts.sh +++ b/src/removeadhosts.sh @@ -1,7 +1,8 @@ #!/bin/bash -sed -n '1,/# start of removeadhosts/p' /etc/hosts > /tmp/removeadhosts -cat /tmp/removeadhosts | tee /etc/hosts >/dev/null -rm /tmp/removeadhosts +sed -n '1,/# start of removeadhosts/p' /etc/hosts > /tmp/removeadhosts-head +sed -n '/# start of removeadhosts/,/# Custom ad list/p' /etc/hosts | sed -e '/# Custom ad list/d' -e '1d' > /tmp/removeadhosts-curl +cat /tmp/removeadhosts-head | tee /etc/hosts >/dev/null +rm /tmp/removeadhosts-head echo "Appended old hosts" if grep -qinE '# start of removeadhosts' /etc/hosts then @@ -12,7 +13,6 @@ else fi echo 'Downloading ad list' - if [ -e /etc/removeadhosts/adlistings.txt ] then cat /etc/removeadhosts/adlistings.txt | \ @@ -22,6 +22,13 @@ then done fi +if [ $(sed -n '/# start of removeadhosts/,/# Custom ad list/p' /etc/hosts | sed -e '/# Custom ad list/d' -e '1d' | wc -l) -lt 2 ] +then + echo "No hosts were downloaded, reusing the old ones" + cat /tmp/removeadhosts-curl | tee -a /etc/hosts >/dev/null +fi +rm /tmp/removeadhosts-curl + echo 'Adding custom items from /etc/removeadhosts' if [ -e /etc/removeadhosts/adlist.txt ] then