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

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.

Just out of curiosity - isn’t it possible to create a rpm package from your scripts that can be put on openrepos/chum so everybody can install it easily without the need to ssh to the device?
Not everybody is able/willing to do this - but i guess everybody would appreciate an rpm package that could be easily installed via a store.

What do you think?

1 Like

This issue has been just raised. A RPM package can run scripts but they are not designed for that task.

This kind of changes would go into something like a configuration manager but SFOS is missing completely such a tool. On the other hand, the tool that could have fulfill that role was Patch Manager but the evolution of PM gone in the direction of applying in-memory-only patches that do not survive to a reboot because otherwise a patch can mess up the system. This choice, as demonstrated in trying to patches some system configuration files, prevent to have a configuration manager tool with the minimum effort starting from the current PM.

However, because a configuration manager can potentially interfere also with the RPM installation / removing / update and for sure with the SFOS version upgrade no any way of applying persistent changes have been made but SSH. Hence, when you use SSH, it is your fault!

Welcome aboard, sailor! :hugs:

It exists a package as described into DNS CACHING section of this guide

The name of that package is dns alternative.

It is not part of the SFOS, but the OpenRepos community contributions.

No.

What was asked was to package the script in to an installable RPM file to make the script available to a user at leisure.

What was not asked was to run said script during installation of an RPM.


Now we have that misunderstanding out of the way: Patchmanager has nothing to do with anything asked here, and you still haven’t completely grokked how it actually works.
But that’s harmless, as it’s not really relevant to the topic of this thread.

Back on Topic, doing stuff with DNS, be it the way you propose in your links or otherwise is a valid approach and on topic in this thread, but the participants here apparently prefer the /etc/hosts/ approach. (Which in a way is a DNS approach, just without DNS.)

4 Likes

I already stated earlier:

Yes but it might take me a while. Thanks for the vote of confidence (well that’s how I choose to interpret it).

1 Like

The question was specific but in general what is required is a configuration manager.

How to provide a configuration manager?

Can be an RPM that install a set of scripts and allows to run them by a GUI providing parameters.

Because a configuration manager should be available also in rescue mode (no graphic interface available) or via remote console (e.g. SSH).

Is this enough?

Nope, if the configuration manager does not manage also the package installation set, as well.

This is possible only if there is a centralized organisation of the RPM repositories which is not the case of SFOS.

Changing the DNS is not the only thing that people wish to do, but just one of many.

Where is the best place to put a configuration manager considering the peculiarities of the smartphone market?

Into a rescue image, not in the system.

Oplà! :blush: