[HOW TO] Extract rom.zip from RUU.exe - Desire General

Hi,
I'm trying to port One V rom to the Desire (my first rom cooking experience).
So I made a small bash script to extract rom.zip file from RUU.exe.
Code:
#!/bin/bash
DEST_DIR=./
WINE_DIR=~/.wine/drive_c/users/*/Temp
ROM=""
PID=0
function usage {
echo "Extract RUU 0.2 of 25 June 2012, by Luc Chante"
echo ""
echo "Usage: extract-ruu [OPTION]... RUU"
echo "Options: "
echo " -d DIR|FILE where to extract the file rom.zip"
echo " ./ by default"
echo " -w DIR directory for wine temporary files"
echo " ~/.wine/drive_c/users/*/Temp by default"
exit 1
}
[ $# -gt 0 ] || usage
while [ $# -gt 1 ]; do
if [ $1 = "-d" ]; then
[ $# -gt 0 ] || usage
shift
DEST_DIR=$1
elif [ $1 = "-w" ]; then
[ $# -gt 0 ] || usage
shift
WINE_DIR=$1
fi
shift
done
[ $# -gt 0 ] || usage
if [ ! -d $WINE_DIR ]; then ls -d $WINE_DIR; exit 1; fi
wine $1 &
PID=$!
TMP=`mktemp`
while [ ${#ROM} -eq 0 ]; do
ROM=`find $WINE_DIR -type f -cnewer $TMP -name rom.zip`
done
kill -9 $PID
if [ -f $ROM ]; then
cp -i $ROM $DEST_DIR
echo "Rom extracted"
else
echo "Rom not found"
fi
Put these lines into a file named extract-ruu, make it executable and juste do :
./extract-ruu RUU_XXXXXXXXXXXXXXX.exe
Wait for a while ... and it's over
don't ever execute with super-user rights !!! (because of kill -9 $PID)
[edit]: version 0.2
- correction of a bug (DEST & DEST_DIR)
- test with a recent file to force 'find' to find the most recent rom.zip file

!!!
I couldn't get the old OpenRUU script to extract my RUU, but this did its job perfectly! props.

Dude you can do it easy with no script, just run the RUU.exe, when the screen pops up with the picture of the device go to the start menu (Windows 7) and type in search *temp* and press enter. When the folder opens search it for ROM.zip and there you go.

CdTDroiD said:
Dude you can do it easy with no script, just run the RUU.exe, when the screen pops up with the picture of the device go to the start menu (Windows 7) and type in search *temp* and press enter. When the folder opens search it for ROM.zip and there you go.
Click to expand...
Click to collapse
The RUU I was using wasn't starting in Vista (I've had too many phone flashing troubles with 7), so I figured I'd just extract it out in Ubuntu. So when I tried that without any script, it decided to crash (which it was going to do anyway since it was missing DLLs) before I could grab the rom.zip out of temp files.
I was tired of it so I just used this so I could just fastboot it and be done.

CdTDroiD said:
Dude you can do it easy with no script, just run the RUU.exe, when the screen pops up with the picture of the device go to the start menu (Windows 7) and type in search *temp* and press enter. When the folder opens search it for ROM.zip and there you go.
Click to expand...
Click to collapse
What about XP?

GrandMstrBud said:
What about XP?
Click to expand...
Click to collapse
Same procedure but you need to go to temp folder in windows XP. Then search for ROM.zip
Sent from my HTC Desire using xda premium

Why you don't port from desire v?
Sent from my HTC Desire using xda premium

rommanager said:
Why you don't port from desire v?
Sent from my HTC Desire using xda premium
Click to expand...
Click to collapse
because its desire v
Sent from my HTC Desire

rommanager said:
Why you don't port from desire v?
Sent from my HTC Desire using xda premium
Click to expand...
Click to collapse
I abandoned the job ...
Desire V seems to be unportable onto the Desire.
And by the way, I'm a linux user, so I don't have Windows 7 "start menu". I made this script under linux.
Maybe the Desire VT328w...

Hey! I was excited to find this thread, because the RUU I'm trying to use will not run or give me the zip in Windows 7, but I am having problems with your script in ubuntu as well. After running ./extract_ruu, I get this:
wine: cannot find L"C:\\windows\\system32\\RUU_PRIMO_C_ICS_40A_Sprint_WWE_VM_1.08.652.6_Radio_1.00.00.0521_2_NV_VM_3.46_0503_PRL61008_release_262414_signed.exe"

dankstahz said:
Hey! I was excited to find this thread, because the RUU I'm trying to use will not run or give me the zip in Windows 7, but I am having problems with your script in ubuntu as well. After running ./extract_ruu, I get this:
wine: cannot find L"C:\\windows\\system32\\RUU_PRIMO_C_ICS_40A_Sprint_WWE_VM_1.08.652.6_Radio_1.00.00.0521_2_NV_VM_3.46_0503_PRL61008_release_262414_signed.exe"
Click to expand...
Click to collapse
Just run it like I said before
Sent from my Galaxy Nexus using Tapatalk 2

The way you said isn't working for me, It be nice if a script was available to extract the rom.zip.
CdTDroiD said:
Just run it like I said before
Sent from my Galaxy Nexus using Tapatalk 2
Click to expand...
Click to collapse

dankstahz said:
Hey! I was excited to find this thread, because the RUU I'm trying to use will not run or give me the zip in Windows 7, but I am having problems with your script in ubuntu as well. After running ./extract_ruu, I get this:
wine: cannot find L"C:\\windows\\system32\\RUU_PRIMO_C_ICS_40A_Sprint_WWE_VM_1.08.652.6_Radio_1.00.00.0521_2_NV_VM_3.46_0503_PRL61008_release_262414_signed.exe"
Click to expand...
Click to collapse
Hi, sorry to answer so late.
Have you a fully functional wine install ?
Because it works just fine for me :
$ extract-ruu RUU_PRIMO_U_ICS_40A_HTC_Europe_1.56.401.2_Radio_20.66.30.0831U_3831.15.00.19_M_release_254696_signed.exe
fixme:storage:create_storagefile Storage share mode not implemented.
/home/luc/.local/bin/extract-ruu : ligne 53 : 5971 Processus arrêté wine $1
Rom extracted
idem with
$ extract-ruu -d test RUU_PRIMO_U_ICS_40A_HTC_Europe_1.56.401.2_Radio_20.66.30.0831U_3831.15.00.19_M_release_254696_signed.exe
Just in case, I'm using archlinux.
[edit]: I also tried with RUU_PRIMO_U_ICS_40A_HTC_Europe_2.22.401.1_Radio_20.76.30.0835U_3831.19.00.120_release_273801_signed.exe succesfully.

How hard is it for someone to use VirtualBox on Linux?
Sent from my Nexus One using Tapatalk 2

eLukas said:
Hi,
Put these lines into a file named extract-ruu, make it executable and juste do :
./extract-ruu RUU_XXXXXXXXXXXXXXX.exe
Wait for a while ... and it's over
don't ever execute with super-user rights !!! (because of kill -9 $PID)
[edit]: version 0.2
- correction of a bug (DEST & DEST_DIR)
- test with a recent file to force 'find' to find the most recent rom.zip file
Click to expand...
Click to collapse
DUDE, you ROCK, your script so saved me and my One X..... Thanks

Thanks, your script saved my one V. Now giving it for repairs. Thank you very much.

anybody any more didn't meet

It says that I can't run this on my 64 bit windows.. is there anything I can do?
eLukas said:
Hi,
I'm trying to port One V rom to the Desire (my first rom cooking experience).
So I made a small bash script to extract rom.zip file from RUU.exe.
Code:
#!/bin/bash
DEST_DIR=./
WINE_DIR=~/.wine/drive_c/users/*/Temp
ROM=""
PID=0
function usage {
echo "Extract RUU 0.2 of 25 June 2012, by Luc Chante"
echo ""
echo "Usage: extract-ruu [OPTION]... RUU"
echo "Options: "
echo " -d DIR|FILE where to extract the file rom.zip"
echo " ./ by default"
echo " -w DIR directory for wine temporary files"
echo " ~/.wine/drive_c/users/*/Temp by default"
exit 1
}
[ $# -gt 0 ] || usage
while [ $# -gt 1 ]; do
if [ $1 = "-d" ]; then
[ $# -gt 0 ] || usage
shift
DEST_DIR=$1
elif [ $1 = "-w" ]; then
[ $# -gt 0 ] || usage
shift
WINE_DIR=$1
fi
shift
done
[ $# -gt 0 ] || usage
if [ ! -d $WINE_DIR ]; then ls -d $WINE_DIR; exit 1; fi
wine $1 &
PID=$!
TMP=`mktemp`
while [ ${#ROM} -eq 0 ]; do
ROM=`find $WINE_DIR -type f -cnewer $TMP -name rom.zip`
done
kill -9 $PID
if [ -f $ROM ]; then
cp -i $ROM $DEST_DIR
echo "Rom extracted"
else
echo "Rom not found"
fi
Put these lines into a file named extract-ruu, make it executable and juste do :
./extract-ruu RUU_XXXXXXXXXXXXXXX.exe
Wait for a while ... and it's over
don't ever execute with super-user rights !!! (because of kill -9 $PID)
[edit]: version 0.2
- correction of a bug (DEST & DEST_DIR)
- test with a recent file to force 'find' to find the most recent rom.zip file
Click to expand...
Click to collapse

This is what i've done: (WIN8x64)
Created a file. Download from the attachments
Place them in C:/cygwin (yes, you need cygwin)
open cygwin, type cd C:/cygwin
Then, ./ruuextract *RUUNAME*
Worked

CdTDroiD said:
Dude you can do it easy with no script, just run the RUU.exe, when the screen pops up with the picture of the device go to the start menu (Windows 7) and type in search *temp* and press enter. When the folder opens search it for ROM.zip and there you go.
Click to expand...
Click to collapse
I tried that with Wildfire S and when I flash it in CWM it says E:Can't open /sdcard/rom.zip (Bad) at the begging.

Related

[TRICK/CWM3/EDIFY] Output to recovery UI from shell script

Took me a few minutes to figure this out, so I thought to share
This is taken from some scripts I use in CF-Root, you might need to change it slightly for other CWM3 kernels (like prefixing busybox to various commands, etc).
updater-script
Assumptions:
- rootfs is mounted as rw, so we can write temporary files anywhere (ram disk)
- you put a "myscript.sh" in the system folder inside the update
All this script does is extract whatever you have in update.zip/system folder to /tmp/update, and run the myscript.sh file.
Code:
ui_print("Extracting files ...");
package_extract_dir("system", "/tmp/update");
set_perm(0, 0, 0755, "/tmp/update/myscript.sh");
run_program("/tmp/update/myscript.sh");
myscript.sh
Assumptions:
- all busybox commands are symlinked in /sbin, this is usually the case for CWM3 kernels
Code:
#!/sbin/busybox sh
# get file descriptor for output
OUTFD=$(ps | grep -v "grep" | grep -o -E "update_binary(.*)" | cut -d " " -f 3);
# same as progress command in updater-script, for example:
#
# progress 0.25 10
#
# will update the next 25% of the progress bar over a period of 10 seconds
progress() {
if [ $OUTFD != "" ]; then
echo "progress ${1} ${2} " 1>&$OUTFD;
fi;
}
# same as set_progress command in updater-script, for example:
#
# set_progress 0.25
#
# sets progress bar to 25%
set_progress() {
if [ $OUTFD != "" ]; then
echo "set_progress ${1} " 1>&$OUTFD;
fi;
}
# same as ui_print command in updater_script, for example:
#
# ui_print "hello world!"
#
# will output "hello world!" to recovery, while
#
# ui_print
#
# outputs an empty line
ui_print() {
if [ $OUTFD != "" ]; then
echo "ui_print ${1} " 1>&$OUTFD;
echo "ui_print " 1>&$OUTFD;
else
echo "${1}";
fi;
}
# --- example usage ---
# empty line after "Extracting ..." from updater-script
ui_print;
# give the user some status
ui_print "doing something (1 of 4)";
# assume this won't take more than 30 seconds
progress 0.25 30;
# you'd do something useful here
sleep 15s;
# update status
ui_print "- done with something (1 of 4)";
# we're done, make sure the progress bar is at 25%
set_progress 0.25;
# empty line
ui_print;
# repeat this a few times ;)
ui_print "doing something (2 of 4)";
progress 0.25 30;
sleep 15s;
ui_print "- done with something (2 of 4)";
set_progress 0.50;
ui_print;
ui_print "doing something (3 of 4)";
progress 0.25 30;
sleep 15s;
ui_print "- done with something (3 of 4)";
set_progress 0.75;
ui_print;
ui_print "doing something (4 of 4)";
progress 0.25 30;
sleep 15s;
ui_print "- done with something (4 of 4)";
set_progress 1.00;
ui_print;
# done !
ui_print "done! rebooting!";
How, what, why ?
While updater-script is fine for a lot of things, like installing a new ROM and whatnot, anything sufficiently complicated still has to be done through shell scripts, because a great many things just cannot be easily done in edify. It's nice to be able to give the user some status when doing these operations. There are modded versions of CWM that make the same thing possible in other ways, like simply writing to STDOUT or STDERR. This requires either a custom update_binary or recovery binary, though.
This works because communication between recovery and update_binary is through a file descriptor (pipe). Recovery runs update_binary with the FD as command line parameter. Because the shell script is run as a child process of update_binary, it can write the same commands to that FD (commands recovery listens for), because child processes inherited FD numbers and access rights.
So, all the script has to do is figure out which FD to write to, and pass it the right commands. Finding the FD isn't difficult, as it is passed on the command line and so is listed in the output of ps. Some grep and cut magic retrieve it. See the OUTFD=$(...) line. The right commands are defined in the functions at the top.
Note: this is all taken from my rfs<=>ext4 conversion script for CF-Root/ext4. Slightly adjusted, hopefully it still works as expected
Enjoy!
Thank you chainfire
Sent from my GT-I9000 using Tapatalk
Thanks for this chainfire.
Precisely what I was looking for! You're my hero today, man!
Hi Chainfire
Thanks for your tricks, I'm using it for an almost bulletproof MTD flash script.
BTW, i'd like to call some set_perm commands. But set_perm isn't a recognized command for update-binary.
IDK if I'm clear.
Do you have some advise on that?
RolluS said:
BTW, i'd like to call some set_perm commands. But set_perm isn't a recognized command for update-binary.
Click to expand...
Click to collapse
I've sort this writing equivalent functions:
Code:
set_perm() { # same as set_perm command in updater-script, for example:
#
# set_perm 0 3003 02750 "/system/bin/netcfg"
#
# sets user:group to 0:3003 and perm to 02750 for the file /system/bin/netcfg
$CHOWN $1:$2 $4
$CHMOD $3 $4
}
set_perm_recursive() { # same as set_perm command in updater-script, for example:
#
# set_perm_recursive 0 2000 0755 0755 "/system/bin"
#
# sets uid:gid to 0:2000 and perm to 0755 for folders and 0755 for files recursively in /system/bin
$CHOWN -R $1:$2 $5
$CHMOD $3 $5
#chmod recursive of folder
$FIND $5/* -type d |while read folder; do
$CHMOD $3 $folder
done
#chmod recursive of files
$FIND $5/* -type f |while read file; do
$CHMOD $4 $file
done
}
There is no error handling (yet), so be carrefull when calling these functions
no FD, no output
Chainfire said:
This works because communication between recovery and update_binary is through a file descriptor (pipe). Recovery runs update_binary with the FD as command line parameter. Because the shell script is run as a child process of update_binary, it can write the same commands to that FD (commands recovery listens for), because child processes inherited FD numbers and access rights.
So, all the script has to do is figure out which FD to write to, and pass it the right commands. Finding the FD isn't difficult, as it is passed on the command line and so is listed in the output of ps. Some grep and cut magic retrieve it. See the OUTFD=$(...) line.
Click to expand...
Click to collapse
finding the FD is difficult on an SGY phone under MT 2.0 kernel, because is is not passed as command line param and therefore not in the ps output.
can anyone give an example of a working FD ?
the expression returns "" on my SGY, and no output is readable from script.
above zip as one file with the (.*) business removed from FD expression in myscript.sh
I don't see that ps gives me a "FD" in its output. whatever that really is. /tmp/recovery.log says that /sbin/recovery has no command line params either on SGY
from recov.log:
I:Set boot command "boot-recovery"
Command: "/sbin/recovery"
there is no FD in the command line ! where is it then ?
I'll test this in a bit. Nice hack b/w.
any news?
Thanks for this trick. What I wanted to do is to redirect stdout (and stderr) of my script to the UI. I know that you can see this in "show logs", but I wanted it to display right during the installation. Here is what I came up with:
Code:
#!/sbin/busybox ash
OUTFD=$(ps | grep -v "grep" | grep -o -E "update_binary(.*)" | cut -d " " -f 3);
/sbin/busybox ash $* 2>&1 |
while read -r line
do
echo "ui_print $line" >&$OUTFD;
echo "ui_print " >&$OUTFD;
done
If you save this as "scripts/stdoutwrapper.sh", you can do something like this:
Code:
package_extract_dir("scripts", "/tmp/update");
set_perm(0, 0, 0755, "/tmp/update/stdoutwrapper.sh");
run_program("/tmp/update/stdoutwrapper.sh", "/tmp/update/myscript.sh", "param1", "param2");
In myscript.sh, use any shell commands. The output will be redirected to the UI. Therefore, you should be able to write scripts that work both on the command line and in recovery without changes.
Please note: As all output will be printed, the tricks with set_progress etc. don't work. It would probably be possible to use a prefix to identify commands that should be executed, not printed, so you could do e.g. "echo '<#>set_progress 0.25'".
what value does OUTFD have? find out like below:
adb shell
ps
then /sbin/recovery might have PID 2166 on SGY phone
su
ls -l --color=never /proc/2166/fd
may give you e.g.
3 -> /dev/tty0
so 3 is your OUTFD !
now grep it accordingly for the script. use MT kernel 2.0 on SGY for above capability
time saver
edify Scripts may be tested by executing update-binary directly:
update-binary version output package
An example would be:
update-binary 2 stdout /sdcard/update.zip
Just noticed Chainfire's ui_print shell script in the latest SuperSU zip, and that lead me here.
Here are some updated versions (for CWM6?); ui_print and set_perm from SuperSU and the other 2 from my tinkering today:
Code:
OUTFD=$2;
ZIP=$3
ui_print() {
echo -ne "ui_print $1\n" > /proc/self/fd/$OUTFD;
echo -ne "ui_print\n" > /proc/self/fd/$OUTFD;
}
set_perm() {
chown $1.$2 $4
chown $1:$2 $4
chmod $3 $4
}
show_progress() { echo "progress $1 $2" > /proc/self/fd/$OUTFD; }
set_progress() { echo "set_progress $1" > /proc/self/fd/$OUTFD; }
ex:
show_progress 1.34 0;
ui_print "Hello world!";
set_progress 0.5;
ui_print " "; #blank line
set_progress 1.34;
ui_print "Done!";
Also worth noting he just uses busybox unzip to extract files from the flashable zip directly and goes from there.
ex:
ui_print "Extracting files!"
cd /tmp
unzip -o "$ZIP"
mai77 said:
what value does OUTFD have?
Click to expand...
Click to collapse
I put ui_print "Test: $OUTFD" in a script and the value of OUTFD appears to increase with every zip flashed.
Not much use knowing it in that case.
Nice work, I used this in my little zip. However, it doesn't work with TWRP. Is there any way to accomplish that?
sorry to put this here but could anyone direct me towards the cwm or TWRP version for "jxjpb" (asia) baseband pls?
klenamenis said:
Nice work, I used this in my little zip. However, it doesn't work with TWRP. Is there any way to accomplish that?
Click to expand...
Click to collapse
TWRP names the extracted update-binary "updater", so you can add something like this (or modify the regex in the existing line):
Code:
[ $OUTFD != "" ] || OUTFD=$(ps | grep -v "grep" | grep -o -E "updater(.*)" | cut -d " " -f 3)
_that said:
TWRP names the extracted update-binary "updater", so you can add something like this (or modify the regex in the existing line):
Code:
[ $OUTFD != "" ] || OUTFD=$(ps | grep -v "grep" | grep -o -E "updater(.*)" | cut -d " " -f 3)
Click to expand...
Click to collapse
Shouldn't be necessary with any reasonably current recovery. That was just a hack Chainfire wrote to get the FD back in the CWM3 days.
All that should be required (and has always worked for me) is to make the update-binary your shell script, then:
Code:
OUTFD=$2;
See my other updated commands above. And some zips I've made which should provide good references for people: Nexus Louder, Xposed Framework Installer, and Nexus BootUnlocker. All available in my Odds and Ends thread, linked in my sig.
osm0sis said:
Shouldn't be necessary with any reasonably current recovery. That was just a hack Chainfire wrote to get the FD back in the CWM3 days.
All that should be required (and has always worked for me) is to make the update-binary your shell script, then:
Code:
OUTFD=$2;
Click to expand...
Click to collapse
Yes, that works if you replace the whole update-binary with a shell script, but this method is for scripts that are called from the updater-script when using a binary updater.
I've recently switched to a shell script as updater too, but I had to write my own zip signing program because busybox unzip was unable to extract files from a zip signed by SignApk.
osm0sis said:
See my other updated commands above. And some zips I've made which should provide good references for people: Nexus Louder, Xposed Framework Installer, and Nexus BootUnlocker. All available in my Odds and Ends thread, linked in my sig.
Click to expand...
Click to collapse
Wow, nice collection! I remember some other posts from you that were very helpful, thanks!
_that said:
Yes, that works if you replace the whole update-binary with a shell script, but this method is for scripts that are called from the updater-script when using a binary updater.
I've recently switched to a shell script as updater too, but I had to write my own zip signing program because busybox unzip was unable to extract files from a zip signed by SignApk.
Wow, nice collection! I remember some other posts from you that were very helpful, thanks!
Click to expand...
Click to collapse
Nice! My misunderstanding then.
And ah yes, the old "1 and 8" issue with unzip. Might be resolved in the latest busybox 1.22.1 but I'm not 100% about that, and it'll be awhile before that makes it into recoveries.
I'd love to get hold of your zip signer if that'd be okay. I have Chainfire's solution, but I was still running into some verification problems (I think) from the MinSignApk whole file resigning.
osm0sis said:
And ah yes, the old "1 and 8" issue with unzip. Might be resolved in the latest busybox 1.22.1 but I'm not 100% about that, and it'll be awhile before it makes it into recoveries.
Click to expand...
Click to collapse
Exactly! I learned a lot about the zip format while researching this.
osm0sis said:
I'd love to get hold of your zip signer if that'd be okay. I have Chainfire's solution, but I was still running into some verification problems (I think) from the MinSignApk whole file resigning.
Click to expand...
Click to collapse
Argh! I saw your original question in that thread but I never found the solution because there were so many pages in between...
I ended up with a hack that appears to resemble Chainfire's minsignapk, but I didn't need to write my own zipadjust. Basically I simply sign the zip normally with signapk, then I unpack and repack the whole archive using 7zip (bonus: slightly better compression), and then I run the whole-zip-signer on the archive.
Here is my SignWholeFile.jar - the source code is just too ugly to publish. View attachment SignWholeFile.jar If you find that it works better than Chainfire's version, I'll clean the source and release it.
This is the script I use for signing:
Code:
#!/bin/sh
KEYDIR=~/android/aosp/build/target/product/security
SIGNAPK=~/android/aosp/prebuilts/sdk/tools/lib/signapk.jar
SIGNWHOLEFILE=~/android/src/signapk/SignWholeFile.jar
java -jar $SIGNAPK -w $KEYDIR/testkey.x509.pem $KEYDIR/testkey.pk8 "$1" "$1.signed.zip"
mv "$1" "$1.unsigned"
signedzip=$(readlink -f "$1.signed.zip")
[ -d /tmp/signapk2 ] && rm -rf /tmp/signapk2
mkdir /tmp/signapk2
pushd /tmp/signapk2
unzip $signedzip
rm $signedzip
7z a -r -mx=9 $signedzip *
#7z a -r $signedzip *
popd
mv "$1.signed.zip" "$1"
java -jar $SIGNWHOLEFILE $KEYDIR/testkey.x509.pem $KEYDIR/testkey.pk8 "$1" "$1"

[SOLVED] Shell scripting problem: unexpected "fi"

SOLVED: The file had Windows EOL formatting. *nix no likely that.
In the init script there are several instances of if statements like this:
Code:
testvar=1
if [ "$testvar" = "1" ] ; then
echo "Testvar is equal to one"
fi
Yet, when I put if statements exactly like this into a shell script and execute them in an adb shell (or connectbox shell), I get the following error:
line 4: syntax error: unexpected "fi" (expecting "then")
I've also taken if statements directly from init and they throw the same error.
Any busybox gurus here know what's up with this?
toadlife said:
In the init script there are several instances of if statements like this:
Code:
testvar=1
if [ "$testvar" = "1" ] ; then
echo "Testvar is equal to one"
fi
Yet, when I put if statements exactly like this into a shell script and execute them in an adb shell (or connectbox shell), I get the following error:
line 4: syntax error: unexpected "fi" (expecting "then")
I've also taken if statements directly from init and they throw the same error.
Any busybox gurus here know what's up with this?
Click to expand...
Click to collapse
Remove the ; and enter the then
Code:
testvar=1
if [ "$testvar" = "1" ]
then
echo "Testvar is equal to one"
fi
Nope. Still throws the same error.
This is driving me nuts. What I'm doing is editing the /init script. The loops work just fine when executed at bootup in / init, but remounting the filesystem, editing /init and rebooting just the test a change takes forever.
For now I've got my changes to init working, but it would be nice to be able to test before editing /init
I just realized that I forgot to put `#!/bin/sh` at the top of my script. But doing so doesn't seem to help. Instead I get not found error.
Weird!
toadlife said:
Nope. Still throws the same error.
This is driving me nuts. What I'm doing is editing the /init script. The loops work just fine when executed at bootup in / init, but remounting the filesystem, editing /init and rebooting just the test a change takes forever.
For now I've got my changes to init working, but it would be nice to be able to test before editing /init
Click to expand...
Click to collapse
Code:
testvar=1
if [ $testvar = `1` ] (`=~ key)
then
echo "Testvar is equal to one"
fi
[/QUOTE]
It gives the echo, but also 1: not found.
Here is the actual code I put into my init:
(this works)
Code:
#Super cool battery thingy
RUNSCBS=`/bin/grep -o "run.scbs=.*" /proc/cmdline | /bin/sed -e "s/.*run.scbs=//g" -e "s/ .*//g"`
if [ "$RUNSCBS" = "1" ] ; then
dev=$(cat /sys/class/scbs/0/dev | sed -e "s/:/ /g")
mknod /dev/scbs0 c $dev
scbs -d -co /sdcard/scbs.conf
fi
# Debug logs
TAKELOGS=`/bin/grep -o "take.logs=.*" /proc/cmdline | /bin/sed -e "s/.*take.logs=//g" -e "s/ .*//g"`
if [ "$TAKELOGS" = "1" ] ; then
logfiledate=`expr substr \`date -Iseconds|tr -d :|tr -d \+|tr -d \-|tr -d T\` 1 14`
tar -cz -f "$card"/debuglogs_"$logfiledate".tar.gz "$card"/debuglogs_*.txt
cat /proc/kmsg>"$card"/debuglogs_kmsg_"$logfiledate".txt &
logcat -v time >"$card"/debuglogs_logcat_time_"$logfiledate".txt &
logcat -v time -b radio>"$card"/debuglogs_logcat_time_radio_"$logfiledate".txt &
fi
Ooooo I really like the idea of having logging running from init. Does that work well? Do the logs ever 'loop' and you end up missing things, or do they just keep on churnin?
arrrghhh said:
Ooooo I really like the idea of having logging running from init. Does that work well? Do the logs ever 'loop' and you end up missing things, or do they just keep on churnin?
Click to expand...
Click to collapse
AFAIK, they go forever. I started doing it last night by just putting the static command in the /init and the logging was still going when I got up this morning.
This morning wanted to see if I could make logging and scbs triggerable by an option in the command line.
Both are working for me now.
Know if where talking about scripts, i have a question too.
This is my RIL logs script:
Code:
#! /system/bin/sh
i="0"
while [ $i -lt 2 ]
do
date=`date +%Y%m%d%H%M`
if [ -d /sdcard/logs/ril/$date/ ]
then
echo "/sdcard/logs/ril/$date/ exists!"
else
mkdir /sdcard/logs/ril/$date/
echo " Made direction /sdcard/logs/ril/$date!"
fi
logcat -v time > /sdcard/logs/ril/$date/logcat-time.txt &
logcat -v time -b radio > /sdcard/logs/ril/$date/logcat-time.txt &
sleep 18000 && kill -0 $! && kill $!
cd /sdcard/logs/ril/
tar -czf ril$date.tar.gz $date
rm -r $date
cd /
done
The thing, i believe, is that only the logcat -v time -b radio is killed and when it's sleeping it's not doing that in the background.
Sleeping for 18000 seconds (5h), because if it's running for a day the logcat log will be more than 10 mb or so.
lol.
Your date string...
Code:
date +%Y%m%d%H%M
...is a bit simpler than mine...
Code:
expr substr `date -Iseconds|tr -d :|tr -d \+|tr -d \-|tr -d T` 1 14
(I couldn't figure out the `date` syntax)
Christiaan91 said:
Know if where talking about scripts, i have a question too.
This is my RIL logs script:
Code:
#! /system/bin/sh
i="0"
while [ $i -lt 2 ]
do
date=`date +%Y%m%d%H%M`
if [ -d /sdcard/logs/ril/$date/ ]
then
echo "/sdcard/logs/ril/$date/ exists!"
else
mkdir /sdcard/logs/ril/$date/
echo " Made direction /sdcard/logs/ril/$date!"
fi
logcat -v time > /sdcard/logs/ril/$date/logcat-time.txt &
logcat -v time -b radio > /sdcard/logs/ril/$date/logcat-time.txt &
sleep 18000 && kill -0 $! && kill $!
cd /sdcard/logs/ril/
tar -czf ril$date.tar.gz $date
rm -r $date
cd /
done
The thing, i believe, is that only the logcat -v time -b radio is killed and when it's sleeping it's not doing that in the background.
Sleeping for 18000 seconds (5h), because if it's running for a day the logcat log will be more than 10 mb or so.
Click to expand...
Click to collapse
Hmm. I haven't set up gscript myself yet, but you might need to nohup the logcats to get them to stay once gscript shuts down.
arrrghhh said:
Ooooo I really like the idea of having logging running from init. Does that work well? Do the logs ever 'loop' and you end up missing things, or do they just keep on churnin?
Click to expand...
Click to collapse
I have found one issue. It's seems that whenever scbs runs, locat fails to open the log devices. I just disabled scbs and logcat worked. I'm going to try swapping the code around so scbs runs after the logging starts.
It seems scbs blows up logcat, even when it is triggered after logging starts. Ughhh.
Entropy512 said:
Hmm. I haven't set up gscript myself yet, but you might need to nohup the logcats to get them to stay once gscript shuts down.
Click to expand...
Click to collapse
logcat will be going, even when you close the terminal, but when you deleted the files they stop. So that's not a problem, cuz i won't delete.
BTW: is it possible to silently run scripts? Like this one?
./pathtoscript1 & ./pathtoscript2 & ./pathtoscript3
Christiaan91 said:
logcat will be going, even when you close the terminal, but when you deleted the files they stop. So that's not a problem, cuz i won't delete.
BTW: is it possible to silently run scripts? Like this one?
./pathtoscript1 & ./pathtoscript2 & ./pathtoscript3
Click to expand...
Click to collapse
What do you mean "silently run" - do you mean disable any printing to stdout?
./pathtoscript1 &>/dev/null & ; ./pathtoscript2 &>/dev/null &
should do the trick The &>/dev/null routes all output to /dev/null
Man, you guys go way overboard on this stuff. This is my gscript logging script.
Code:
cd /sdcard
mv logg.txt logg.0.txt
mv logr.txt logr.0.txt
nohup logcat -v time > logg.txt &
nohup logcat -v time -b radio > logr.txt &
nohup klogd > klog.txt
highlandsun said:
Man, you guys go way overboard on this stuff. This is my gscript logging script.
Code:
cd /sdcard
mv logg.txt logg.0.txt
mv logr.txt logr.0.txt
nohup logcat -v time > logg.txt &
nohup logcat -v time -b radio > logr.txt &
nohup klogd > klog.txt
Click to expand...
Click to collapse
Yeah, well we don't all have kung-fu coding ablities like you, so we go overboard with what we can overboard with.
Besides, I think it might be beneficial to put something like the code I wrote into the official init, so noobs can more easily provide debug logs.
One thing to keep in mind, busybox = /bin/sh, statically compiled sh is /system/bin/sh. I got tired of not having arrow key support whenever I su'ed (since /bin/su spawns a root /system/bin/sh regardless of what's in /etc/passwd) so I bind mounted /bin/sh (which is a symlink to busybox) over the one in /system in my user.conf. I haven't come across any ill effect, but if you feel that the shell difference may be causing issues, you could try that route, since it's very easy to undo.
-- Starfox
Starfox said:
One thing to keep in mind, busybox = /bin/sh, statically compiled sh is /system/bin/sh. I got tired of not having arrow key support whenever I su'ed (since /bin/su spawns a root /system/bin/sh regardless of what's in /etc/passwd) so I bind mounted /bin/sh (which is a symlink to busybox) over the one in /system in my user.conf. I haven't come across any ill effect, but if you feel that the shell difference may be causing issues, you could try that route, since it's very easy to undo.
-- Starfox
Click to expand...
Click to collapse
Thanks for the tip. I'll give that a shot.
LOL. I'm an idiot
Figured out what the problem was. The file had Windows EOL formatting.
That's what I get for using Windows to edit shell scripts.

[Q] Installing package thru script

Hi Guys
I'm knocking my head over the wall since one week. I'm trying to write a sh script that could install apk from a folder located on sdcard.
Writing the script seems simple, but running it doesn't give me the attended result.
Here is my script :
Code:
!/system/bin/sh
if [ -f /data/200notrestored ]
then
if ! cat /proc/mounts | grep /mnt/sdcard
then
mount /dev/block/mmcblk0p1 /mnt/sdcard;
fi;
if ! cat /proc/mounts | grep /data
then
mount /data;
fi;
test=""
while [ "$test" == "" ]
do
sleep 3;
test=`busybox ps | grep systemui | grep -v "$(echo grep systemui)"`
done
for app in /sdcard/.apps/toinstall/*.apk
do
pm install -r $app;
done;
busybox rm -f /data/200notrestored
fi;
this script is located in /system/etc/init.d fodler and is then supposed to run during the boot.
I've seen that it is run, but not fully.
The command line
Code:
pm install -r $app;
seems to be not working at all.
I tried to replace this command by "cp" and then the package is well copied.
Why do I need to use "pm" command... simply because someapk does't support the "cp" command, and need a proper install to be run.
So here is my question :
has someone succeed in writing a script (run during boot) that install an apk ?
If yes , how ?
I know for example that the script works well on a DHD... why not on a Desire ?
Any help appreciate.
thx
Just for information
Running the script thru Termianl emulator works fine.
What can be the issue when the file is run at boot (put in init.d folder) ? What is the difference from runnihbgit at boot and in terminal ?
any idea ?
thx

[Script] Flash recovery from Terminal v1.0 [2012_0513]

I have create a script file that will flash a recovery from the terminal in the Galaxy Nexus.
I got the command from xda but I could not remember it when I wanted to flash a recovery,
so I wrote a script to do it.
AS WITH ANY FLASHING OR MODDING OF "YOUR" PHONE, I AM NOT RESPONSIBLE FOR ANY DAMAGES YOU MAY CAUSE!
I have tested this on my:
Unlocked Galaxy Nexus 4.1.1 takju (flashed from yakju)
Sprint Galaxy Nexus 4.0.4
Thanks to -viperboy- for help.
Code:
Created by Smurph82 2012_0512 (c) v1.0
flashr [-h] [-r] [-m] [-s s] -- Flash a recovery
to the Galaxy Nexus.
where:
-h show this help text
-r will reboot after flashing is complete.
-m image is in the root of the sdcard
-s source of the recovery image (/sdcard/recovery.img).
To use the script:
Download and Flash the script file from your current recovery
Or download the zip file and move the flashr file in the /system/bin folder to /system/bin with RootExplorer
or other root level file manager.
If you manually add the file you must
Code:
chmod 0755 /system/bin/flashr
or change the permissions from RootExplorer
Then open Terminal and type
Code:
su
first, yes you have to be rooted to do this!
Next type
Code:
flashr
or
Code:
flashr -h
to get the help
If you want to flash a recovery you must have the recovery.img
somewhere on your device that you can remember. Like the root of the sdcard.
To flash a recovery type
Code:
flashr -s /sdcard/recovery.img
or if the recovery is in the root of the sdcard type
Code:
flashr -ms recovery.img
If you want to reboot after the flashing is complete next use
Code:
flashr -mrs recovery.img
In the code examples above I used recovery.img as an example.
This should be "what ever you named the recovery".img it does not have to be recovery.
Reserved
Change Log:
v1 - Initial Release
i know you might think that im trolling, but im really not. what id like to know is what makes that better than just flashing the recovery, via the terminal, the old-fashioned way..
su(press enter)
flash_image recovery /sdcard/recovery.img(press enter)
reboot recovery(press enter, if you want to go to the recovery)
providing ithe file is on the main fs in the sd storage.
flash_image does not work with ics, that I have found. So I wrote my own. If there is a new flash_image that works with the galaxy nexus then I could not find it. Maybe it is because I'm still using the stock rom and kernel. I took the flash_image out of cm9 but it didn't work for me.
Sent from my Galaxy Nexus using XDA Premium HD app
Would you be willing to share the sources for this? It would be interesting to know how this works, since it may be useful also for other purposes than flashing recovery images. Or not?
I will post the source later today. It really is not much.
Sent from my Transformer Prime TF201 using XDA Premium HD app
E:V:A said:
Would you be willing to share the sources for this? It would be interesting to know how this works, since it may be useful also for other purposes than flashing recovery images. Or not?
Click to expand...
Click to collapse
Hope that this is helpful to someone.
Code:
#!/system/bin/sh
usage="Created by Smurph82 2012_0512 (c) v1.0
flashr [-h] [-r] [-m] [-s s] -- Flash a recovery
to the Galaxy Nexus.
where:
-h show this help text
-r will reboot after flashing is complete.
-m image is in the root of the sdcard
-s source of the recovery image (/sdcard/recovery.img)."
# Read in the options turn off verbose and require -s to have input
while getopts :hrms: opt; do
case $opt in
h) echo "$usage"
echo
exit;;
m) sdroot="/sdcard/";;
s) sourcedir=$OPTARG;;
r) reboot="t";;
*) echo
echo
echo "Invalid option: -$OPTARG" >&2
echo "$usage"
echo
exit;;
esac
done
shift $(($OPTIND - 1))
# This was for testing
#echo
#echo "Vars: m $sdroot: s $sourcedir: r $reboot: dir $sdroot$sourcedir"
#echo
# Check to make sure somthing was typed if not show help
if [ "$sourcedir" == "" ]; then
echo "$usage"
echo
exit
else
# Check that something is in that location if not dont flash
if [ -s $sdroot$sourcedir ]; then
echo "Flashing image from: $sdroot$sourcedir"
cat $sdroot$sourcedir > /dev/block/platform/omap/omap_hsmmc.0/by-name/recovery
else
echo "File not found at $sdroot$sourcedir"
exit
fi
fi
# Early in the morning I was getting cute
if [ "$reboot" == "t" ]; then
echo "Rebooting in 5.."
sleep 1
echo "Rebooting in 4.."
sleep 1
echo "Rebooting in 3.."
sleep 1
echo "Rebooting in 2.."
sleep 1
echo "Rebooting in 1.."
sleep 1
reboot recovery
fi
thank u very much for this! so easy now!!
It is just as easily done in a terminal by the following (assuming you downloaded the recovery you want to /sdcard and named it recovery.img):
su
dd if=/sdcard/recovery.img of=dev/block/platform/omap/omap_hsmmc.0/by-name/recovery
efrant said:
It is just as easily done in a terminal by the following (assuming you downloaded the recovery you want to /sdcard and named it recovery.img):
su
dd if=/sdcard/recovery.img of=dev/block/platform/omap/omap_hsmmc.0/by-name/recovery
Click to expand...
Click to collapse
Yes I know that but who wants to type all of that out. I just made it shorter more
or else. If you want to type the whole command then by all means have at it. I just
think that "flashr -mrs twrp.img" is a whole lot easier. Just my thoughts.
Hi
Nice enough script.
Although I feel I should warn people that it looks like this script will write anything you tell it. making no effort to verify that the file is a valid or correct for your phone. so be careful not to specify the wrong file.
fastboot flash recovery $file is much safer.
That is true if you are connected to a computer but this script is run on the phone from the terminal. If someone knows a way to check a file from the terminal running on the phone please tell me and I will update the script. I understand that there is currently no verification of the file that is being written so please make sure that you are writing the right file.
Sent from my Galaxy Nexus using XDA Premium HD app

[TIP] Running random scripts at boot

HTC One M8.
I have done HTCdev with http://htc-one.wonderhowto.com/how-to/unlock-bootloader-root-your-htc-one-m8-0154444/
then rooted
Then did S-OFF with http://firewater-soff.com/instructions/
Then, to be able to write to /system, you need more steps. From recovery, it works easily. From live running system, the default stock ROM has a write protection. This WP can be removed easily by loading a kernel module:
http://forum.xda-developers.com/showthread.php?t=2701816
then:
Code:
insmod /mnt/sdcard/Download/wp_mod_m8.ko
mount -o remount,rw /system
Now, I want to run random scripts.
First, check if the stock ROM has the same issue as my previous phone:
Code:
[email protected]_m8:/ # echo $PATH
/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin:/vendor/bin
[email protected]_m8:/ # ls -l /system/sbin
/system/sbin: No such file or directory
1|[email protected]_m8:/ #
That's exactly what we need: a folder that is in PATH, that does not exist, and should exist somewhere we can create it. So:
Code:
insmod /mnt/sdcard/Download/wp_mod_m8.ko
mount -o remount,rw /system
mkdir /data/local/bin
ln -s /data/local/bin/ /system/sbin
Then, create two small scripts in there: do vi /system/sbin/vibrate , then i to enter insert mode, paste this code, esc, :x ... or use any other editor if you want:
Code:
#!/system/xbin/ash
#
i="$1"
[ "$i" = "" ] && i=400
# default value for voltage_level at boot is 3100 mV.
v=3100
vmin=1200
[ $i -gt 0 ] 2>/dev/null || {
echo "Invalid argument '$i'; should be a number below 9999 ms."
exit 1
}
[ $i -gt 9999 ] && {
echo "Invalid argument '$i'; should be below 9999 ms."
exit 1
}
[ "$2" != "" ] && {
[ $2 -ge $vmin ] 2>/dev/null || {
echo "Invalid argument '$2'; should be a number between $vmin and ${v} mV."
exit 1
}
[ $2 -gt $v ] && {
echo "Invalid argument '$2'; should be below ${v} mV."
exit 1
}
}
[ "$i" = "" ] && { echo "Provide argument: time in ms." ; exit 1 ; }
[ "$2" = "" ] && {
echo "Voltage not provided. Using default $v mV."
} || {
v=$2
echo "Using voltage argument $v mV."
}
echo $v > /sys/devices/virtual/timed_output/vibrator/voltage_level
echo "$i" > /sys/devices/virtual/timed_output/vibrator/enable
It was an old code for HTC Sensation; voltage does not work anymore, but duration does.
A shorter script for flash, and create the init script:
Code:
echo "echo 255 > /sys/class/leds/flashlight/brightness" > /system/sbin/flashlight
echo "#!/system/bin/sh
# /system/etc/init.qcom.bt.sh
/data/local/bin/vibrate
/system/sbin/flashlight" > /data/local/bin/rc.init
chmod 755 /system/sbin/flashlight
chmod 755 /system/sbin/vibrate
chmod 755 /data/local/bin/rc.init
Now, the tricky part: make the init script run at boot. Edit /system/etc/init.qcom.bt.sh , and below the comment, insert this line:
Code:
/data/local/bin/rc.init &
Reboot, enjoy Your phone flashes and vibrates at boot. As is, this is almost useless. But, now you can create system scripts, and run them at boot ... you can do pretty much anything you do on a classic Linux machine.
Because scripts are put in a folder which is in the default system $PATH, all apps or widgets can run those scripts. This vibrate script can be called for example from a Tasker or ScriptManager widget.
I love vibrate, because it's a small noise; I tail it to any command that is likely to take more than 1mn to run. Having a ScriptManager widget running it also helps me check the system load. If phone seems slow, and vibration does not happen at once, then the phone has big load, and I shall wait for things to settle.
/system/etc/init.qcom.bt.sh was not a random choice. To understand why: open /init.target.rc , and now, search a script that is run ... at boot ... with user root ... and that lays in /system. Many scripts are run as user, or stored outside /system.
Now, it's up to you to create scripts that are usefull to you.
Hey thanks for the directions but I tried running the command mnt/sdcard/download/wp_mod.ko and I got a "failed exec format error"....
rgolnazarian said:
Hey thanks for the directions but I tried running the command mnt/sdcard/download/wp_mod.ko and I got a "failed exec format error"....
Click to expand...
Click to collapse
This is completely unrelated and offtopic. Either your file does not have exec bit, or wrong interpreter, or stored on partition that has noexec.
Hmmm ... why is the quoted message different from the one I received by email ???
Any way, even if you are in /, "mnt/sdcard/download/wp_mod.ko" is an invalid command. A module can not be executed, it must be inserted; see tutos about it.

Categories

Resources