Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 73 lines (65 sloc) 2.53 KB
#!/bin/bash
#/*
#* com.nathulal.AdBlockToggle
#*
#* Copyright (c) 2009 nathulal <inathulal at gmail.com>. All rights reserved.
#*
#* This file is part of iPhoneAdBlockToggle.
#*
#* iPhoneAdBlockToggle is free software: you can redistribute it and/or modify
#* it under the terms of the GNU General Public License as published by
#* the Free Software Foundation, either version 3 of the License, or
#* (at your option) any later version.
#*
#* iPhoneAdBlockToggle is distributed in the hope that it will be useful,
#* but WITHOUT ANY WARRANTY; without even the implied warranty of
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#* GNU General Public License for more details.
#*
#* You should have received a copy of the GNU General Public License
#* along with iPhoneAdBlockToggle. If not, see <http://www.gnu.org/licenses/>.
#*/
download_update()
{
rm -f /tmp/adblock_hosts
wget "http://hosts-file.net/ad_servers.asp" -O /tmp/adblock_hosts
if [ -f /tmp/adblock_hosts ]; then
FILESIZE=`stat -c %s /tmp/adblock_hosts`
echo "Size of new adblock_hosts file is $FILESIZE bytes"
if [ $FILESIZE -gt 0 ]; then
cat /tmp/adblock_hosts | grep ^127 | grep -v localhost | sed -e 's|^127.0.0.1|0.0.0.0|' \
> /var/mobile/Library/SBSettings/Toggles/AdBlock/AdBlockOn_hosts
fi
rm /tmp/adblock_hosts
fi
}
m_username=`whoami|grep .`
if [ "$m_username" != "root" ]
then
echo "You must be logged in as root."
exit
fi;
if [ ! -f /var/mobile/Library/SBSettings/Toggles/AdBlock/AdBlock.pid ]
then
#download_update
echo "AdBlock On" > /var/mobile/Library/SBSettings/Toggles/AdBlock/AdBlock.pid
rm -f /etc/hosts
if [ -f /private/var/mobile/Library/Preferences/UserHostEntries ]; then
echo "### USERHOSTENTRIES BEGIN ###" >> /etc/hosts
cat /private/var/mobile/Library/Preferences/UserHostEntries >> /etc/hosts
echo "### USERHOSTENTRIES END ###" >> /etc/hosts
fi
cat /var/mobile/Library/SBSettings/Toggles/AdBlock/AdBlockOff_hosts >> /etc/hosts
echo "" >> /etc/hosts
echo "### ADBLOCK HOSTS BEGIN ###" >> /etc/hosts
cat /var/mobile/Library/SBSettings/Toggles/AdBlock/AdBlockOn_hosts >> /etc/hosts
echo "### ADBLOCK HOSTS END ###" >> /etc/hosts
else
rm /var/mobile/Library/SBSettings/Toggles/AdBlock/AdBlock.pid
if [ -f /private/var/mobile/Library/Preferences/UserHostEntries ]
then
cat /private/var/mobile/Library/Preferences/UserHostEntries /var/mobile/Library/SBSettings/Toggles/AdBlock/AdBlockOff_hosts > /etc/hosts
else
cp /var/mobile/Library/SBSettings/Toggles/AdBlock/AdBlockOff_hosts /etc/hosts
fi;
fi;