Post Reply

[SCRIPT] Adblock Script and Updater

OP yareally

13th August 2011, 06:07 AM   |  #1  
yareally's Avatar
OP Senior Member
Thanks Meter: 220
 
1,425 posts
Join Date:Joined: Feb 2011
Donate to Me
I put together a small shell script to make it easy for anyone rooted to block ads and check to see if they have the latest version I keep of adhosts. If after checking you do not have the latest, it will download it for you automatically.

What does this script do (in a nutshell):

1) Checks to see if you have the latest version of ad hosts for adblocking from me
2) If you do not have the latest, it will download it for you
3) If you have the latest, it just exits out, no changes
4) Installs the script to your /system/xbin directory so the next time you just have to type:

Code:
su
blockads
and it will run the script for you

How to run this?

Get this if you are using an AOSP ROM:
1) Download it from http://dl.dropbox.com/u/24904191/blockads

Try this if you are using a SENSE ROM (thanks chrootz for the fixes):
1) http://dl.dropbox.com/u/24904191/sense/blockads

*** If you have troubles getting the script to work, try updating your system to the latest version of busybox (stick it in /system/xbin and overwrite the current version of busybox, then change the permissions to 755 and owner and group to root) ***

2) Move it to /data/local/tmp (if you dont have it, create it) from a file explorer with root permissions (must set the system in r/w mode) or from the terminal shell
3) make sure the script has the right permissions by typing:

Code:
su
chmod 755 /data/local/tmp/blockads
in the terminal shell (in the emulator or whatever you use to get to it)

4) run the script by typing

Code:
/data/local/tmp/blockads
5) let it do its thing

After its done you can run it again anytime from the terminal by typing

Code:
su
blockads
as already mentioned.


I'm working on making it a GUI app next (with more features), but this should tie anyone who wants it over until then

Anyone who finds any adservers and wants me to add them to the list, feel free to list them here and I will add them.

Latest updates:
2011-12-01: Updated to block carrieriq
Last edited by yareally; 5th December 2011 at 11:28 AM.
The Following 7 Users Say Thank You to yareally For This Useful Post: [ View ]
13th August 2011, 06:55 AM   |  #2  
Account currently disabled
Flag Southern Michigan
Thanks Meter: 190
 
2,037 posts
Join Date:Joined: Sep 2010
Tried this out and got this:

sh-3.2# su
sh-3.2# /data/local/tmp/blockads
Fetching host file via hostname
wget: bad address 'dl.dropbox.com'
update could not be completed, sorry
sh-3.2#
The Following User Says Thank You to newter55 For This Useful Post: [ View ]
13th August 2011, 07:11 AM   |  #3  
yareally's Avatar
OP Senior Member
Thanks Meter: 220
 
1,425 posts
Join Date:Joined: Feb 2011
Donate to Me
Quote:
Originally Posted by newter55

Tried this out and got this:

sh-3.2# su
sh-3.2# /data/local/tmp/blockads
Fetching host file via hostname
wget: bad address 'dl.dropbox.com'
update could not be completed, sorry
sh-3.2#

I forgot some ROMs and such have a busybox version that doesn't work right with hostnames in wget. I'll see if I can work around that and update the script

EDIT: updated to work around by using the IP for those that their busybox wget does not work correctly with hostnames. Only issue with that is the IP may change.
Last edited by yareally; 13th August 2011 at 07:15 AM.
13th August 2011, 02:12 PM   |  #4  
GermanGuy's Avatar
Senior Member
Flag Minneapolis
Thanks Meter: 117
 
1,091 posts
Join Date:Joined: Mar 2005
More
Ok. I am stuck. I actually don't have a hosts file under "etc", only a hosts.bak. With root explorer mounted as r/w I am still not able to rename the "host.bak" file to "hosts" - error message "read-only file/directory". I created a blank "hosts" text file, put in on the sdcard and with terminal emulator still can't cp to "etc" because of "read-only directory" error message. Any other suggestions?
13th August 2011, 02:39 PM   |  #5  
Account currently disabled
Flag Troy, Michigan
Thanks Meter: 2,105
 
3,859 posts
Join Date:Joined: Dec 2010
Donate to Me
More
Quote:
Originally Posted by GermanGuy

Ok. I am stuck. I actually don't have a hosts file under "etc", only a hosts.bak. With root explorer mounted as r/w I am still not able to rename the "host.bak" file to "hosts" - error message "read-only file/directory". I created a blank "hosts" text file, put in on the sdcard and with terminal emulator still can't cp to "etc" because of "read-only directory" error message. Any other suggestions?

