Hosts-block (ad-blocking via /etc/hosts) now in Chum:testing

hosts-block Ad-blocking via /etc/hosts

Disclaimer: this software is in testing. Don’t use it if you don’t want to use the command line on your phone or aren’t prepared to use recovery.
That said, it will come out of testing at some point so stay tuned.

(general explainer - my motivation)

The script collects, sanitizes and compiles blocklists from the internet into a hosts file that will block domains on your whole system.
It runs immediately after installation, then once a week (currently hardcoded) through a systemd timer/service.
It sends various graphical notifications when something important happens (good or bad).

Only if you want stricter or less strict blocking, can you copy /usr/share/doc/hosts-block/cfg.sh.example to /home/defaultuser/.config/cfg.sh
and edit it to your liking. You can also black/whitelist sites by creating /home/defaultuser/.config/whitelist.txt and blacklist.txt resp.

By default only Steven Black’s default list is used, but the script can extract domains from all kinds of formats and combine them into one huge list. See /usr/share/doc/hosts-block/cfg.sh for a maxi list (about 10x larger than the default).

The package is a collaboration between myself & @vlagged.

Source
Framagit.org
Notabug.org

20 Likes

Many thanks to you for bringing ad-blocking to lazy tinkerers like me!

Certain sites load much faster, almost instantly, after installing Hosts-block. I always thought the browser was just a bit slow in some regard, but apparently it was all about excessive traffic caused by the ads.

I don’t know if this should be expected, but I had to install lipstick-qt5-tools before I was able to install this package.

devel-su zypper install lipstick-qt5-tools

4 Likes

Yes, adblocking is good for performance, too.

Thanks for bringing the dependency issue to my attention. lipstick-qt5-tools is listed as a dependency; I thought that as such, it gets installed automatically.

It’s not even a hard dependency, only for notifications.

3 Likes

Thanks for bringing it to chum! I had it installed before already and did the installation without uninstalling it before. So far I didn’t notice any problems, do you think that was OK?

1 Like

I don’t think that caused any problems. But please show us:

ls -hl /etc/hosts*
head /etc/hosts.head

Very nice! Finally! Cool!
Ohnonot, would you explain please, if i want to adblock “more and more and more”, i need to copy cfg.sh file from doc folder to home/defaultuser/.config and uncomment last lines only as on screenshot? That’s all? What’s after, need to restart something, how?

1 Like

Thanks for using it.
Yes, uncomment the variables from here onwards:

## uncomment all variables for maximum blocking:
## all variables can contain multiple urls separated by newlines (see extraurls below)

## uassets Must be in tar.gz format. top folder must be named *u[aA]ssets*
## under which we look for thirdparties and filters subfolders
uassets="https://github.com/uBlockOrigin/uAssets/archive/refs/heads/master.tar.gz"

## A list of urls containing blocklists. Only lines starting with http(s) are considered:
metalists="https://v.firebog.net/hosts/lists.php?type=tick"

## Extra urls of blocklists, 1 per line: (note the quotes, var contains newlines)
extraurls="https://malware-filter.gitlab.io/malware-filter/phishing-filter-hosts.txt
https://malware-filter.gitlab.io/malware-filter/urlhaus-filter-hosts.txt
https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts"

and save as /home/defaultuser/.config/hosts-block/cfg.sh.

Currently it won’t automatically update /etc/hosts*; open a terminal and enter
devel-su systemcl start hosts-block

* I just found out that this is relatively simple to achieve. Stay tuned!

1 Like

Sorry, I can’t access per ssh at the moment, therefore only per screenshot:

Thank you! In manual was not said about hosts-block folder in .config :slight_smile: Systemctl )

Cool, etc/hosts was 3,58 mb, now it 40,78 mb, amazing! Let’s block’em all :smiley:

Yep, restart service from Terminal is kinda easy. For newcomers of Sailfish - sure hard and not obvious)

Ou! It even can block ads in AppSupport too! Excellent!

We must set file alien-generate-extra-config.sh executable as root only?

Tested with rights set to all, except 2 in middle:

But not works, on same page in Sailfish - no ads, in that page in AppSupport - there’s ads.

Then - just start AppSupport and it will work?
If we want to disable ad block in AppSupport - just delete this alien-generate-extra-config.sh file?

And would you please explain, how does hosts-block works with this huge 40 mb file on filesystem? Read it every time? Load it into memory? In what process? Didn’t find any new processes in Crest after installing hosts-block.

2 Likes

This last solution of creating 50-etc-hosts.sh works for AppSupport! Cool! Free from ads everywhere on Sailfish now :blush:

1 Like

@jauri.gagarin.II
Your system still works but hosts.head is too large.
Just delete it (as root), it will be recreated with default values the next time the script runs.

devel-su rm /etc/hosts.head
2 Likes

Nice! I will evtl. look into it, but next up is the auto-restart on config/whitelist/blacklist changes.

And would you please explain, how does hosts-block works with this huge 40 mb file on filesystem? Read it every time? Load it into memory?

https://www.man7.org/linux/man-pages/man3/gethostbyname_r.3.html

In short, the glibc resolver does it. How exactly it’s buffered I don’t know but I’m sure all or most of it will be loaded into memory.

But programs can use their own ways to resolve names. Usually they still respect /etc/hosts but not always (Chrome).

I have used hosts-based adblocking on various devices for years (with equally large files) and never had performance issues.

3 Likes

This did not happen for me just now, the Chum package pulled the dependency in just as one would expect. Maybe this is from the very old package (before I made this thread) or the one from Openrepo’s (broken through my fault, @vlagged should remove)?

Version 0.0.6-1 now in chum:testing :tada:

As promised blacklisting & whitelisting works and the script will auto-update /etc/hosts if one of blacklist.txt, whitelist.txt or cfg.sh have been edited in ~/.config/hosts-block

1 Like

Not sure what happened there. The message is very recent and the 0.0.2 from openrepos should’ve fixed it (maybe the 0.0.2 builds were not listed as latest, as there were two… hmm).

To be safe(er), I have updated 0.0.6 in openrepos one last time, and added a message to use chum. Thanks

I installed the package was from Chum testing repository after reading your original post. I even double-checked this just now; the package is not listed as installed in Storeman, only in Chum GUI.

I’ll see if I can reproduce the issue.

1 Like

What is the name of the application in Chum? I can’t find it…

How can i install this application?

You have to enable the test repo in the settings. Maybe even to not only show packages.

I turned it on. But I left the option to only show apps on.
When I turned that off, I was able to find it without any problems.

2 Likes

For some reason I had to reset the phone.

However, now I have a problem that it won’t boot. It just shows the Sailfish OS logo.

Any ideas?