FORUMS
Remove All Ads from XDA

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

11,416 posts
Thanks Meter: 88,031
 
By Chainfire, Moderator Emeritus / Senior Recognized Developer - Where is my shirt? on 5th April 2011, 02:14 PM
Post Reply Email Thread
27th August 2014, 08:37 PM |#31  
osm0sis's Avatar
Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 29,909
 
Donate to Me
More
Any ideas how to get the name of the zip update-binary is running from, via a .sh executed by the EDIFY?

It's dead easy with a pure shell script update-binary ($3) but I'm having trouble figuring it out when doing EDIFY.


Edit: Nevermind! Figured it out myself!

Very similar to the OUTFD, we can just pull it from the updater commandline (duh $3!) through ps, but we have to go wide to get the whole thing.

Full path:
Code:
ps -w | grep -v "grep" | grep -oE "update(.*)" | cut -d" " -f4
Just the zip name:
Code:
basename `ps -w | grep -v "grep" | grep -oE "update(.*)" | cut -d" " -f4`
The Following 3 Users Say Thank You to osm0sis For This Useful Post: [ View ]
 
 
27th August 2014, 09:11 PM |#32  
Recognized Developer / Recognized Contributor
Thanks Meter: 4,262
 
Donate to Me
More
Quote:
Originally Posted by osm0sis

Code:
ps -w | grep -v "grep" | grep -oE "update(.*)" | cut -d" " -f4

Does that work if the zip name contains spaces? You may need to append a "-", i.e. "-f4-" (untested).
The Following 2 Users Say Thank You to _that For This Useful Post: [ View ]
27th August 2014, 11:34 PM |#33  
osm0sis's Avatar
Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 29,909
 
Donate to Me
More
Quote:
Originally Posted by _that

Does that work if the zip name contains spaces? You may need to append a "-", i.e. "-f4-" (untested).

Good catch! Thanks.

I just made the AnyKernel2 zip for the GN DirtyV kernel allow the user to choose what variant (Normal,ASRAM,SuperRAM) zImage they want based on the way they name the zip.
2nd May 2015, 11:29 AM |#34  
ScratMan38's Avatar
Senior Member
Flag Grenoble
Thanks Meter: 470
 
More
I tried the method from the OP to display the feedbacks from a shell script in the recovery's console, but it does not work.
I'm using TWRP compiled by KToonsez for SM-G900F.

I'my trying to compare two versions of a file, and if it matches, replace the file in /system/etc with a new modified file.

When running my sh script in the terminal window from TWRP, it works perfectly fine. But when I include this script in a flashable zip, it does not work anymore. And I can't have feedback as the method from Chainfire does not work.
2nd May 2015, 01:42 PM |#35  
Recognized Developer / Recognized Contributor
Thanks Meter: 4,262
 
Donate to Me
More
Quote:
Originally Posted by ScratMan38

I tried the method from the OP to display the feedbacks from a shell script in the recovery's console, but it does not work.
I'm using TWRP compiled by KToonsez for SM-G900F.

See my post earlier in this thread - TWRP names the updater binary differently.
The Following User Says Thank You to _that For This Useful Post: [ View ]
2nd May 2015, 05:11 PM |#36  
ScratMan38's Avatar
Senior Member
Flag Grenoble
Thanks Meter: 470
 
More
Quote:
Originally Posted by _that

See my post earlier in this thread - TWRP names the updater binary differently.

Thanks, I finally solved my issue by replacing the update-binary from edify by the script I made, basing my work on the scripts from klenamenis.

My script looks like this :
updater-binary :
Code:
#!/sbin/sh
#set -e
## Script is inspired from tweakprop by klenamenis http://forum.xda-developers.com/showthread.php?t=2664332

## credits for ui_print() go to chainfire
OUTFD=$2
ui_print() {
	echo -n -e "ui_print $1\n" > /proc/self/fd/$OUTFD
	echo -n -e "ui_print\n" > /proc/self/fd/$OUTFD
}

ui_print " "
ui_print "#########################"
ui_print "# Increase Rec Mic Gain #"
ui_print "#########################"
ui_print " "

ui_print "Mount system partition..."
mount /system
mount -o rw,remount /system
mount -o rw,remount /system /system

ui_print "Check file version"

if cmp -s /sdcard/Cyandelta/mixer_paths_ref.xml /system/etc/mixer_paths.xml; then
	ui_print "*** The files version match ***"
else
    ui_print "### The files version are different, exiting ###"
    umount /system
	exit 1
fi

# # update status
ui_print "Copying mixer_paths.xml file with higher mic gain"
chmod 0666 /system/etc/mixer_paths.xml
cp -f /sdcard/Cyandelta/mixer_paths_mod.xml /system/etc/mixer_paths.xml
chmod 644 /system/etc/mixer_paths.xml

ui_print "Checking file has been correctly written"

if cmp -s /sdcard/Cyandelta/mixer_paths_mod.xml /system/etc/mixer_paths.xml; then
	ui_print "*** Copy Success: The files match ***"
else
    ui_print "### Copy Failed : The files are different ###"
fi

ui_print " "
# done !
ui_print "done! exiting!"
ui_print " "
umount /system
exit 0
The only issue I'm facing now is that I need to keep the two xml files mixer_paths_ref.xml and mixer_paths_mod.xml in the /sdcard/Cyandelta folder.
When I try to include them in the zip file, the shell does not find them to compare with the original file.
The files should be extracted from the zip at the same time as the update-binary script, but I can't find where they are to correct the path in the script.

But anyway, it's working and now I can automatically fix the microphone gain during video recording when using Cyandelta to update my ROM.

Thanks
20th September 2017, 07:29 PM |#37  
Senior Member
Flag Toba Tek Singh
Thanks Meter: 233
 
More
I'm able to print the output of "echo" command to recovery output by defining "ui_print" function as explained in guide. But how can I get verbose output of a command like "tar" or "unzip" on recovery output?

---------- Post added at 07:21 PM ---------- Previous post was at 06:57 PM ----------

Quote:
Originally Posted by ScratMan38

The only issue I'm facing now is that I need to keep the two xml files mixer_paths_ref.xml and mixer_paths_mod.xml in the /sdcard/Cyandelta folder.
When I try to include them in the zip file, the shell does not find them to compare with the original file.
The files should be extracted from the zip at the same time as the update-binary script, but I can't find where they are to correct the path in the script.

Put them in any folder xyz in zip along with META-INF folder and extract the folder to /tmp and then set permissions. Now use them for any purpose you want.
Sorry for late reply. I know you must have figured this out long ago but I just figured it out

---------- Post added at 07:29 PM ---------- Previous post was at 07:21 PM ----------

Quote:
Originally Posted by rovo89

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");

What's param1 and param2 here?
21st September 2017, 09:08 PM |#38  
Recognized Developer / Recognized Contributor
Thanks Meter: 4,262
 
Donate to Me
More
Quote:
Originally Posted by mirfatif

What's param1 and param2 here?

Whatever your script expects.
12th January 2019, 01:28 AM |#39  
Senior Member
Thanks Meter: 102
 
More
i have read -d illegal option in twrp (busybox) ash shell, how can i use korn mksh shell from updater-binary (shell script) instead? read -d is important for correct file name handling (find -print0 | while read -r -d $'\0'). find -exec does not know functions (find -exec my_function {} \;) because of subshells i guess, so the only thing left is use mksh...
Code:
LD_LIBRARY_PATH=/system/lib:/sbin /system/bin/sh my-script.sh "[email protected]"
seems to work for twrp 3.2.2, but with multirom twrp 3.0.0 it gives linker errors. is there a more generic way to use the android mksh from recovery?

And next question: for ui_print is there a way to update or clear the screen? I need a file select / highlight function controlled with volume keys. I am thinking about writing one, but at least clear screen is required (update some lines would be better) otherwise the output becomes ugly...
i have tried ANSI escape codes, but this just adds this sequence of characters into fd, there is no way to remove contents of that file descriptor...
Code:
printf 'ui_print ' > /proc/self/fd/$2
printf \\033[2J\\033[\;H > /proc/self/fd/$2
printf '\nui_print\n' > /proc/self/fd/$2
there must be a way to clear the screen, i mean i can far remember that i have seen this in a flashable zip from YashdSaraf or osm0sis?
27th March 2019, 09:26 AM |#40  
AxelBlaz3's Avatar
Member
Flag Hyderabad
Thanks Meter: 58
 
More
I have a query, what if I'd like to run the script from terminal emulator after extracting zip manually? Is it possible? I know it can't figure out the FD. But I'm curious to know if there's a way to run such scripts from terminal.
27th March 2019, 10:01 AM |#41  
Senior Member
Thanks Meter: 102
 
More
In your script, add a echo in ui_print function. This will send everything to fd and stdout simultaneously
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