gaenserich / hostsblock

an ad- and malware-blocking script for Linux

Home Page:https://github.com/gaenserich/hostsblock

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in hostsblock on Ubuntu

glitsj16 opened this issue · comments

Hi, using latest hostsblock on Ubuntu returns an error. The same version on Archlinux does not. Seems not critical, hosts.block is updated as expected.

Ubuntu 16.04.2 LTS

$ sudo systemctl start hostsblock

$ systemctl status hostsblock
...
Jul 28 04:14:44 crow16 hostsblock[8448]: /usr/bin/hostsblock: line 442: [: /var/lib/hostsblock/hosts.head: integer expression expected
...

Regards

Thanks for the hint. I couldn't get rid of the stderr using your suggested change. But as I always use the hosthead functionality I got away with:

if [ "$hostshead" == 0 ]; then

I've run into a few issues with shell scripts. Shellcheck is a good resource to help refine/fix any naggling issues. I'd offer to push my "fixed" scripts, but I'm not sure if this would have any negative effect on other distros. I'm using Ubuntu 16.04

Here's the output of shellcheck on "install.sh" of the master branch:

In install.sh line 11:
if $(which $dep) &>/dev/null; then
^-- SC2091: Remove surrounding $() to avoid executing output.

In install.sh line 22:
if [ "$d" != "" ] || [ -n $d ]; then
^-- SC2070: Always true because you failed to quote. Use [[ ]] instead.
^-- SC2086: Double quote to prevent globbing and word splitting.

In install.sh line 32:
if [ "$h" != "" ] || [ -n $h ]; then
^-- SC2070: Always true because you failed to quote. Use [[ ]] instead.
^-- SC2086: Double quote to prevent globbing and word splitting.

In install.sh line 49:
if ps aux | grep [d]nsmasq | tr -s ' ' | cut -d' ' -f 11- | grep -q [d]nsmasq; then
^-- SC2009: Consider using pgrep instead of grepping ps output.
^-- SC2062: Quote the grep pattern so the shell won't interpret it.
^-- SC2062: Quote the grep pattern so the shell won't interpret it.

In install.sh line 50:
dnsmasq_user=$(ps aux | grep [d]nsmasq | tr -s ' ' | cut -d' ' -f 1)
^-- SC2009: Consider using pgrep instead of grepping ps output.
^-- SC2062: Quote the grep pattern so the shell won't interpret it.

In install.sh line 60:
if [ "$dns" != "" ] || [ -n $dns ]; then
^-- SC2070: Always true because you failed to quote. Use [[ ]] instead.
^-- SC2086: Double quote to prevent globbing and word splitting.

Here's the output of running "sudo ./install.sh" without modifications:

getent utility missing. Please install before running this script. Exiting...

Here's the output of the same command after fixing only the first warning:

Destination directory for hostsblock is /usr/bin/. Enter a new path or press Enter to keep as is.
/usr/bin/
Using preexisting user 'hostsblock'
Using preexisting group 'hostsblock'
Adding user hostsblock to group hostsblock
You appear to be running dnsmasq under user libvirt+
root
dnsmasq. If you will be using hostsblock
with dnsmasq as a caching daemon, dnsmasq needs read access to hostsblock's home directory.
To do so, should I add libvirt+
root
dnsmasq to the hostblock group?
y/N y
gpasswd: user 'libvirt+
root
dnsmasq' does not exist
gpasswd: user 'libvirt+
root
dnsmasq' does not exist
In order to manage hostsblock correctly, you must run the script as the user 'hostsblock',
even when using the 'hostsblock-urlcheck' script (aka 'hostsblock -c').
To do so, type 'sudo -u hostsblock hostsblock' or 'sudo -u hostsblock hostsblock-urlcheck', etc.
Before you can do this, however, the following line must be added to sudoers:

jake ALL = (hostsblock) NOPASSWD: /hostsblock,/hostsblock-urlcheck

where 'jake' is the user from which you want to manage hostsblock.
Do you want to add this line to the bottom of sudoers right now? (if so, make sure to copy the text now).
[y/N]
Setting up permissions for hostsblock home directory ...
chown: cannot access '': No such file or directory
chmod: cannot access '': No such file or directory
Should I enable and/or start the hostsblock service? (Requires systemd)
1) Only Enable
2) Only Start
3)Start and Enable
4) Do Nothing (Default)
[1-4]
hostsblock is now installed. Check out the configuration file under /hostsblock.conf.
By default, hostsblock does not directly write to /etc/hosts or manipulate your dnsmasq daemon.
To make it do so, see the instructions included in /hostsblock.conf

I hope this helps