Tiny Core Extensions > TCE Q&A Forum

Use /etc/host for ad-blocking?

<< < (2/3) > >>

emninger:
I changed the script in this way:

Before:

--- Code: ---# Combine system hosts with adblocks
echo Merging with original system hosts...
echo -e "\n# Ad blocking hosts generated "$(date) | cat ~/hosts-system - $temphosts2 > ~/hosts-block

# Clean up temp files and remind user to copy new file
echo "Cleaning up..."
rm $temphosts1 $temphosts2
echo "Done."
echo
echo "Copy ad-blocking hosts file with this command:"
echo " sudo cp ~/hosts-block /etc/hosts"
echo
echo "You can always restore your original hosts file with this command:"
echo " sudo cp ~/hosts-system /etc/hosts"
echo "so don't delete that file! (It's saved read-only for your protection.)"
echo
--- End code ---

Now:

--- Code: ---# Combine system hosts with adblocks
#echo Merging with original system hosts...
#echo -e "\n# Ad blocking hosts generated "$(date) | cat ~/hosts-system - $temphosts2 > ~/hosts-block

# In TinyCoreLinux /etc/hosts  is recreated at boot by  /usr/bin/sethostname
# therefore no need to merge blacklist with original hosts. In bootsync.sh
# that is done by: 'cat ~/blocklist >> /etc/hosts'
cp $temphosts2 blocklist

# Clean up temp files and remind user to copy new file
echo "Cleaning up..."
rm $temphosts1 $temphosts2
echo "Done."
echo

--- End code ---

Seems to work ... ;)

emninger:

--- Quote from: Misalf on December 23, 2015, 07:09:54 AM ---
[...]

The script needs GNU wget it seems (at least for  hosts-file.net ).

[...]

--- End quote ---

Hi Misalf!

I wanted to turn back on this: Indeed doing
--- Code: ---wget -q -O - http://hosts-file.net/ad_servers.asp
--- End code ---
i get an error prompt
--- Code: ---wget: bad address '.%5Cad_servers.txt'
--- End code ---
.

Now, i'm trying to understand how and why ... ;) And if there is, eventually a way to play around this problem (?)
Guessing in the dark, i went to the address in the browser and copied the link to the host file, which looks like this:


--- Code: ---http://hosts-file.net/.%5Cad_servers.txt
--- End code ---

When i do "wget http://hosts-file.net/.%5Cad_servers.txt" it works. But may be, that's a "static" link ... (?)

PS. As i understand it, TCL uses busybox, so if i do 'wget' in a shell in reality it is 'busybox wget' (because TCL somewhere - where? - defined wget as a symlink to busybox wget). Is that correct?

Rich:
Hi emninger
Install  wget.tcz.

coreplayer2:
Somewhere in this forum is a thread on updating the host file from from the good folks at putorius.net
Maybe it's the same script..?  this one works fine.  Update and add etc/hosts to your backup
I've been experimenting with this, but it adds a considerably large file to my backup so tend not to use it.   
it's hard to tell the difference as I hardly every get ad's anyhow


--- Code: ---~ $ ./HostFileUpdate.sh
Connecting to winhelp2002.mvps.org (216.155.126.40:80)
hosts.txt            100% |************************************************|   498k  0:00:00 ETA
~ $

--- End code ---


--- Code: ---#!/bin/sh
## Update hosts file
## http://www.putorius.net/2012/01/block-unwanted-advertisements-on.html

## backup old hsts file
# cp /etc/hosts ~/.hosts_bak


if [ -f ~/.hosts_bak ]; then
cd /tmp
wget http://winhelp2002.mvps.org/hosts.txt
sudo rm /etc/hosts
sudo mv hosts.txt /etc/hosts
sudo cat ~/.hosts_bak >> /etc/hosts
else
echo "No hosts backup found"
fi
exit

--- End code ---


Good luck

Rich:
Hi emninger

--- Quote ---PS. As i understand it, TCL uses busybox, so if i do 'wget' in a shell in reality it is 'busybox wget' (because TCL somewhere - where? - defined wget as a symlink to busybox wget). Is that correct?
--- End quote ---
Yes,  wget  is a symlink in  /bin  which points to busybox. If you install  wget.tcz  then  wget  will also be found in
/usr/local/bin. Since  /usr/local/bin  appears in the  path  variable before  /bin  it will default to using that version if you
enter  wget.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version