Ad-blocking via /etc/hosts
(general explainer - my motivation)
After installation the script runs immediately, and then updates every week (configurable).
By default only one list is used, but you can add as
many sources as you want - they’ll be combined to create the ultimate ad-blocking hosts file.
3 formats are supported:
- actual lists of hosts (many lists contain extra info or formatting, but the script will extract the domains only) (
listurls) - lists of URLs to actual lists of hosts (
metalists) - uBlock’s uassets repo (all will be stripped of extra information HOSTS cannot deal with) (
uassets)
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.
For starters, I recommend just one link from this repository.
E.g.:
#listurls="https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"
becomes
listurls="https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn/hosts"
You can whitelist sites by creating
/home/defaultuser/.config/hosts-block/whitelist.txt - the format is much like hosts
itself
but without the numerical address, so just the [sub.]domain.tld, one per line.
Same for blacklist.txt/blacklisting.
Please keep in mind that the www. subdomain has to be specified explicitely, if so desired.
In other words, for most domains you’ll probably want 2 lines:
domain.tld
www.domain.tld
There is no way to add wildcards for all subdomains to hosts.
If one of the config or black/whitelist files is edited, a new (not 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.
Before installing the package
There is nothing to do if you haven’t customized /etc/hosts. But if you want to preserve its content please move/copy it to /etc/hosts.head
before installing.
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.
Other apps writing to /etc/hosts?
You should not have other software installed that touches hosts. The file is static by definition (which does not mean that one isn’t allowed to modify it).
Credits to @vlagged for making me get into packaging.
Source
Framagit.org
Notabug.org


Systemctl )


