Ad blocking in SailfishOS in 2023 - What are the options?

I still use a simple systemd timer to download a hosts file to /etc/hosts, as described (and now updated) here, incl. bind-mount on Android.

6 Likes

Hey, @ohnonot thank you so much for your Instruction. Finally I did manage to ban ads from my browser. I makes a real difference in performance.

A short notice for others: Your instructions are not for newbies. It was necessary to do several additional steps to set up the system correctly.

I can reproduce the following code and modify hosts.timer and hosts.service as described :

> cd /etc/systemd/system
> nano hosts.timer hosts.service
> systemctl daemon-reload
> systemctl enable hosts.timer

During the next steps, however, I got lost.
Putting the following in the terminal:
~/.local/bin/hosts
results in an error (no such file/directory exists)
I had to create the file first.
the same goes with hosts.head (I needed to create the file first, and have to chance the permissions second)

2 Likes

Thanks for your feedback! It is much appreciated.

  • I have changed the article so that the script resides in /usr/local/bin/hostsupdate instead of the user’s home directory, and gave it a better name. It makes more sense this way.
  • the necessity of hosts.head being present beforehand (and created manually) is mentioned in the article. I cannot automate ths process without complicated checks and taking the user’s freedom to have a customised hosts file (i.e. the head portion of it) but I added a check to the script that will make it fail if that file is not present.
  • Yes some preliminaries are required but tbf, it is possible to do everything on the device, without ssh.
5 Likes

I just used your script/timer approach and went with the ad block test site Test Ad Block - Toolz from 9% to 54% of blocked ads with the sailfish browser - pretty nice.

However, for AAS Fennec with ublock I get 96%…

1 Like

I get 87% with Blocky and wally3k’s ticked list :slight_smile:

1 Like

Check this part of this guide, I use these DNS on my laptop and they are doing a pretty well job:

1 Like

I get very similar results even with the strictest single list.

The developer of this tool also made this one. Not sure what the difference is, but it gives far less flattering results. I could not find any other differentiated & opensourced tools.

Using firebog.net’s meta 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.

Anyhow, I updated my script and uploaded it to a VCS site. To be continued.

3 Likes

Using (DNS alternative ) + DNScrypt-proxy blocklist + Defender II that can be used simultaneously, I get 93% for lists updated in August.

is there a way that doesn’t use DNSmasq?

1 Like

Yes, there is, You can install DNScrypt-proxy and then DNScrypt-proxy blocklist alone.

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

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

8 Likes

Thanks @ohnonot for this!
Two questions:

  1. Have you considered packaging this as a rpm? Might be just adapting an existing spec.
  2. The script is not compatible with busybox, one needs to zypper in gnu-bash. Is there any “bashism” unavoidable?

P.S. Good job, I now have a 18M hosts, rebooting :slight_smile:

4 Likes

Is that a Roman or metric “M”?

:rofl: Roman Megabytes octets :wink:

1 Like
  1. Yes but it might take me a while. Thanks for the vote of confidence (well that’s how I choose to interpret it).
  2. Good point, and done. Please check it out - it works for me. (my /bin/sh still points to busybox).

Dependencies:
curl comes pre-installed afair.
Apart from that busybox has versions of all utils used: mktemp tar grep sed sort but I have no idea how to check which version the script actually uses?

PS: there were also some bugs to fix.

4 Likes

Thanks for your effort. However, I can see something in the output what I don’t understand:

./hostsupdate: line 92: 0: not found

Am I doing something wrong or is this to be expected?

1 Like

Firefox with ublock is all I need. For Youtube I have Libretube, and I guess I could get streamlink to work somehow if I were so inclined to watch twitch streams and whatever.

I guess your /bin/sh is linked to bash. I have changed the offending bit now so it should work both with bash and busybox (see previous comments). Please try again.

1 Like

Thank you very much for the update! Now it worked. My Shell is busybox, though.

/bin/sh -> ../usr/bin/busybox

Anyway, thanks a lot!

Small new thing I discovered is this: (but I don’t really want to bother you any further)

rm: can't remove 'meta-list': No such file or directory
1 Like

It’s no bother. It should’ve been meta.list instead of meta-list. Fixed, pull again.

Btw and @everybody: this will result in pretty strict domain blocking. Not to everyone’s taste. If you want less maybe you can choose one of Steven Black’s ready-made files instead.