Related
I've seen other post, so I thought I should share this with anyone who may be interested.
This script is based on "Adblock script" by Adrian Jon Kriel, http://lifehacker.com/5060053/set-up-universal-ad-blocking-through-your-router
This will only work on rooted phone.
Download: adblock.sh
or copy-n-paste source code below
Code:
#!/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: Testing for Internet Connection..."
if ping -c 1 yahoo.com > /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 [email protected] Source"
eval GOTSOURCE="1"
else
echo "ADBLOCK: Failed to download [email protected] 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: Remounting /system to read-write"
mount -o remount,rw /dev/block/mtdblock3 /system
rm /system/etc/hosts
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
be sure to place this script at root level of sdcard
Example:
Code:
/sdcard/adblock.sh
Open terminal emulator and excute as following.
Code:
$ su
# cd /sdcard
# sh adblock.sh
I Hope you find this useful. Enjoy!
Just wondering, is this all your own shell code? Looks awfully similar to one I used on my router -- variable names and all.
Either way -- good post. Just wondering since you posted it with GPL and all
Edit: Ah, here is the script I previously used and thought it reminded me of; "Adblock script" by Adrian Jon Kriel, http://lifehacker.com/5060053/set-up-universal-ad-blocking-through-your-router
yes you're right. Mostly is borrowed from tomato firmware forums (can't remember where), however their script is meant for dnsmasq, and I revised this to work with hosts file.
EDIT: Saw your source link, the reason I GPL'ed this script to prevent anyone else taking credit for Adrain Jon Kriel's work, I'll revision first post to give him proper credit thanks for link.
firestrife23 said:
yes you're right. Mostly is borrowed from tomato firmware forums, however their script is meant for dnsmasq, and I revised this to work with hosts file.
Click to expand...
Click to collapse
Ahh, just wondering -- good work with it. Though I'd assume the original other (no matter how much you edited it) would like a little credit on it too
how/why is this better than the app? doesn't it do the same thing?
Lieu10ant said:
how/why is this better than the app? doesn't it do the same thing?
Click to expand...
Click to collapse
It does the same as app, however my script is only 4.3kb.
Basically it combine multiple hosts source into single hosts file by clean up garbage such as ^M (MS-DOS end of line) which can be quite problematic for linux/unix in general (yes Android is Linux), and trimmed down to much smaller file size by removing comments, duplications, and finally sort everything by 0-9 and A-Z order to speed up hosts look up.
Does this need to be rerun on any sort of schedule? Or will it take care of looking for new address to add to the hosts file?
Love this script, thanks for sharing!
nice work!
way to condense this down to nearly nothing. Quick question, does this autoupdate? Do I have to run this from time to time to update the hosts its blocking?
Thanks!
No it does not auto update, you can just rerun the script yourself.
autoupdate
so then, how could we force this to run at boot so Android will always be adfree? Could we add a line to userinit.sh?
innerspace said:
so then, how could we force this to run at boot so Android will always be adfree? Could we add a line to userinit.sh?
Click to expand...
Click to collapse
I have my doubts that the internet connection is live until phone is fully booted. And it certainly is not if you have SIM card pin enabled.
We have 3 options from where I sit.
We can add it to the userinit.sh (or user.conf) file(s) and perhaps set it up with a delay (since most of our internet won't be on right when the phone is booting) ie sleep 120 like from this post.
We can use Autostart from the Market.
We can just run the script manually.
Thanks, works nice.
(nice name above me )
I keep getting an error, it can't connect to any of the sites to download the files... like it says 'bad address' and then 'error files not downloaded'
Can someone please help me?
I am running JACHero v1.4
I'm pretty sure I'm trying this wrong.
I used the autostart app and created a .sh file (I'll post the content at the end of this) and the corresponding directory in data.
I started the phone and got a SU permission request (which I expected). But I don't know if the script ran right.
BTW I created this script using notepad in XP. Probably not the smartest choice, but I really don't know what I'm doing and figured I'd give it a shot.
Here is the content of the .sh file I created:
--------------------------------------
setPriorityLater()
{
# sleep for 2 minutes
sleep 120
# phone and all processes should surely by up by now
su
cd /sdcard
sh adblock.sh
}
setPriorityLater > /dev/null 2>&1 &
-----------------------------------------
I copied the text of the script from http://forum.xda-developers.com/showpost.php?p=4355721&postcount=78 and inserted the commands to run this script.
Be honest, I screwed it up didn't I?
Couldn't you just use Gscript and run it every so often?
Gilliland12 said:
I'm pretty sure I'm trying this wrong.
I used the autostart app and created a .sh file (I'll post the content at the end of this) and the corresponding directory in data.
I started the phone and got a SU permission request (which I expected). But I don't know if the script ran right.
BTW I created this script using notepad in XP. Probably not the smartest choice, but I really don't know what I'm doing and figured I'd give it a shot.
Here is the content of the .sh file I created:
--------------------------------------
setPriorityLater()
{
# sleep for 2 minutes
sleep 120
# phone and all processes should surely by up by now
su
cd /sdcard
sh adblock.sh
}
setPriorityLater > /dev/null 2>&1 &
-----------------------------------------
I copied the text of the script from http://forum.xda-developers.com/showpost.php?p=4355721&postcount=78 and inserted the commands to run this script.
Be honest, I screwed it up didn't I?
Click to expand...
Click to collapse
It's recommended to use notepad++. Trust me. It's much better than notepad.
cannot create hosts
C:\Documents and Settings\Administrator\Desktop>adb shell
# sh /sdcard/adblock.sh
sh /sdcard/adblock.sh
ADBLOCK: Testing for Internet Connection...
ADBLOCK: Success
/sdcard/adblock.sh: cannot create hosts: read-only file system
/sdcard/adblock.sh: cannot create hosts: read-only file system
ADBLOCK: Failed to download MVPS Source
/sdcard/adblock.sh: cannot create hosts: read-only file system
ADBLOCK: Failed to download [email protected] Source
ADBLOCK: Adding Mobile Ads to blocklist
/sdcard/adblock.sh: cannot create hosts: read-only file system
/sdcard/adblock.sh: cannot create hosts: read-only file system
/sdcard/adblock.sh: cannot create hosts: read-only file system
ADBLOCK: Error Files Not Downloaded
ADBLOCK: Remounting /system to read-write
rm: cannot remove '/system/etc/hosts': No such file or directory
cp: cannot stat '/sdcard/hosts': No such file or directory
ADBLOCK: Updated Hosts
ADBLOCK: Remounting /system to read-only
rm: cannot remove 'hosts': No such file or directory
#
Binary100100 said:
C:\Documents and Settings\Administrator\Desktop>adb shell
# sh /sdcard/adblock.sh
sh /sdcard/adblock.sh
ADBLOCK: Testing for Internet Connection...
ADBLOCK: Success
/sdcard/adblock.sh: cannot create hosts: read-only file system
/sdcard/adblock.sh: cannot create hosts: read-only file system
ADBLOCK: Failed to download MVPS Source
/sdcard/adblock.sh: cannot create hosts: read-only file system
ADBLOCK: Failed to download [email protected] Source
ADBLOCK: Adding Mobile Ads to blocklist
/sdcard/adblock.sh: cannot create hosts: read-only file system
/sdcard/adblock.sh: cannot create hosts: read-only file system
/sdcard/adblock.sh: cannot create hosts: read-only file system
ADBLOCK: Error Files Not Downloaded
ADBLOCK: Remounting /system to read-write
rm: cannot remove '/system/etc/hosts': No such file or directory
cp: cannot stat '/sdcard/hosts': No such file or directory
ADBLOCK: Updated Hosts
ADBLOCK: Remounting /system to read-only
rm: cannot remove 'hosts': No such file or directory
#
Click to expand...
Click to collapse
I had the same problem, thn i moved:
Code:
echo "ADBLOCK: Remounting /system to read-write"
mount -o remount,rw /dev/block/mtdblock3 /system
at the beginning of the script, and now it works fine
Hi,
I'm creating a simple update pack to replace fonts and apn
all very basic but for some reason i can get a clean run of a script that i want to run
this is the script
Code:
#!/sbin/sh
#
# This script gets 1 parameter - the directory which the new files are in (under /cache)
# he then go over each of them, finding where thier matching file in /system and /data are
# and replace them with the new file
# after going over the list of files we then delete the /cache/<name_of_dir>
#
# the purpose of this script is to not hardcoded the path of files we want to replace
#
# Created by dmanbuhnik
# Version 0.5 (12/03/2010)
find_replace_file() {
nfile=$1
dir=$2
echo $nfile
echo $dir
rfile=`find /system -name "$nfile"`
cp /cache/$dir/$nfile rfile
rfile=`find /data -name "$1"`
cp /cache/$dir/$nfile rfile
}
mount /system
mount /data
dir=$1
echo $dir
cd /cache/$dir
pwd
for from_list in * ; do
echo $from_list
find_replace_file $from_list $dir
done
rm -rf /cache/$dir
exit 0
and i'm calling it from the upate-script by:
Code:
show_progress 0.1 0
copy_dir PACKAGE:cache CACHE:
show_progress 0.2 0
run_program PACKAGE:listInstall.sh new_fonts
show_progress 0.2 0
run_program PACKAGE:listInstall.sh new_apn
but i get failures when trying to flash it:
Code:
E:Error in listInstall.sh
(Status 65280)
E:Failure at line 5:
run_program PACKAGE:listInstall.sh new_fonts
when running the script line by line - all good
but when I try to run the script i get weird failures:
Code:
: not foundh: line 12:
new_apn
': No such file or directory
': No such file or directory
: not foundh: line 22: }
: not foundh: line 23:
in /etc/fstabind /system
in /etc/fstabind /data
: not foundh: line 26:
new_apn
: not foundh: line 29:
/sdcard/g.sh: cd: line 30: can't cd to /cache/new_apn
: not foundh: line 31: pwd
/sdcard/g.sh: line 32: syntax error: unexpected word (expecting "do")
please help
The recovery images use execv() to call the program. This means that shell scripts are not supported.
that doesn't make sense, cyan runs the 'backuptools.sh' in the recovery (the script that backup and restore your close source application)
dmanbuhnik said:
that doesn't make sense, cyan runs the 'backuptools.sh' in the recovery (the script that backup and restore your close source application)
Click to expand...
Click to collapse
Indeed, you're correct. I was looking at the wrong code
Anyway, make sure that the script runs outside of the updatescript properly. Esp. be vary ofc the commands you use. The recovery environment is based on busybox versions of the commands, and the might not behave exactly the same way you expect them to do.
i tried running it as a normal script in recovery env
you can see that errors in the last part of my first thread
i don't understand why they are errors, as i said when running the script commands manually (line by line) everything is great, so i know the shell support the commands but
btw, thank you for you help
help? pls....
Did you get this fixed? I'm not familiar with shell scripting, hence I might be more hindrance than help, but no one else is posting, so...
1) I'd be inclined to rewrite the script to handle errors, rather than just assume they won't occur.
2) Why not upload a copy of your update.zip & maybe someone will try to test it? (obviously after backing up their own /system & /data)
3) In the new_font case, say, I understand looking in /system but why/where is there also a copy expected within /data to replace?
4) In find_replace_file, why is the 2nd -name pattern "$1" rather than "$nfile"
5) In find_replace_file, why is the destination for both cp's rfile & not $rfile?
not yet.
1) no problem but i can't seems to even run the script correctly, after i do i will handle everything
2) the update.zip is not important, the update-script is not running as it should in the recovery as a stand alone script, so lets fix that first and then launch it from the update.zip
3) i'm building this script for the future, i want to be ready if someone will decided to move the directories around
4) you are correct, i will fix that
5) mmm, that looks stupid... let me fix that
ok, no change
running the script in the recovery with:
Code:
/sdcard/listInstall new_fonts
will get:
Code:
/sbin/sh: ./listInstall.sh: not found
if i try with 'sh /sdcard/listInstall':
Code:
: not found.sh: line 12:
': No such file or directory
': No such file or directory
: not found.sh: line 22: }
: not found.sh: line 23:
in /etc/fstabind /system
in /etc/fstabind /data
: not found.sh: line 26:
: not found.sh: line 29:
listInstall.sh: cd: line 30: can't cd to /cache/
: not found.sh: line 31: pwd
listInstall.sh: line 32: syntax error: unexpected word (expecting "do")
dmanbuhnik said:
3) i'm building this script for the future, i want to be ready if someone will decided to move the directories around
Click to expand...
Click to collapse
The script is looking for files in locations in which they currently don't exist (as you say above, for the future), but then assumes find has returned the location of a file. You need to catch & deal with the cases where it says the file doesn't exist.
A general rule in programming is to construct your own code with rigour, but make no assumptions about your input being well behaved, including data you receive from external function calls. An obvious corollary is that you must handle errors.
Generous debug info is always a good idea when you get into a situation like this too.
BTW I've been stuck staring at even shorter sections of my own code in the past which I 'knew' should work. It's all part of the fun
dmanbuhnik said:
not yet.
1) no problem but i can't seems to even run the script correctly, after i do i will handle everything
2) the update.zip is not important, the update-script is not running as it should in the recovery as a stand alone script, so lets fix that first and then launch it from the update.zip
3) i'm building this script for the future, i want to be ready if someone will decided to move the directories around
4) you are correct, i will fix that
5) mmm, that looks stupid... let me fix that
ok, no change
running the script in the recovery with:
Code:
/sdcard/listInstall new_fonts
will get:
Code:
/sbin/sh: ./listInstall.sh: not found
if i try with 'sh /sdcard/listInstall':
Code:
: not found.sh: line 12:
': No such file or directory
': No such file or directory
: not found.sh: line 22: }
: not found.sh: line 23:
in /etc/fstabind /system
in /etc/fstabind /data
: not found.sh: line 26:
: not found.sh: line 29:
listInstall.sh: cd: line 30: can't cd to /cache/
: not found.sh: line 31: pwd
listInstall.sh: line 32: syntax error: unexpected word (expecting "do")
Click to expand...
Click to collapse
I know this is old, but I was wondering if anyone can solve this issue.
I have a similiar problem.
If I run the following from recovery after mounting /system:
Code:
if [ -s /system/etc/data2sd.on ]; then echo Presemt; else echo No; fi;
I get the output: Present
However, if I put it in a script:
Code:
#!/sbin/sh
if [ -s /system/etc/data2sd.on ];
then
mkdir /tmp/data2sd ;
cp /system/etc/data*.* /tmp/data2sd/ ;
echo "Data2SD exists" > /tmp/data2sd.os ;
else
#Do nothing
echo "Do nothing" ;
fi;
Code:
I get this error:
/tmp # sh /tmp/test.sh
sh /tmp/test.sh
: not foundh: line 10:
: not foundh: line 10:
Do nothing
: not foundh: line 10:
/tmp #
The line 10 seems to be fi;
Can anyone good at this explain?
Hi,
I have a problem executing one script.
I put my script as /system/bin/toleinit with 775 permissions:
Code:
# ls -l /system/bin/toleinit
ls -l /system/bin/toleinit
-rwxrwxr-x root root 373 2010-03-22 02:17 toleinit
Well, when I try to run this script I get a "not found" error:
Code:
# /system/bin/toleinit
/system/bin/toleinit
/system/bin/toleinit: not found
If I run it with "sh" the script works fine:
Code:
# sh /system/bin/toleinit
sh /system/bin/toleinit
+++ Wellcome to toleinit Script
How to run the script directly? (without write "sh" before)
The same error occurs when I run "busybox run-parts dirname", I get a "not found" error for each script file in the directory.
Thanks in advance.
write this on the very first line of your script :
#!/bin/sh
Click to expand...
Click to collapse
The first line is:
Code:
#!/system/bin/sh
I think that is correct. or not?
Argh!!
The problem is solved when I save the script file in UTF-8 and not ANSI. Now I can run the script without problems.
Thanks anyway.
I'm trying to run scripts in recovery and running into some trouble.
Example1:
Code:
#!/sbin/sh
if [ -s /system/etc/data2sd.on ]; then echo Presemt; else echo No; fi;
Output:
Code:
sh /tmp/test.sh
Presemt
Example2:
Code:
#!/sbin/sh
if [ -s /system/etc/data2sd.on ];
then
echo Presemt;
else
echo No;
fi;
Output
Code:
sh /tmp/test.sh
: not foundh: line 7:
: not foundh: line 7:
No
: not foundh: line 7:
/tmp #
I've been trying out different spacing, and punctuation; still cannot work this out. I'm running it on a Desire. If anyone could offer some suggestions on a fix, I'd be thankful. I've got a very complex script if/else script which runs fine when run in init.d as busybox runparts. However this simple script doesnt run in recovery without errors!
droidzone said:
Example2:
Code:
#!/sbin/sh
if [ -s /system/etc/data2sd.on ] [B]# remove the ;[/B]
then
echo Presemt;
else
echo No;
fi [B]# remove the ;[/B]
Click to expand...
Click to collapse
This should work
Benee said:
This should work
Click to expand...
Click to collapse
Thanks for the reply!
But..now it gives:
Code:
cat test.sh
#!/sbin/sh
if [ -s /system/etc/data2sd.on ];
then
echo Presemt;
else
echo No;
fi
#test/tmp # sh /tmp/test.sh
sh /tmp/test.sh
[B]/tmp/test.sh: line 8: syntax error: unexpected end of file (expecting "fi")[/B]
/tmp #
Another one:
Code:
#!/sbin/sh
#Restore backed up Settings
if [ -s /tmp/data2sd/data2sd.on ]; then cp /tmp/data2sd/*.* /system/etc/ ; echo "All backed up"; else echo "Not backing up"; fi;
The above script works perfectly.
The one below gives an error:
Code:
#!/sbin/sh
#Restore backed up Settings
if [ -s /tmp/data2sd/data2sd.on ];
then
cp /tmp/data2sd/*.* /system/etc/ ;
echo "All backed up" ;
else
echo "Not backing up" ;
fi ;
I'm wondering whether recovery sh does not support multiline if/else statements.
/tmp/data2sd # sh /tmp/test.sh
sh /tmp/test.sh
: not foundh: line 9:
: not foundh: line 9:
Not backing up
: not foundh: line 9:
/tmp/data2sd #
Click to expand...
Click to collapse
droidzone said:
Code:
if [ -s /system/etc/data2sd.on ] [B]No ; here[/B]
then
echo Presemt;
else
echo No;
fi
Click to expand...
Click to collapse
droidzone said:
Another one:
Code:
#!/sbin/sh
#Restore backed up Settings
if [ -s /tmp/data2sd/data2sd.on ] [B]No ; here[/B]
then
cp /tmp/data2sd/*.* /system/etc/ ;
echo "All backed up" ;
else
echo "Not backing up" ;
fi [B]No ; here[/B]
Click to expand...
Click to collapse
If, then, else fi lines don't end with a ; .
Benee said:
If, then, else fi lines don't end with a ; .
Click to expand...
Click to collapse
Thanks again..I've modified it as:
Code:
#!/sbin/sh
#Restore backed up Settings
if [ -s /tmp/data2sd/data2sd.on ]
then
cp /tmp/data2sd/*.* /system/etc/ ;
echo "All backed up" ;
else
echo "Not backing up" ;
fi
This gives this error:
/tmp/data2sd # sh /tmp/test.sh
sh /tmp/test.sh
sh: missing ]
: not foundh: line 9:
Not backing up
: not foundh: line 9:
/tmp/data2sd #
Click to expand...
Click to collapse
This is weird. I cant understand why it wont run smoothly. If I put it all on one line, it runs correctly.
droidzone said:
Code:
#!/sbin/sh
#Restore backed up Settings
if [ -s /tmp/data2sd/data2sd.on ]
then
cp /tmp/data2sd/*.* /system/etc/
echo "All backed up"
else
echo "Not backing up"
fi
Click to expand...
Click to collapse
Man I'm stupid Too early in the morning for me. No need for ; at all ...
Benee said:
Man I'm stupid Too early in the morning for me. No need for ; at all ...
Click to expand...
Click to collapse
Code:
#!/sbin/sh
#Restore backed up Settings
if [ -s /tmp/data2sd/data2sd.on ]
then
cp /tmp/data2sd/*.* /system/etc/
echo "All backed up"
else
echo "Not backing up"
fi
Now the error code has changed. It's still giving me the wrong output.
sh /tmp/test.sh
sh: missing ]
: not foundh: line 9:
Not backing up
~ # sh /tmp/test.sh
sh /tmp/test.sh
sh: missing ]
: not foundh: line 9:
Not backing up
~ #
Click to expand...
Click to collapse
I then put a ; after the ]
Code:
#!/sbin/sh
#Restore backed up Settings
if [ -s /tmp/data2sd/data2sd.on ];
then
cp /tmp/data2sd/*.* /system/etc/
echo "All backed up"
else
echo "Not backing up"
fi
This gives:
sh /tmp/test.sh
: not foundh: line 9:
: not foundh: line 9:
Not backing up
Click to expand...
Click to collapse
droidzone said:
Code:
#!/sbin/sh
#Restore backed up Settings
if [ -s /tmp/data2sd/data2sd.on ]
then
cp /tmp/data2sd/*.* /system/etc/
echo "All backed up"
else
echo "Not backing up"
fi
...
Click to expand...
Click to collapse
hrmm maybe some debugging trys.
Code:
if [ -s /tmp/data2sd/data2sd.on ]
then
echo "All backed up"
else
echo "Not backing up"
fi
Try this
Benee said:
hrmm maybe some debugging trys.
Code:
if [ -s /tmp/data2sd/data2sd.on ]
then
echo "All backed up"
else
echo "Not backing up"
fi
Try this
Click to expand...
Click to collapse
That gives this:
sh /tmp/test.sh
/tmp/test.sh: line 8: syntax error: unexpected "fi" (expecting "then")
Click to expand...
Click to collapse
droidzone said:
Thanks again..I've modified it as:
Code:
#!/sbin/sh
#Restore backed up Settings
if [ -s /tmp/data2sd/data2sd.on ]
then
cp /tmp/data2sd/*.* /system/etc/ ;
echo "All backed up" ;
else
echo "Not backing up" ;
fi
Click to expand...
Click to collapse
Tangent: unless I'm mistaken, *.* will not backup everything but only files with a "." in their name. You should use 'cp /tmp/data2sd/* /system/etc/' instead.
Also, isn't it 'cp SOURCE DESTINATION' ? Do you really want to back up from /tmp/data2sd to /system/etc ?
fake edit: ah, just saw the comment . Then it should be "All restored"/"Not restoring" right ?
Code:
if [ -s /tmp/data2sd/data2sd.on ]; then
echo "All backed up"
else
echo "Not backing up"
fi
again
10 Chars
SebHTCHero said:
Tangent: unless I'm mistaken, *.* will not backup everything but only files with a "." in their name. You should use 'cp /tmp/data2sd/* /system/etc/' instead.
Also, isn't it 'cp SOURCE DESTINATION' ? Do you really want to back up from /tmp/data2sd to /system/etc ?
fake edit: ah, just saw the comment . Then it should be "All restored"/"Not restoring" right ?
Click to expand...
Click to collapse
You're right. I was kind of going along with the msdos style wildcards. But my files (data2sd.ver, data2sd.log) do have a . in between.
Yup, I'm indeed restoring from tmp. Since it was a debug, I wasnt paying attention to the echo commands. It's the second part of a script, the first part of which backs up these files to tmp before system format, and then restores them after. Unfortunately, as soon as I make it multiline, it fails with some error.
Benee said:
Code:
#!/sbin/sh
#Restore backed up Settings
if [ -s /tmp/data2sd/data2sd.on ]; then
echo "All backed up"
else
echo "Not backing up"
fi
again
10 Chars
Click to expand...
Click to collapse
Again
Code:
sh test.sh
test.sh: line 7: syntax error: unexpected "fi" (expecting "then")
droidzone said:
Again
Code:
sh test.sh
test.sh: line 7: syntax error: unexpected "fi" (expecting "then")
Click to expand...
Click to collapse
In my kernel compile script on line 63 there is a similar if. It should work. I don't know what is wrong anymore. Really strange
Compile script
Benee said:
In my kernel compile script on line 63 there is a similar if. It should work. I don't know what is wrong anymore. Really strange
Compile script
Click to expand...
Click to collapse
Thanks anyway.
I noticed that your script uses bash as the script debugger
#!/bin/bash
Could there be a difference in these two? I dont think this is it either. I saw similiar if/else script in Firerat's MTD patcher script too, and that seems to work.
Thanks a lot anyway..I'll just put the script on one big line.
droidzone said:
Thanks anyway.
I noticed that your script uses bash as the script debugger
#!/bin/bash
Could there be a difference in these two? I dont think this is it either. I saw similiar if/else script in Firerat's MTD patcher script too, and that seems to work.
Thanks a lot anyway..I'll just put the script on one big line.
Click to expand...
Click to collapse
hehe yeah... the sbin and bin shouldn't fix the problem. I can't find the error. Everything is looking good. But yeah this is a solution
What editor are you using for the multi-line script? Are you saving it in DOS format? bash won't read the \r\n from a Windows/DOS text editor at the end of lines if you're using Notepad, etc.
romracer said:
What editor are you using for the multi-line script? Are you saving it in DOS format? bash won't read the \r\n from a Windows/DOS text editor at the end of lines if you're using Notepad, etc.
Click to expand...
Click to collapse
Used Notepad++. It seems to be good enough for update-scripts.
droidzone said:
Used Notepad++. It seems to be good enough for update-scripts.
Click to expand...
Click to collapse
Maybe, but update-scripts aren't BASH scripts. BASH does care about line endings; I don't know whether Amend/Edify do or not.
Anyway, Notepad++ can save with UNIX line endings. I don't use it, but this forum post suggests you look in the options:
http://www.phpbb.com/community/viewtopic.php?f=71&t=2083365
Notepad++ > Settings > Preferences > New Document/Default Directory > Format > Unix.
Other Google searches indicate there may be a conversion option under the Edit or Format menus.
As it is my first message, I have permissions only to post messages here.
I want to run Backtrack 5 on my Gratia. I installed Debdroid as written at gitbrew's website[/url]
I use oririnal BT image from this website.
I renamed btandr35.img to debian.img to make no changes to .conf file.
After "mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system", "export ...", "su", "bash" I've got this error
localhost / # debshell bash
/system/bin/debshell: line 17: /data/local/debian/etc/hostname: No such file or directory
Opening debdroid chroot on loop255
chroot: can't execute 'bash' No such file or directory
Exiting debdroid chroot - System is still running
localhost / #
Anybody knows solution?
Syavick said:
As it is my first message, I have permissions only to post messages here.
I want to run Backtrack 5 on my Gratia. I installed Debdroid as written at gitbrew's website[/url]
I use oririnal BT image from this website.
I renamed btandr35.img to debian.img to make no changes to .conf file.
After "mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system", "export ...", "su", "bash" I've got this error
localhost / # debshell bash
/system/bin/debshell: line 17: /data/local/debian/etc/hostname: No such file or directory
Opening debdroid chroot on loop255
chroot: can't execute 'bash' No such file or directory
Exiting debdroid chroot - System is still running
localhost / #
Anybody knows solution?
Click to expand...
Click to collapse
I have the exact same problem as you, I am running the Droid 2 CM 7 Nightly build (latest). I have bash, etc. Bash exists in two places: /system/xbin and /etc/bash, but even using the command (after you are in bash) "chroot /data/local/debian /system/xbin/bash" (chroot command goes: "chroot directory [FILE ARGS]") and still got the same exact error: chroot: can't execute 'bash': No such file or directory.
I have used two different GB roms (leaked motorola stock and CM 7). I must have spent over a hundred hours this week looking for and testing out possible solutions, to no avail.
What are we missing?
/system/bin/debshell: line 17: /data/local/debian/etc/hostname: No such file or directory
I fixed this error by creating empty file "hostname" in "etc" directory. But I still have chroot error. I made some experiments with copying bash to different folders - no results.
Yeah that part of the problem was an easy fix, and even though I can use the bash command wherever I am in my filesystem as well as when I am using bash, it seems that chroot cannot find the bash command. Trouble is, I can't find chroot, and I would assume that chroot would be in the same directories as bash. Even using the command ls /*/chroot gives me nothing.
Nothing works as before!