surf

surf
git clone git@git.zachrice.app:repos/surf.git
Log | Files | Refs | README | LICENSE

surf-adblock-update (1037B)


      1 #!/bin/sh
      2 # surf-adblock-update - download hosts blocklists and convert to WebKit JSON
      3 #
      4 # Fetches Steven Black's unified hosts (ads + malware + trackers),
      5 # converts to WebKit Content Blocker JSON, saves to ~/.surf/adblock.json.
      6 # Restart surf after running to pick up changes.
      7 #
      8 # Usage: surf-adblock-update
      9 #        crontab: 0 4 * * 0 surf-adblock-update
     10 
     11 OUTFILE="${HOME}/.surf/adblock.json"
     12 HOSTS_URL="https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"
     13 
     14 mkdir -p "${HOME}/.surf"
     15 
     16 echo "Downloading blocklist..."
     17 curl -sL "$HOSTS_URL" \
     18     | grep '^0\.0\.0\.0 ' \
     19     | awk '{print $2}' \
     20     | grep -v '^0\.0\.0\.0$' \
     21     | sort -u \
     22     | awk '
     23 BEGIN { printf "[" }
     24 {
     25     gsub(/\./, "\\\\.", $0)
     26     if (NR > 1) printf ","
     27     printf "{\"trigger\":{\"url-filter\":\"^https?://([^/]*\\\\.)?%s\"},\"action\":{\"type\":\"block\"}}", $0
     28 }
     29 END { printf "]\n" }
     30 ' > "${OUTFILE}.tmp" && mv "${OUTFILE}.tmp" "$OUTFILE"
     31 
     32 domains=$(grep -o '"block"' "$OUTFILE" | wc -l)
     33 echo "Done: ${domains} domains blocked -> ${OUTFILE}"