diff --git a/src/removeadhosts.sh b/src/removeadhosts.sh index 7e82314..eea5265 100755 --- a/src/removeadhosts.sh +++ b/src/removeadhosts.sh @@ -1,6 +1,10 @@ #!/bin/bash + +# Create temporary files to hold the old configs 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 + +# Copy back all the custom entries cat /tmp/removeadhosts-head | tee /etc/hosts >/dev/null rm /tmp/removeadhosts-head echo "Appended old hosts" @@ -12,13 +16,16 @@ else echo '# start of removeadhosts' >> /etc/hosts fi + +# Download entries from the listings list echo 'Downloading ad list' if [ -e /etc/removeadhosts/adlistings.txt ] then cat /etc/removeadhosts/adlistings.txt | \ while read SITE; do + echo "# removeadhosts site - $SITE" >> /etc/hosts curl $SITE 2>/dev/null | tee -a /etc/hosts >/dev/null - echo "0.0.0.0 $CMD" >> /etc/hosts + echo "# removeadhosts site - end" >> /etc/hosts done fi @@ -29,6 +36,8 @@ then fi rm /tmp/removeadhosts-curl + +# Add entries from adlist echo 'Adding custom items from /etc/removeadhosts' if [ -e /etc/removeadhosts/adlist.txt ] then