Commits

MrTux Hdb  committed a1465b0

Add new blocking ads script. Remove old script

  • Participants
  • Parent commits fe549b2

Comments (0)

Files changed (2)

File bin/install-adblocking-hosts

+#!/bin/bash
+# Filename: install-adblocking-hosts
+# Description: Script to automate building an adblocking hosts file
+
+# Perform work in temporary files
+temphosts=$(mktemp)
+systemhosts="/etc/hosts"
+
+# Obtain various hosts files and merge into one
+echo "Downloading ad-blocking hosts files..."
+wget -q -O - "http://adaway.org/hosts.txt" >> $temphosts
+wget -q -O - "http://winhelp2002.mvps.org/hosts.txt" >> $temphosts
+wget -q -O - "http://hosts-file.net/ad_servers.asp" >> $temphosts
+wget -q -O - "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext" >> $temphosts
+wget -q -O - "http://sysctl.org/cameleon/hosts" >> $temphosts
+wget -q -O - "http://someonewhocares.org/hosts/hosts" >> $temphosts
+wget -q -O - "http://www.malwaredomainlist.com/hostslist/hosts.txt" >> $temphosts
+wget -q -O - "http://www.hostsfile.org/Downloads/hosts.txt" >> $temphosts
+
+# Processing hosts file:
+# 1. Remove MS-DOS carriage returns
+# 2. Replace 127.0.0.1 with 0.0.0.0 because then we don't have to wait for the
+#    resolver to fail
+# 3. Delete all lines that don't begin with 0.0.0.0
+# 4. Delete any lines containing the word localhost because we'll obtain that
+#    from the original hosts file
+# 5. Delete any comments on lines
+# 5. Convert tabs to spaces
+# 6. Remove extra spaces
+echo "Parsing and merging hosts files..."
+sed -i -e 's/\r//' -e 's/127.0.0.1/0.0.0.0/' -e '/^0.0.0.0/!d' -e '/localhost/d' -e 's/#.*$//' -e 's/\t/ /g' -e 's/  */ /g' $temphosts
+
+# Combine system hosts with adblocks
+echo "Merging with original system hosts..."
+# Delete all line from mark line (old data)
+sed -i '/There is no place like 127.0.0.1/,$d' $systemhosts
+# Add new line for next update
+echo "# There is no place like 127.0.0.1" >> $systemhosts
+
+# Remove duplicate using sort and add them to system hosts file
+sort -u $temphosts >> $systemhosts

File bin/update-hosts

-#!/bin/sh
-# Filename: update_hosts.sh
-# Description: Update lastest mvps hosts
-
-ETC_HOSTS=/etc/hosts
-MVPS_HOSTS=/tmp/hosts.txt
-MVPS_URL="http://winhelp2002.mvps.org/hosts.txt"
-
-if wget ${MVPS_URL} -O ${MVPS_HOSTS} 1>/dev/null 2>&1 ; then
-        #dos2unix $MVPS_HOSTS
-        sed -i 's/\r$//' $MVPS_HOSTS
-        sed -i '/This MVPS HOSTS file is a free download from/,$d' $ETC_HOSTS
-        cat $MVPS_HOSTS >> $ETC_HOSTS
-        echo "$ETC_HOSTS updated"
-else
-        echo "$ETC_HOSTS not updated"
-        exit 1
-fi
-
-## End of file #####