To be found here (it’s high time I moved this to its own repository).
After installation the script runs immediately, and then updates every week (configurable).
By default medium protection is used, provided by one of firebog’s meta lists, checked against false positives.
You can add as many sources as you want - they’ll be combined and de-duplicated to create the ultimate ad-blocking hosts file.
3 formats are supported, all are URLs to
metalists)uassets)listurls)Each variable can contain several URLs, separated by newlines.
If you want stricter or less strict blocking, copy
/usr/share/doc/hosts-block/cfg.sh to /home/defaultuser/.config/hosts-block/
and edit it to your liking.
The file is sourced by the ash shell script, i.e. it follows shell syntax.
When the edited config file is saved a forced run is triggered automatically.
You can force-regenerate the hosts file manually with devel-su systemctl start
hosts-block-forced.service or devel-su hosts-block forced.
The script sends various graphical notifications when something important happens (good or bad).
“Modifications to this file normally take effect immediately, except in cases where the file is cached by applications” (source). Since this is the case for the SFOS browser you will be prompted to restart it if required.
You can whitelist sites by creating
/home/defaultuser/.config/hosts-block/whitelist.txt - the format is much like hosts
itself but without the numerical IP address, so just the [sub.]domain.tld, one per line.
Same for blacklist.txt/blacklisting.
Both can also be achieved via two “Open with…” .desktop files that will show up in a context menu for links, but unfortunately not in the browser itself as that would require a Share plugin (TODO).
Both can also be achieved via two “Open with…” .desktop files that will show up in a context menu for links, but unfortunately not in the browser itself as that would require a Share plugin (TODO).
This will not blacklist the specific URL that was tapped, but its full domain. E.g.
https://forum.sailfishos.org/t/hosts-block-ad-blocking-via-etc-hosts-now-in-chum/22282
is stripped down to
forum.sailfish.org
and
https://framagit.org/ohnonot/sfos/hosts-block
is stripped own to
framagit.org
Please keep in mind that some sites redirect to the www. subdomain, which has to be specified explicitely, if so desired. In other words, for such domains you’ll probably want 2 lines (TODO: make the script act accordingly when the domain starts with www):
domain.tld
www.domain.tld
There is no way to add wildcards for all subdomains to hosts.
If one of the black/whitelist files is edited (manually or via .desktop entry), an offline (not forced) run is triggered automatically.
Has been added. AFAICS updates to the hosts file don’t transfer to Android apps in real time. I’m still investigating, but until then a restart of AAS is desired when hosts is updated.
There is nothing to do if you haven’t customized /etc/hosts. But if you want to use its content as the head of the new hosts file, move/copy it to /etc/hosts.head before installing.
In any case, rpm will archive the existing /etc/hosts as /home/hosts*, on initial installation only.
If /etc/hosts.head does not exist, the script uses a default hosts.head (see repo) that covers both standard SFOS and AAS entries.
Either file becomes the “head” (i.e. the first few lines) of your new hostsfile.
It is, however, not a good idea to put to-be-blocked domains in /etc/hosts.head. Please use the blacklist feature for that (if you think these domains haven’t been covered by one of the available blocklists already).
If you uninstall hosts-block /etc/hosts.head (or the repo default) will become your regular hosts file again.
You should not have other software installed that modifies hosts. System software won’t do this anyhow - the file is static
by definition (which does not mean that one isn’t allowed to modify it).
Nevertheless, upon first installation rpm will archive /etc/hosts to /home/hosts*tar.gz but will not restore it upon uninstallation.
Source
Framagit.org
Notabug.org