[G1 Android Development] woSaa:
i move the "Remounting /system to read-write" permission to head of script.

it´s works fine for me!

thanks to rastacre

#!/bin/sh
## Adblock script for G1
## By Jason Driver
## firestrife23(at)gmail(dot)com
## Version 1.1
## May 19 2009
##
## This script is based on "Adblock script" by Adrian Jon Kriel,
## http://lifehacker.com/5060053/set-up-universal-ad-blocking-through-your-routerr
##
## This script is free: 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.
##
## This program 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 this program. If not, see <http://www.gnu.org/licenses/>.

## Required AD Blocklist
eval MVPSSOURCE="1"	## default 1
eval PGLSOURCE="1"	## default 1

## Extra AD Blocklist, Extremist Only
## HUGE FILE!! your G1 may experience performance hit!!
eval HSFSOURCE="0"	## default 0
eval HFPSOURCE="0"	## default 0

## DO NOT EDIT BELOW, UNLESS YOU KNOW WHAT YOU'RE DOING!!!!

eval GENFILE="hosts"

eval MVPSOURCEFILE="http://www.mvps.org/winhelp2002/hosts.txt"
eval PGLSOURCEFILE="http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts"
eval HSFSOURCEFILE="http://www.it-mate.co.uk/downloads/hosts.txt"
eval HFPSOURCEFILE="http://hostsfile.mine.nu/Hosts"

echo "ADBLOCK: Remounting /system to read-write"
mount -o remount,rw /dev/block/mtdblock3 /system

echo "ADBLOCK: Testing for Internet Connection..."
if ping -c 1 google.de > /dev/null; then
echo "ADBLOCK: Success"

eval GOTSOURCE="0"
echo "" > $GENFILE
## download
if [ "$MVPSSOURCE" = "1" ] ; then
if wget -q $MVPSOURCEFILE -O - >> $GENFILE ; then
echo "ADBLOCK: Downloaded MVPS Source"
eval GOTSOURCE="1"
else
echo "ADBLOCK: Failed to download MVPS Source"
fi
fi
if [ "$PGLSOURCE" = "1" ] ; then
if wget -q $PGLSOURCEFILE -O - >> $GENFILE ; then
echo "ADBLOCK: Downloaded pgl@yoyo.org Source"
eval GOTSOURCE="1"
else
echo "ADBLOCK: Failed to download pgl@yoyo.org Source"
fi
fi
if [ "$HSFSOURCE" = "1" ] ; then
if wget -q $HSFSOURCEFILE -O - >> $GENFILE ; then
echo "ADBLOCK: Downloaded I.T. Mate Group Source"
eval GOTSOURCE="1"
else
echo "ADBLOCK: Failed to download I.T. Mate Group Source"
fi
fi
if [ "$HFPSOURCE" = "1" ] ; then
if wget -q $HFPSOURCEFILE -O - >> $GENFILE ; then
echo "ADBLOCK: Downloaded Hosts File Project Source"
eval GOTSOURCE="1"
else
echo "ADBLOCK: Failed to download Host File Project Source"
fi
fi

echo "ADBLOCK: Adding Mobile Ads to blocklist"
echo '127.0.0.1 p.admob.com' >> $GENFILE
echo '127.0.0.1 analytics.admob.com' >> $GENFILE
echo '127.0.0.1 r.admob.com' >> $GENFILE

if [ "$GOTSOURCE" = "1" ]; then
echo "ADBLOCK: Got Source Files"

echo "ADBLOCK: Stripping Source Files"
sed -i -e '/^[0-9A-Za-z]/!d' $GENFILE
sed -i -e '/%/d' $GENFILE
sed -i -e 's/[[:cntrl:][:blank:]]//g' $GENFILE
sed -i -e 's/^[ \t]*//;s/[ \t]*$//' $GENFILE

echo "ADBLOCK: Sanitize, and Optimising"
sed -i -e 's/[[:space:]]*\[.*$//' $GENFILE
sed -i -e 's/[[:space:]]*\].*$//' $GENFILE
sed -i -e '/[[:space:]]*#.*$/ s/[[:space:]]*#.*$//' $GENFILE
sed -i -e '/^$/d' $GENFILE
sed -i -e 's/127.0.0.1/127.0.0.1 /g' $GENFILE
sed -i -e 's/www.//g' $GENFILE

echo "ADBLOCK: Removing Duplicates (Resource Friendly)"
cat $GENFILE | sort -u > $GENFILE.new
mv $GENFILE.new $GENFILE

## including important informations
sed -i -e '1i127.0.0.1 localhost' $GENFILE
sed -i -e '2i##' $GENFILE
sed -i -e '3i##-----------------------------------------' $GENFILE
sed -i -e '4i## Generated by Adblock script v1.1	' $GENFILE
sed -i -e '5i##-----------------------------------------' $GENFILE
sed -i -e '6i##' $GENFILE

## removing last line (garbage)
sed -i -e '$d' $GENFILE

## info section
echo "ADBLOCK: Unique Hosts Blocked" $(awk 'END { print NR-6 }' $GENFILE)
else
echo "ADBLOCK: Error Files Not Downloaded"
fi
else
echo "ADBLOCK: Error No Internet"
fi

## replacing old hosts with new hosts file
echo "ADBLOCK: Remove old host"
rm /system/etc/hosts
echo "ADBLOCK: Copy new Host"
cp /sdcard/hosts /system/etc/hosts
echo "ADBLOCK: Updated Hosts"
echo "ADBLOCK: Remounting /system to read-only"
mount -o remount,ro /dev/block/mtdblock3 /system
rm $GENFILE