Top right corner of Root Explorer .... Mount RW.



Sent from my A05PTH3ORY using XDA App
The Following User Says Thank You to DroidTh3ory For This Useful Post: [ View ]
13th August 2011, 02:39 PM   |  #6  
spotmark's Avatar
Senior Member
Massachusetts
Thanks Meter: 507
 
1,460 posts
Join Date:Joined: Feb 2010
More
Does this do anything differently then AdFree, from the market?
Last edited by spotmark; 13th August 2011 at 02:47 PM.
13th August 2011, 02:57 PM   |  #7  
Account currently disabled
Flag Southern Michigan
Thanks Meter: 190
 
2,037 posts
Join Date:Joined: Sep 2010
Quote:
Originally Posted by yareally

I forgot some ROMs and such have a busybox version that doesn't work right with hostnames in wget. I'll see if I can work around that and update the script

EDIT: updated to work around by using the IP for those that their busybox wget does not work correctly with hostnames. Only issue with that is the IP may change.

Updated blockads script to test this am and:


sh-3.2$ export PATH=/data/local/bin:$PATH
sh-3.2$ su
sh-3.2# blockads
Fetching host file via hostname
wget: bad address 'dl.dropbox.com'
The busybox version of wget on your system does not work correctly with
hostnames. Trying workaround with latest known IP to the hostname...
Connecting to 184.73.229.87 (184.73.229.87:80)
hosts 100% |***********| 641k 00:00:00 ETA
backing up old host file and updating
failed on 'hosts' - Cross-device link
md5sum: can't open '/system/etc/hosts': No such file or directory
/system/xbin/blockads: line 38: [: 8172d35d1b72871f7e1ef4e709920f0e: unary operator expected
Unable to chmod /system/etc/hosts: No such file or directory
Unable to chmod /system/etc/hosts: No such file or directory
remounting filesystem in r/o mode...
Cleaning up files...
rm failed for -f, No such file or directory
update complete!
sh-3.2#

The end result is the existing hosts file being renamed hosts.bak and obviously no new hosts filebeing being created.

EDIT.... The above is testing on my inspire running busybox 1.19. Tried using the script on my sensation running bb 1.18.4 and it works fine.

Edit edit... Installed bb 1.18.4 on inspire and result is the same as posted above.
Last edited by newter55; 13th August 2011 at 03:54 PM.
13th August 2011, 03:08 PM   |  #8  
GermanGuy's Avatar
Senior Member
Flag Minneapolis
Thanks Meter: 117
 
1,091 posts
Join Date:Joined: Mar 2005
More
Quote:
Originally Posted by DroidTh3ory

Top right corner of Root Explorer .... Mount RW.



Sent from my A05PTH3ORY using XDA App

That's what I did, but it does not work - still does not let me modify read-only files.
13th August 2011, 04:14 PM   |  #9  
twistedumbrella's Avatar
Recognized Developer
Thanks Meter: 6,457
 
6,364 posts
Join Date:Joined: Sep 2007
More
After reading over the code and seeing the comments, I can only guess you had the modified version of wget on your device during testing, which does support host names. Before I continue, I am not trying to rain on your parade, but... By downloading the file, checking the md5, comparing it to the existing file, replacing if needed, and then cleaning up... you went about 5 steps beyond what just doing an "if server file is newer" check would do by including a custom wget. Even though you have to put in the code to install and verify the wget, the trade is that you no longer have to download the file every time, check it every time, and worry about making sure the md5 matches.

If you decide you want to switch over to that method, you can check out the option already included in http://forum.xda-developers.com/show....php?t=1092128 by downloading the live install version to view the actual script. Just a recommendation to optimize the process. Nice work, though, you definitely found a way to get the job done.

As for the difference between this and Adfree. There is no real difference. Adfree checks the server, does a callback, and prompts the user with updates. Adfree just requires an entire shell to turn it into an app, but will automatically run on boot.
13th August 2011, 04:22 PM   |  #10  
spotmark's Avatar
Senior Member
Massachusetts
Thanks Meter: 507
 
1,460 posts
Join Date:Joined: Feb 2010
More
Quote:
Originally Posted by twistedumbrella

As for the difference between this and Adfree. There is no real difference. Adfree checks the server, does a callback, and prompts the user with updates. Adfree just requires an entire shell to turn it into an app, but will automatically run on boot.

So, for those of you not comfortable running ADB, or Terminal Emulator, just install AdFree, and let it do everything for you.

Post Reply Subscribe to Thread

Tags
adblock, ads, bash, shell
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes