FORUMS
Remove All Ads from XDA

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

11,416 posts
Thanks Meter: 88,028
 
By Chainfire, Moderator Emeritus / Senior Recognized Developer - Where is my shirt? on 5th April 2011, 02:14 PM
Post Reply Email Thread
29th January 2013, 10:43 AM |#11  
mai77's Avatar
Senior Member
Thanks Meter: 582
 
More
Re: [TRICK/CWM3/EDIFY] Output to recovery UI from shell script
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
The Following User Says Thank You to mai77 For This Useful Post: [ View ] Gift mai77 Ad-Free
 
 
17th February 2013, 06:54 PM |#12  
mai77's Avatar
Senior Member
Thanks Meter: 582
 
More
Lightbulb 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
24th September 2013, 11:44 PM |#13  
osm0sis's Avatar
Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 29,909
 
Donate to Me
More
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"

Quote:
Originally Posted by mai77

what value does OUTFD have?

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.
The Following 4 Users Say Thank You to osm0sis For This Useful Post: [ View ]
14th March 2014, 01:12 AM |#14  
Senior Member
Thanks Meter: 179
 
More
Nice work, I used this in my little zip. However, it doesn't work with TWRP. Is there any way to accomplish that?
6th April 2014, 02:53 PM |#15  
shohag2018's Avatar
Senior Member
Thanks Meter: 35
 
More
sorry to put this here but could anyone direct me towards the cwm or TWRP version for "jxjpb" (asia) baseband pls?
7th April 2014, 09:49 PM |#16  
Recognized Developer / Recognized Contributor
Thanks Meter: 4,262
 
Donate to Me
More
Quote:
Originally Posted by klenamenis

Nice work, I used this in my little zip. However, it doesn't work with TWRP. Is there any way to accomplish that?

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)
The Following 4 Users Say Thank You to _that For This Useful Post: [ View ]
15th May 2014, 04:39 AM |#17  
osm0sis's Avatar
Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 29,909
 
Donate to Me
More
Quote:
Originally Posted by _that

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)

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.
The Following User Says Thank You to osm0sis For This Useful Post: [ View ]
15th May 2014, 07:17 AM |#18  
Recognized Developer / Recognized Contributor
Thanks Meter: 4,262
 
Donate to Me
More
Quote:
Originally Posted by osm0sis

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;

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.

Quote:
Originally Posted by osm0sis

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.

Wow, nice collection! I remember some other posts from you that were very helpful, thanks!
The Following 2 Users Say Thank You to _that For This Useful Post: [ View ]
15th May 2014, 05:01 PM |#19  
osm0sis's Avatar
Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 29,909
 
Donate to Me
More
Quote:
Originally Posted by _that

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!

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.
15th May 2014, 09:26 PM |#20  
Recognized Developer / Recognized Contributor
Thanks Meter: 4,262
 
Donate to Me
More
Quote:
Originally Posted by osm0sis

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.

Exactly! I learned a lot about the zip format while researching this.

Quote:
Originally Posted by osm0sis

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.

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. 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"
The Following 2 Users Say Thank You to _that For This Useful Post: [ View ]
15th May 2014, 09:51 PM |#21  
osm0sis's Avatar
Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 29,909
 
Donate to Me
More
Quote:
Originally Posted by _that

Exactly! I learned a lot about the zip format while researching this.

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. Attachment 2745848 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"

Fantastic! Thanks a lot!

@TKruzze is working on converting his popular PA GApps packages over to shell script update-binary, and asked me to look into the signing issue again citing my old post there, so if Chainfire's doesn't do the trick then I'll point him this way.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes