Nemo 7d286f68c8 fixed an oops 11 months ago
..
.gitignore f4720d2545 usable version of hostsupdate. added chargecurrent 11 months ago
README.md a3b4a67b58 use sh instead of bash, fix some bugs 11 months ago
hosts.service 71a1432e6f simplifying script, adding systemd stuff 11 months ago
hosts.timer a3b4a67b58 use sh instead of bash, fix some bugs 11 months ago
hostsupdate 7d286f68c8 fixed an oops 11 months ago

README.md

hostsblock

I reworked my hosts-based adblock script based on these insights:

The developer of this tool also made this one . Not sure what the difference is, but it gives far less flattering results.

Using firebog.net ’s meta list + Steven Black's largest list combined into one big hosts file I get ~80% with both tools.

A slightly stricter µBlock configuration gives me 100% though, and µBlock gets a lot of its lists in AdBlock format. I will try to figure out how to best convert these to hosts format.

If I use a combination of different hosts-based domain lists (as above) I get 87% and 65% resp. with those two test tools.

If I convert and add domains from ublock's lists to that I get 91% and 87% resp., even though this adds "only" a few thousand unique entries.

Therefore the script has grown quite complex:

  • it converts uBO's uAssets as far as possible to be used by /etc/hosts
  • it downloads everything from firebog.net's meta list plus Steven Black's largest hosts file
  • it combines and unique-sorts everything, adds a header and finally overwrites the old /etc/hosts

Ultimately it comes down to get a timely combination of as many sources as possible. I'm already re-inventing the wheel here; various more configurable solutions exist. But then, the whole thing is simple enough.

Keep in mind that uBO does more than domain blocking, and many adblock-specific rules can never be part of hosts-based blocking.
OTOH hosts-based blocking is always system-wide and very light on resources.

Anyhow, get the script with systemd service/timer here:
Notabug.org or
Framagit.org

Adjust to your liking.
Copy the shell script to /usr/local/bin/hostsupdate and the systemd files to /etc/systemd/system.
Start & enable the timer: systemctl start --now hosts.timer && systemctl enable hosts.timer

Android App Support

It is possible to use the same hosts file under AAS. Create /usr/libexec/appsupport/alien-generate-extra-config.sh with the following content, and make it executable:

#!/bin/sh

echo ">>> $0" >&2
echo ">>> \$1 $1" >&2
echo ">>> \$2 $2" >&2

[ "$#" -gt 1 ] && shift

echo "lxc.mount.entry = /etc/hosts system/etc/hosts none bind,create=file 0 0" > "$1/29-hosts_config"

You should now also add the alias Android uses for ipv6 to /etc/hosts.head:

127.0.0.1		localhost.localdomain localhost
::1		localhost6.localdomain6 localhost6 ip6-localhost