Introducing XDA:DevCon – A Conference For Developers By Developers
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
dmanbuhnik
Old
#1  
Member - OP
Thanks Meter 0
Posts: 52
Join Date: Jun 2009
Unhappy running scrpit in update.zip

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
 
packetlss
Old
#2  
packetlss's Avatar
Senior Member
Thanks Meter 5
Posts: 220
Join Date: Aug 2009
The recovery images use execv() to call the program. This means that shell scripts are not supported.
Assembly moron / HW tinkerer.

LG Optimus 2X
Google Nexus S
Samsung Galaxy Tab
Google Nexus One
HTC Hero GSM White

gtalk: packetlss@gmail.com
twitter: http://twitter.com/packetlss
 
dmanbuhnik
Old
#3  
Member - OP
Thanks Meter 0
Posts: 52
Join Date: Jun 2009
that doesn't make sense, cyan runs the 'backuptools.sh' in the recovery (the script that backup and restore your close source application)
 
packetlss
Old
#4  
packetlss's Avatar
Senior Member
Thanks Meter 5
Posts: 220
Join Date: Aug 2009
Quote:
Originally Posted by dmanbuhnik View Post
that doesn't make sense, cyan runs the 'backuptools.sh' in the recovery (the script that backup and restore your close source application)
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.
Assembly moron / HW tinkerer.

LG Optimus 2X
Google Nexus S
Samsung Galaxy Tab
Google Nexus One
HTC Hero GSM White

gtalk: packetlss@gmail.com
twitter: http://twitter.com/packetlss
 
dmanbuhnik
Old
#5  
Member - OP
Thanks Meter 0
Posts: 52
Join Date: Jun 2009
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
 
dmanbuhnik
Old
#6  
Member - OP
Thanks Meter 0
Posts: 52
Join Date: Jun 2009
help? pls....
 
cauli
Old
#7  
Senior Member
Thanks Meter 0
Posts: 316
Join Date: Mar 2010
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?
 
dmanbuhnik
Old
#8  
Member - OP
Thanks Meter 0
Posts: 52
Join Date: Jun 2009
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")
 
cauli
Old
#9  
Senior Member
Thanks Meter 0
Posts: 316
Join Date: Mar 2010
Quote:
Originally Posted by dmanbuhnik View Post
3) i'm building this script for the future, i want to be ready if someone will decided to move the directories around
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
 
Droidzone
Old
#10  
Droidzone's Avatar
Recognized Developer
Thanks Meter 2059
Posts: 5,454
Join Date: Sep 2010
Location: Kerala

 
DONATE TO ME
Quote:
Originally Posted by dmanbuhnik View Post
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")
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?

 
Post Reply+
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Go to top of page...