View Single Post
Posts: 178 | Thanked: 91 times | Joined on May 2011 @ Mira (Venice) - Italy
#1
Read this page one the wiki if you don't know what I'm talking about (the page talk about ad-blocking on N900 but the hosts file method works with nearly every OS ever created).

And maybe a look here shuld be useful too.

So first of all you need root acces, so type: devel-su

Backup your current hosts file with:
Code:
cp /etc/hosts /etc/hosts.base
hosts.base will be used by the script to create the new hosts file so do not delete it!

Now create a file (example: vi update-hosts) with these commands:
Code:
#!/bin/bash

URL=http://winhelp2002.mvps.org/hosts.txt
TEMP=/etc/hotst.tmp
BASE=/etc/hosts.base
HOSTS=/etc/hosts

rm -f $TEMP 2> /dev/null
curl $URL | grep ^0.0.0.0 | cut -d "#" -f 1 | grep -v localhosts >> $TEMP && rm -f $HOSTS && cat $BASE $TEMP | sed -e "s/^\s*//g" -e "s/\s*$//g" -e "/^\s*$/d" -e "/^$/d" >> $HOSTS
rm -f $TEMP 2> /dev/null
The third line of commands goes from curl to >> $HOSTS, it's only 1 line with a lot of commands... I know... this looks bad but it's a safe way to menage the hosts file without break anything.

Make it executable, writable and readable only by root with:
Code:
chown root:root update-hosts
chmod 770 update-hosts
Execute it with (or without devel-su if you have are the root)
Code:
devel-su ./update-hosts
Run this file to update the hosts file. "hosts.tmp" will be created to store the file downloaded from http://winhelp2002.mvps.org/hosts.txt. The script automatically remove the temp file and every comment or usless strings and characters in the file to reduce the size (not so much, ~100KB).

To restore the original hosts file type:
Code:
rm -f /etc/hosts
mv /etc/hosts.base /etc/hosts
Btw this ad-blocking method is very simple and works only with the well know ads... but...

You can test it by yourself on your Jolla with these sites:
1) http://ads-blocker.com/testing (partially works)
2) http://thepcspy.com/blockadblock/ (works!)
3) http://simple-adblock.com/faq/testing-your-adblocker/ (do not work)

Last edited by Vento; 2015-08-12 at 10:50. Reason: Script update
 

The Following 7 Users Say Thank You to Vento For This Useful Post: