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
stable
Justin Reichardt 2021-08-03 15:06:17 -05:00
parent 76fdf17314
commit 621e9ebb2f
1 changed files with 11 additions and 4 deletions

View File

@ -1,7 +1,8 @@
#!/bin/bash #!/bin/bash
sed -n '1,/# start of removeadhosts/p' /etc/hosts > /tmp/removeadhosts sed -n '1,/# start of removeadhosts/p' /etc/hosts > /tmp/removeadhosts-head
cat /tmp/removeadhosts | tee /etc/hosts >/dev/null sed -n '/# start of removeadhosts/,/# Custom ad list/p' /etc/hosts | sed -e '/# Custom ad list/d' -e '1d' > /tmp/removeadhosts-curl
rm /tmp/removeadhosts cat /tmp/removeadhosts-head | tee /etc/hosts >/dev/null
rm /tmp/removeadhosts-head
echo "Appended old hosts" echo "Appended old hosts"
if grep -qinE '# start of removeadhosts' /etc/hosts if grep -qinE '# start of removeadhosts' /etc/hosts
then then
@ -12,7 +13,6 @@ else
fi fi
echo 'Downloading ad list' echo 'Downloading ad list'
if [ -e /etc/removeadhosts/adlistings.txt ] if [ -e /etc/removeadhosts/adlistings.txt ]
then then
cat /etc/removeadhosts/adlistings.txt | \ cat /etc/removeadhosts/adlistings.txt | \
@ -22,6 +22,13 @@ then
done done
fi 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' echo 'Adding custom items from /etc/removeadhosts'
if [ -e /etc/removeadhosts/adlist.txt ] if [ -e /etc/removeadhosts/adlist.txt ]
then then