Elementary sh scripting doubt - Desire Android Development

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.

Related

[UTIL] a2sd Updated script w/ error checking! 10/12/09

**New version in the works. See last page for my post**
**Updated 5:51pm CST**
-Made sweeping changes to the script. Thanks Farmatito for the suggestions. Output from script also goes to adb logcat
-See script for additional changelog
**Updated 11:00am CST**
-Changed a couple "cp" commands to "ln" as this is a smarter way of doing it. Script has been updated and re-uploaded
After having issues with the current a2sd script floating around (under certain environments the script would erase all user & system apps) I decided to update it so that there is proper error checking, logging, and back-out procedures on failure. The log is stored in /data/a2sd.log so if you get stuck at a black screen or it won't boot, now you can check the log and find out where its failing! By the way, if your phone won't boot or you have a black screen obviously the only way you can read the log is by connecting the phone to a pc and using adb shell cat /data/a2sd.log .
Anyways here it is, enjoy.
Procedure
Code:
adb remount
adb shell cp /system/bin/a2sd /system/bin/a2sd.bak
adb shell push a2sd.txt /system/bin/a2sd
adb shell chmod 777 /system/bin/a2sd
adb shell reboot
Everything should work like before. But you can rest at night knowing if your phone won't boot you now have a way to know if it was related to a2sd and what the cause was
**NOTE: If you get stuck at the boot screen it's probably b/c your /system/sd partition is failing the fsck. You should probably fsck it on your own to fix any corruption. If you don't want the fsck then comment it out of the script.
Very cool, lets hope a developer picks this up and uses it.
bubonik said:
Very cool, lets hope a developer picks this up and uses it.
Click to expand...
Click to collapse
I could toss this in my next build if the masses like it (sure they will)
I was going to read through this and give a full opinion but it is too long for me to do it this late. My eyes are crossing trying to read it. But at first glance it looks good (logs are always good right ). And I've never seen shafty not do good work. I'll try to look it over in full tomorrow. Plus you've inspired me to try to think of same way to contribute to this file. So now I have to put that on my todo list.
miketaylor00 said:
I was going to read through this and give a full opinion but it is too long for me to do it this late. My eyes are crossing trying to read it. But at first glance it looks good (logs are always good right ). And I've never seen shafty not do good work. I'll try to look it over in full tomorrow. Plus you've inspired me to try to think of same way to contribute to this file. So now I have to put that on my todo list.
Click to expand...
Click to collapse
O hell yea, mike the masters on it!
miketaylor00 said:
I was going to read through this and give a full opinion but it is too long for me to do it this late. My eyes are crossing trying to read it. But at first glance it looks good (logs are always good right ). And I've never seen shafty not do good work. I'll try to look it over in full tomorrow. Plus you've inspired me to try to think of same way to contribute to this file. So now I have to put that on my todo list.
Click to expand...
Click to collapse
The more the merrier. It's too bad everyone doesn't have bash installed or we'd be able to take advantage of all the features bash includes (functions, advanced iteration loops, arithmetic).
That would be on all the ROM devs to include it though. Oh and I'm a UNIX Admin so writing shell scripts is like 60% of my job. We try and make our lives easier by writing scripts to do the work for us
shafty023 said:
The more the merrier. It's too bad everyone doesn't have bash installed or we'd be able to take advantage of all the features bash includes (functions, advanced iteration loops, arithmetic).
That would be on all the ROM devs to include it though. Oh and I'm a UNIX Admin so writing shell scripts is like 60% of my job. We try and make our lives easier by writing scripts to do the work for us
Click to expand...
Click to collapse
I figured you did something like that. Your scripts are always good. I've learned a lot from reading through stuff that you have posted. I wish I had your experience with it. I always have to fumble through to find the right syntax to do what I want to do.
miketaylor00 said:
I figured you did something like that. Your scripts are always good. I've learned a lot from reading through stuff that you have posted. I wish I had your experience with it. I always have to fumble through to find the right syntax to do what I want to do.
Click to expand...
Click to collapse
Ya I started out fumbling around just as well. Keep at it and if you ever have any questions about how to do something feel free to PM me. Shell scripting, among the other 10 programming languages I code in fluently, come second nature after years of coding in them. Java/C/C++/Sh/Bash/Lisp/Javascript/Html/Php/Jquery.
shafty023 said:
Ya I started out fumbling around just as well. Keep at it and if you ever have any questions about how to do something feel free to PM me. Shell scripting, among the other 10 programming languages I code in fluently, come second nature after years of coding in them. Java/C/C++/Sh/Bash/Lisp/Javascript/Html/Php/Jquery.
Click to expand...
Click to collapse
Sweet, i will probably take you up on that offer sometime. I have a question about running e2fsck. I always run it with the -f option because it seems like it never finds problems unless they are really bad if I don't. Would there be a problem running it in your a2sd with -fy? I've always wondered why no one uses the -f option.
miketaylor00 said:
Sweet, i will probably take you up on that offer sometime. I have a question about running e2fsck. I always run it with the -f option because it seems like it never finds problems unless they are really bad if I don't. Would there be a problem running it in your a2sd with -fy? I've always wondered why no one uses the -f option.
Click to expand...
Click to collapse
Well there's two sides to this. One could argue we should force a fsck at every boot, and then the other side is to let Android mark the partition as dirty so fsck will run only when needed. Normally the filesystem is supposed to be marked dirty if in fact it is dirty.
So if we force a fsck at every boot then that would add to the boot time of the OS but then again would ensure the filesystem isn't corrupted. It's really personal preference. It breaks down to "Speed of boot" vs "filesystem integrity"
I can't even find a2sd in cm4.1.999. Seems to have gone missing. Anyone know if it exists, and if so, where it's at?
overground said:
I can't even find a2sd in cm4.1.999. Seems to have gone missing. Anyone know if it exists, and if so, where it's at?
Click to expand...
Click to collapse
The default location is /system/bin/a2sd . If it's not there not sure where else it could be hidden at
shafty023 said:
The default location is /system/bin/a2sd . If it's not there not sure where else it could be hidden at
Click to expand...
Click to collapse
That's where it should be and used to be. I looked in the original zip and it's not there either. Checked sbin and xbin and other places where it also shouldn't be, and can't find it...weird.
overground said:
That's where it should be and used to be. I looked in the original zip and it's not there either. Checked sbin and xbin and other places where it also shouldn't be, and can't find it...weird.
Click to expand...
Click to collapse
Perhaps it was integrated into the swap file. And I don't mean swap file as in the literal swap file. I mean /system/bin/swap which is a conf file & shell script in one. I would check there to see if it was incorporated in there.
Hi,
just some comments about the "monster" a2sd script. ;-)
Hope they will help you to imprrove it further.
I would suggest to change the logging so that
it could be seen during a adb logcat of the boot process, from:
echo "Beginning a2sd `date`" >$LOG;
to e.g:
echo "Beginning a2sd `date`" | busybox tee -a $LOG;
(LOG must be initialized if it not exists)
Line 40:
e2fsck -y /dev/block/mmcblk0p2;
if [ $? -ne 0 ];
then
echo "Fail" >>$LOG;
exit 1;
fi;
else
echo "Ok" >>$LOG;
fi;
# set property with exit code in case an error occurs
setprop cm.e2fsck.errors $?;
Setprop is not executed in case of errors as we do exit. Is this intended?
Line 144:
# don't allow /data/data on sd because of upgrade issues - move it if possible
if [ -d /system/sd/data ];
then
echo -n "Found /system/sd/data which is a no-no, removing: " >>$LOG;
busybox cp -a /system/sd/data/* /data/data/;
busybox rm -rf /system/sd/data;
echo "Ok" >>$LOG;
fi;
I suggest cp -ap to preserve permissions and ownership of the copied files
I suggest to mv /system/sd/data to /system/sd/data.bak if cp fails
rather than rm all the data
Line 195:
if [ `ls -l /data/$i/ | wc -l` -ne 0 ];
then
echo -n "Moving /data/$i: " >>$LOG;
busybox cp -a /data/$i/* /system/sd/$i/;
if [ $? -ne 0 ];
then
echo "Fail" >>$LOG;
busybox umount /system/sd;
exit 1;
else
echo "Ok" >>$LOG;
fi;
fi;
I suggest to use cp -ap to preserve permissions and ownership
Line 206:
echo -n "Deleting contents in /data/$i: " >>$LOG;
busybox rm -f /data/$i/*;
I suggest rm -fR /data/$i;
Line 329:
if [ -f /system/lib/hw/lights.msm7k.so ] && [ ! -e /system/lib/hw/lights.trout.so ];
then
busybox cp /system/lib/hw/lights.msm7k.so /system/lib/hw/lights.trout.so;
fi;
if [ -f /system/lib/hw/copybit.msm7k.so ] && [ ! -e /system/lib/hw/copybit.trout.so ];
then
busybox cp /system/lib/hw/copybit.msm7k.so /system/lib/hw/copybit.trout.so;
fi;
if [ -f /system/lib/hw/sensors.msm7k.so ] && [ ! -e /system/lib/hw/sensors.trout.so ];
then
busybox ln -s /system/lib/hw/sensors.msm7k.so /system/lib/hw/sensors.trout.so;
fi;
I suggest to use ln for all.
Line 353:
/system/bin/sh /system/bin/swap;
Cannot find /system/bin/swap on my rom, maybe
if [ -e /system/bin/swap ] ; then.
shafty023 said:
The default location is /system/bin/a2sd . If it's not there not sure where else it could be hidden at
Click to expand...
Click to collapse
update-cm-4.1.99-signed/system/etc/init.d/04apps2sd
farmatito said:
update-cm-4.1.99-signed/system/etc/init.d/04apps2sd
Click to expand...
Click to collapse
Thank you...knew it had to be in there. Love your work, BTW.
echo "Beginning a2sd `date`" >$LOG;
to e.g:
echo "Beginning a2sd `date`" | busybox tee -a $LOG;
Click to expand...
Click to collapse
Unfortunately during boot anything thrown to console is not caught by adb logcat, BUT! You gave me a good idea, it will now look like this
Code:
/system/bin/logwrapper echo "Beginning a2sd `date`";
# set property with exit code in case an error occurs
setprop cm.e2fsck.errors $?;
Click to expand...
Click to collapse
Removed
Line 144:
# don't allow /data/data on sd because of upgrade issues - move it if possible
if [ -d /system/sd/data ];
then
echo -n "Found /system/sd/data which is a no-no, removing: " >>$LOG;
busybox cp -a /system/sd/data/* /data/data/;
busybox rm -rf /system/sd/data;
echo "Ok" >>$LOG;
fi;
I suggest cp -ap to preserve permissions and ownership of the copied files
I suggest to mv /system/sd/data to /system/sd/data.bak if cp fails
rather than rm all the data
Click to expand...
Click to collapse
Great catch, this has been changed
Line 195:
if [ `ls -l /data/$i/ | wc -l` -ne 0 ];
then
echo -n "Moving /data/$i: " >>$LOG;
busybox cp -a /data/$i/* /system/sd/$i/;
if [ $? -ne 0 ];
then
echo "Fail" >>$LOG;
busybox umount /system/sd;
exit 1;
else
echo "Ok" >>$LOG;
fi;
fi;
I suggest to use cp -ap to preserve permissions and ownership
Click to expand...
Click to collapse
Changed
Line 206:
echo -n "Deleting contents in /data/$i: " >>$LOG;
busybox rm -f /data/$i/*;
I suggest rm -fR /data/$i;
Click to expand...
Click to collapse
This was already being done in the following FOR loop but after inspecting further I merged the app symlinks FOR loop with this IF statement.
Line 329:
if [ -f /system/lib/hw/lights.msm7k.so ] && [ ! -e /system/lib/hw/lights.trout.so ];
then
busybox cp /system/lib/hw/lights.msm7k.so /system/lib/hw/lights.trout.so;
fi;
if [ -f /system/lib/hw/copybit.msm7k.so ] && [ ! -e /system/lib/hw/copybit.trout.so ];
then
busybox cp /system/lib/hw/copybit.msm7k.so /system/lib/hw/copybit.trout.so;
fi;
if [ -f /system/lib/hw/sensors.msm7k.so ] && [ ! -e /system/lib/hw/sensors.trout.so ];
then
busybox ln -s /system/lib/hw/sensors.msm7k.so /system/lib/hw/sensors.trout.so;
fi;
I suggest to use ln for all.
Click to expand...
Click to collapse
This change has already been made and I uploaded a new script earlier today.
Line 353:
/system/bin/sh /system/bin/swap;
Cannot find /system/bin/swap on my rom, maybe
if [ -e /system/bin/swap ] ; then.
Click to expand...
Click to collapse
Added.
Thanks for all your suggestions, I will re-upload a new version in an hour or so soon as I get a chance to change the echo commands to use logwrapper. Well I'm keeping the existing echo commands which spit output to my log but will also add another which will spit output to logcat.
miketaylor00 said:
Sweet, i will probably take you up on that offer sometime. I have a question about running e2fsck. I always run it with the -f option because it seems like it never finds problems unless they are really bad if I don't. Would there be a problem running it in your a2sd with -fy? I've always wondered why no one uses the -f option.
Click to expand...
Click to collapse
I take it back, after having suffered yet another file system corruption on my /system/sd partition I'm putting that darn "-f" in there. I'll re-upload a new copy with other changes shortly
Posted a new copy of the a2sd script with lots of changes. Check it out everyone. As always suggestions & questions are welcome

REQUEST/IDEA for a safety script for tweaking/OC

I had an Idea for a script that would run at bootup, and if a certain variable had a "value" of NOT 1.
then the script would change the CHMOD of a userinit.sh located in the sd-ext from 050 or 777 to 750 then it would change the variable "value" to 0 were it would stay untill another script that runs at shut down or reboot setts the variable to 1 and changes CHMOD back to 050 or 777 so that the userinit.sh is not run.
That way if a change is made during operating the phone that causes the phone to crash with out shutting down properly the script runs which causes the userinit.sh to run and "resets" userinit.sh values to a "default". Otherwise if shut down properly nothing happens.
This could be expanded on to include repairing the EXT or clearing some special cache or other stuff I am unfamiliar with but that you might want to run after a crash.(like logcat?)
any way what do you think? any promise?
I think, for overclocking purposes anyway, making the userinit.sh unrunnable would make the phone break immediately, as I think it would go to the highest available frequency. However, I like the idea, though I'm not sure how to run scripts on shutdown. I think for overclocking, it would check if the shutdown was clean on startup, and if not change the applicable line to the next lowest number, which it would get either from a seperate file or maybe it could be stuffed in the script itself. (Just my somewhat uneducated thoughts)
TheNewGuy said:
I had an Idea for a script that would run at bootup, and if a certain variable had a "value" of NOT 1.
then the script would change the CHMOD of a userinit.sh located in the sd-ext from 050 or 777 to 750 then it would change the variable "value" to 0 were it would stay untill another script that runs at shut down or reboot setts the variable to 1 and changes CHMOD back to 050 or 777 so that the userinit.sh is not run.
That way if a change is made during operating the phone that causes the phone to crash with out shutting down properly the script runs which causes the userinit.sh to run and "resets" userinit.sh values to a "default". Otherwise if shut down properly nothing happens.
This could be expanded on to include repairing the EXT or clearing some special cache or other stuff I am unfamiliar with but that you might want to run after a crash.(like logcat?)
any way what do you think? any promise?
Click to expand...
Click to collapse
Keep it simple. If a change in userinit.sh breaks your system, reboot to recovery and edit it and reboot again.
TheNewGuy said:
I had an Idea for a script that would run at bootup, and if a certain variable had a "value" of NOT 1.
then the script would change the CHMOD of a userinit.sh located in the sd-ext from 050 or 777 to 750 then it would change the variable "value" to 0 were it would stay untill another script that runs at shut down or reboot setts the variable to 1 and changes CHMOD back to 050 or 777 so that the userinit.sh is not run.
That way if a change is made during operating the phone that causes the phone to crash with out shutting down properly the script runs which causes the userinit.sh to run and "resets" userinit.sh values to a "default". Otherwise if shut down properly nothing happens.
This could be expanded on to include repairing the EXT or clearing some special cache or other stuff I am unfamiliar with but that you might want to run after a crash.(like logcat?)
any way what do you think? any promise?
Click to expand...
Click to collapse
most rom devs/tweakers launch userinit.sh by calling it with a sh
e.g.
/system/bin/sh /system/sd/userinit.sh
so it will still run !! ( as init doesn't care about permissions, it is god )
don't believe me?
Code:
echo "echo I ran" > /data/test.sh
chmod 000 /data/test.sh
sh /data/test.sh
Keep it simple. If a change in userinit.sh breaks your system, reboot to recovery and edit it and reboot again.
Click to expand...
Click to collapse
Yea thats the easy way!...
(Seriously I'm not that good at Linux Command Line code,wording,but i'm getting there.)
I think, for overclocking purposes anyway, making the userinit.sh unrunnable would make the phone break immediately, as I think it would go to the highest available frequency. However, I like the idea, though I'm not sure how to run scripts on shutdown. I think for overclocking, it would check if the shutdown was clean on startup, and if not change the applicable line to the next lowest number, which it would get either from a seperate file or maybe it could be stuffed in the script itself. (Just my somewhat uneducated thoughts)
Reply With Quote
Click to expand...
Click to collapse
And I know that most roms now have a script called something like in /system/etc/init.d/20userinit that runs at startup and checks to see if a userinit.sh is present in sd-ext,if so it runs it.Also I noticed that the script can be there but if it is CHMOD to 777 it wont run. This is the "Reset script" Set to restet to something you like and run other tasks to help Fix/Diagnose probs.
The OC changes would be made from a different script such as 86supersettings
Or a userinit located in system/sd maybe ?
The thing is making sure one is read before the other.
Any way I probably will just learn the language better and do it from recovery console.
Thanks again
TheNewGuy said:
Yea thats the easy way!...
(Seriously I'm not that good at Linux Command Line code,wording,but i'm getting there.)
And I know that most roms now have a script called something like in /system/etc/init.d/20userinit that runs at startup and checks to see if a userinit.sh is present in sd-ext,if so it runs it.Also I noticed that the script can be there but if it is CHMOD to 777 it wont run. This is the "Reset script" Set to restet to something you like and run other tasks to help Fix/Diagnose probs.
The OC changes would be made from a different script such as 86supersettings
Or a userinit located in system/sd maybe ?
The thing is making sure one is read before the other.
Any way I probably will just learn the language better and do it from recovery console.
Thanks again
Click to expand...
Click to collapse
chmod 777 makes it rw and executable by everyone!!!!!!!!
have a look here
http://www.comptechdoc.org/os/linux/usersguide/linux_ugfilesp.html
but as I mentioned above, init ( the initial progam runs as root and doesn't care about permissions, ( it wouldn't be very good at doing initialising the system if it had to seek permission )
Yea your right. Well I said I wasn't that good at this linux stuff! Now I Proved it.
Any way as you can see this is more of a request..... I still think it's a good Idea.
Thanks for your help FireRat.
Keep it simple. If a change in userinit.sh breaks your system, reboot to recovery and edit it and reboot again.
Click to expand...
Click to collapse
I understand how I could manualy Replace the modified script with a default one that was on my sdcard from within recovery after a faild OC change...but..
Are you saying I could actualy modify the original script from recover? Do you have any info on how? A link?
TheNewGuy said:
I understand how I could manualy Replace the modified script with a default one that was on my sdcard from within recovery after a faild OC change...but..
Are you saying I could actualy modify the original script from recover? Do you have any info on how? A link?
Click to expand...
Click to collapse
If you have RA-Recovery, adb works, so you can pull/push the userinit.sh script. You can also enter the terminal and use vi to edit it from recovery. You may have to mount the ext partition first, but that's pretty easy. "mount /system/sd" will do it, if /system/sd doesn't exist, "mkdir /system/sd".
Ok, Thanks that makes sense. I'm still learning adb though. And I tried vi once before with no luck. But now I know what to learn about.
Thanks a lot I appreciate it.
TheNewGuy said:
Ok, Thanks that makes sense. I'm still learning adb though. And I tried vi once before with no luck. But now I know what to learn about.
Thanks a lot I appreciate it.
Click to expand...
Click to collapse
ok, this would do what you want
/system/bin/shutdown
bold is new
Code:
#!/system/bin/sh
stop;
stop dhcpcd;
sleep 1;
[B]echo "1" > /data/cleanshutdown[/B]
for i in `cat /proc/mounts | cut -f 2 -d " "`;
do
busybox mount -o remount,ro $i 2>&1 > /dev/null;
done
sync;
if [ "$1" = "-r" ];
then
toolbox reboot -f;
else
toolbox reboot -fp;
fi
your script
Code:
#!/system/bin/sh
if [ "`cat /data/cleanshutdown`" != "1" ];
then
echo "shutdown was not clean"
[B]your tweaks[/B]
else
echo "shutdown was clean"
[B]your tweaks[/B]
fi
echo "0" > /data/cleanshutdown
I'm not sure you need it,
this is for education value, if you want to play ^^^ is where to start
Thank You!
That is perfect
I need to add all of this to the startup script right?
if [ "`cat /data/cleanshutdown`" != "1" ];
then
echo "shutdown was not clean"
your tweaks
else
echo "shutdown was clean"
your tweaks
fi
echo "0" > /data/cleanshutdown
Click to expand...
Click to collapse
I am going to use the beta boot up script from ZKX called 86Supersettings, but I could use a userinit/user.conf like most do. Correct?
TheNewGuy said:
Thank You!
That is perfect
I need to add all of this to the startup script right?
I am going to use the beta boot up script from ZKX called 86Supersettings, but I could use a userinit/user.conf like most do. Correct?
Click to expand...
Click to collapse
well, a .conf file should be just that
a file with configurations , not an executable script
well, a .conf file should be just that
a file with configurations , not an executable script
Click to expand...
Click to collapse
OK. I guess I meant both together. I would use the user.conf to make tweaks. Then have to modify the userinit.sh with the part you made. Something like.
#!/system/bin/sh--LEAVE THIS OUT. ITS ALL READY AT THE BEGINNING
if [ "`cat /data/cleanshutdown`" != "1" ];
then
echo "shutdown was not clean"
Dont run user.conf
and set cpu or other stuff to "default"
else
echo "shutdown was clean"
Run user.conf for tweaked settings
fi
echo "0" > /data/cleanshutdown
Click to expand...
Click to collapse
If I'm way off then I guess I need to re-read the Userinit thread.
TheNewGuy said:
OK. I guess I meant both together. I would use the user.conf to make tweaks. Then have to modify the userinit.sh with the part you made. Something like.
If I'm way off then I guess I need to re-read the Userinit thread.
Click to expand...
Click to collapse
well, in practise it doesn't matter
the file extension is only for use humans, if I'm looking in a directory and I see .conf I expect it to be a configuration file, I see .sh, its a shell script, .py python, pl perl .......
I see. Well Thanks again for your help. Your script does work. I tried it. crash on purpose.
I still have a lot to learn.
Folks;
1) If you're OC'ing via SetCPU, remember that this doesn't change the recovery kernel, and you can uninstall SetCPU from Recovery. From there, all you need is a "safe" userinit.sh.
3) If you're OC'ing via userinit.sh -- same deal. Your phone crashes on you and you just edit it to a safe config from recovery.
Tweak away.
This is what I ended up with
Thanks to
XxKolohexX
FireRat
Licknuts
Code:
#!/system/bin/sh
#
echo 255 >/sys/class/leds/blue/brightness;
echo "+++ Now entering the speedy madness of Z.X.D.!"
echo "----- let's clear that Cache first."
echo "----- Too much DBs make System go sloow..."
echo "----- Also be shure to check out CacheMate"
echo "----- It's in the Market. (Made by Android AppCritic)."
echo "----- It's way more powerfull than this script!"
echo "----- (Times 10 or 100... Clears everything :P)"
echo "----- And this script already took hours to build..."
echo "----- domenukk - 2010."
find /data/data -name app_admob_cache | while read line; do du -s $line/* | cut -f1; rm -Rf $line/*; done;
find /data/data -name cache | while read line; do du -s $line/* | cut -f1; rm -Rf $line/*; done;
find /data/data -name google_analytics.db | while read line; do du -s $line | cut -f1; rm -Rf $line; done;
find /data/data -name webviewCache.db | while read line; do du -s $line | cut -f1; rm -Rf $line; done;
rm -rf /data/data/com.facebook.katana/files
rm -rf /data/data/com.google.android.apps.genie.geniewidget/app_news_image_cache
rm -rf /data/data/com.code.i.music/app_admob_cache
rm -rf /data/data/fm.last.android/databases/google_analytics.db
echo "--- All the Cache has been cleared."
sleep 10
echo 0 >/sys/class/leds/blue/brightness;
####determin if shutdown was clean####
if [ "`cat /data/cleanshutdown`" != "1" ];
then
####RUN CLEAN SHUTDOWN SCRIPT####
echo 255 >/sys/class/leds/green/brightness;
####Turbo Script by [email protected]####
####Prioritize everyting ####
echo "----- Enabling Turbo."
dirty_writeback_centisecs=500
/system/bin/prior &
#
# Linux-SWAP
#
if [ -e /dev/block/mmcblk0p3 ];
then
if [ -n /dev/block/mmcblk0p3 ];
then
echo "+++ Set Linux Swap"
busybox mkswap /dev/block/mmcblk0p3;
fi;
if [ -e /dev/block/mmcblk0p3 ];
then
echo "+++ Set Swapiness"
echo 100 > /proc/sys/vm/swappiness;
echo "+++ Activate Swap"
busybox swapon /dev/block/mmcblk0p3;
fi;
fi;
####Better CPU Settings...####
echo "----- Speed up the CPU"
echo 633600 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 122800 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq;
echo 95 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold;
echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/ignore_nice_load;
echo 100000 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate;
echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/powersave_bias;
echo 0 >/sys/class/leds/green/brightness;
echo 255 >/sys/class/leds/blue/brightness;
else
####RUN DIRTY SHUTDOWN SCRIPT####
echo 255 >/sys/class/leds/red/brightness;
####Turbo Script by [email protected]####
####Prioritize everyting ####
echo "----- Enabling Turbo."
dirty_writeback_centisecs=500
/system/bin/prior &
#
# Linux-SWAP
#
if [ -e /dev/block/mmcblk0p3 ];
then
if [ -n /dev/block/mmcblk0p3 ];
then
echo "+++ Set Linux Swap"
busybox mkswap /dev/block/mmcblk0p3;
fi;
if [ -e /dev/block/mmcblk0p3 ];
then
echo "+++ Set Swapiness"
echo 83 > /proc/sys/vm/swappiness;
echo "+++ Activate Swap"
busybox swapon /dev/block/mmcblk0p3;
fi;
fi;
####Better CPU Settings...####
echo "----- Speed up the CPU"
echo 576000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 122800 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq;
echo 45 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold;
echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/ignore_nice_load;
echo 2000000 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate;
echo 200 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/powersave_bias;
fi;
echo "0" > /data/cleanshutdown
echo "+++ continue on lame stock SuperD boot "
##Clearing Davlik-Cache##
for dc in dalvik-cache;
do
umount /cache/$dc;
rm -fr /cache/$dc;
mkdir /cache/$dc;
chown 1000:1000 /cache/$dc;
chmod 771 /cache/$dc;
mount -o bind /data/$dc /cache/$dc;
done;
Named 86supersettings so it runs after userinit.sh if one exists.
I put some Led indicators in so you can tell if it ran right at boot up. (about all I did besides copy and paste) Thinking about adding some other stuff like repair ext, or some kind of log to help me see what happed... any suggestions.
OK, here's another Idea for another safety feature...
I would like to "hard code" a temp fail-safe in to the code. I would like to get rid of SetCPU and when OC-ing it's nice to have a temp failsafe.SHUTDOWN!LOL
Any way I guess I would just add a few lines to some existing script in my phone?.... Any suggestions.
Thanks for your time.

Tizen chrooted for Android

Hello xda-developers!
I'm trying to port Tizen for samsung wave 1.
But now I'm doing some research.
This thread will be my research on doing a chrooted scripts and try to boot a Tizen 2 Alpha working through vnc-viewer.
I'll write here my scripts for everyone to test it.
After these scripts an app. But now scripts.
This thread will be updated everytime I get a spare time to write it.
Thanks!
Tutorial:
First download the image from the torrent file.
Copy it for your extsd or sdcard phone/tablet.
It's to copy the image file from Tizen 2 Alpha for these two places.
And on terminal emulator run the tizen_run bash file.
Test it and I will test it too as I'm writing this tutorial and post.
Rename the script tizen_run.sh.txt to tizen_run.sh
Thanks !
PS: This code was changed to work with Tizen 2 Alpha I'm going to test it now.
I've putted here for everyone can get work it too.
Code:
#!/bin/sh
# Modify this according to your needs
DEVICE="/dev/block/mmcblk1p2"
LOOP="yes"
# Maybe this as well
MNT_PATH="/mnt/extsd/tizen"
# Modify only if you know, what are you doing
BINDS="dev dev/pts proc sys mnt/extsd"
ANDROID_BINDS=" /system /data "
TMPS="tmp var/tmp var/log var/run"
MY_MOUNTS=""
unset PS1
# Helper functions
die() {
echo " $1"
exit 1
}
safe_mount() {
mkdir -p "$MNT_PATH""$2"
if [ "$3" ]; then
OPTION=" $3 "
else
OPTION=""
fi
if [ -z "`mount | grep " $MNT_PATH$2 "`" ]; then
mount $OPTION "$1" "$MNT_PATH$2" || die "Can't mount $2!!!"
fi
MY_MOUNTS="$MNT_PATH$2 $MY_MOUNTS"
}
# Real work
[ "`whoami || echo root`" = "root" ] || die "You must be root first!"
LOOP_ARG=""
[ "$LOOP" = "yes" ] || LOOP_ARG=" -o loop "
safe_mount $DEVICE "" "$LOOP_ARG -t ext4 "
for i in $BINDS; do
safe_mount "/$i" "/$i" " -o bind "
done
if [ -d /Removable ]; then
for i in /Removable/*; do
[ -d "$i" ] && safe_mount $i /mnt$i " -o bind "
done
fi
for i in $ANDROID_BINDS; do
safe_mount $i /mnt/android$i " -o bind "
done
for i in $TMPS; do
safe_mount none /$i " -t tmpfs "
done
mount -o remount,ro "$MNT_PATH"
chroot "$MNT_PATH" /sbin/fsck.ext2 -y "$DEVICE"
mount -o remount,rw "$MNT_PATH"
# Tweak configuration of the chroot during first start
if [ \! -f "$MNT_PATH"/etc/profile.d/tweak.sh ]; then
mkdir -p "$MNT_PATH"/home/demo
echo 'nameserver 8.8.8.8' > "$MNT_PATH"/etc/resolv.conf
echo 'net:x:3003:root,demo' >> "$MNT_PATH"/etc/group
echo 'demo:x:1000:100::/home/demo/bin/bash' >> "$MNT_PATH"/etc/passwd
echo 'demo:$1$joWqOQdr$YsapocP32UtdiR3PKBXVM1:15395:0:::::' \
>> "$MNT_PATH"/etc/shadow
sed -i 's|^root:.*|root:$1$joWqOQdr$YsapocP32UtdiR3PKBXVM1:15395:0:::::|' \
"$MNT_PATH"/etc/shadow
echo '#!/bin/sh
export TERM=linux
export LANG="en_US.utf-8"
export EDITOR="busybox vi"
alias vi="busybox vi"
precmd() { :; }
if [ "`whoami`" = root ]; then
export HOME=/root
export USER=root
hostname -F /etc/HOSTNAME
fi
if [ -z "$CHROOTED" ]; then
export CHROOTED=yes
export HOME="/home/demo"
export USER="demo"
su demo
fi
' > "$MNT_PATH"/etc/profile.d/tweak.sh
fi
export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/system/xbin:/system/bin"
# Chroot
chroot "$MNT_PATH" /bin/bash
# Cleanup
echo "Umount everything (yes/NO)?"
read answer
if [ "$answer" = yes ]; then
for i in $MY_MOUNTS; do
umount -l $i
done
fi
For bada
And Bada there any way to run it there,,,, or only possible in Badadroid,,,,:good::,,,,
Only possible in badadroid.
astronfestmon said:
Hello xda-developers!
I'm trying to port Tizen for samsung wave 1.
But now I'm doing some research.
This thread will be my research on doing a chrooted scripts and try to boot a Tizen 2 Alpha working through vnc-viewer.
I'll write here my scripts for everyone to test it.
After these scripts an app. But now scripts.
This thread will be updated everytime I get a spare time to write it.
Thanks!
Tutorial:
First download the image from the torrent file.
Copy it for your extsd or sdcard phone/tablet.
It's to copy the image file from Tizen 2 Alpha for these two places.
And on terminal emulator run the tizen_run bash file.
Test it and I will test it too as I'm writing this tutorial and post.
Thanks !
PS: This code was changed to work with Tizen 2 Alpha I'm going to test it now.
I've putted here for everyone can get work it too.
Code:
#!/bin/sh
# Modify this according to your needs
DEVICE="/dev/block/mmcblk1p2"
LOOP="yes"
# Maybe this as well
MNT_PATH="/mnt/extsd/tizen"
# Modify only if you know, what are you doing
BINDS="dev dev/pts proc sys mnt/extsd"
ANDROID_BINDS=" /system /data "
TMPS="tmp var/tmp var/log var/run"
MY_MOUNTS=""
unset PS1
# Helper functions
die() {
echo " $1"
exit 1
}
safe_mount() {
mkdir -p "$MNT_PATH""$2"
if [ "$3" ]; then
OPTION=" $3 "
else
OPTION=""
fi
if [ -z "`mount | grep " $MNT_PATH$2 "`" ]; then
mount $OPTION "$1" "$MNT_PATH$2" || die "Can't mount $2!!!"
fi
MY_MOUNTS="$MNT_PATH$2 $MY_MOUNTS"
}
# Real work
[ "`whoami || echo root`" = "root" ] || die "You must be root first!"
LOOP_ARG=""
[ "$LOOP" = "yes" ] || LOOP_ARG=" -o loop "
safe_mount $DEVICE "" "$LOOP_ARG -t ext4 "
for i in $BINDS; do
safe_mount "/$i" "/$i" " -o bind "
done
if [ -d /Removable ]; then
for i in /Removable/*; do
[ -d "$i" ] && safe_mount $i /mnt$i " -o bind "
done
fi
for i in $ANDROID_BINDS; do
safe_mount $i /mnt/android$i " -o bind "
done
for i in $TMPS; do
safe_mount none /$i " -t tmpfs "
done
mount -o remount,ro "$MNT_PATH"
chroot "$MNT_PATH" /sbin/fsck.ext2 -y "$DEVICE"
mount -o remount,rw "$MNT_PATH"
# Tweak configuration of the chroot during first start
if [ \! -f "$MNT_PATH"/etc/profile.d/tweak.sh ]; then
mkdir -p "$MNT_PATH"/home/demo
echo 'nameserver 8.8.8.8' > "$MNT_PATH"/etc/resolv.conf
echo 'net:x:3003:root,demo' >> "$MNT_PATH"/etc/group
echo 'demo:x:1000:100::/home/demo/bin/bash' >> "$MNT_PATH"/etc/passwd
echo 'demo:$1$joWqOQdr$YsapocP32UtdiR3PKBXVM1:15395:0:::::' \
>> "$MNT_PATH"/etc/shadow
sed -i 's|^root:.*|root:$1$joWqOQdr$YsapocP32UtdiR3PKBXVM1:15395:0:::::|' \
"$MNT_PATH"/etc/shadow
echo '#!/bin/sh
export TERM=linux
export LANG="en_US.utf-8"
export EDITOR="busybox vi"
alias vi="busybox vi"
precmd() { :; }
if [ "`whoami`" = root ]; then
export HOME=/root
export USER=root
hostname -F /etc/HOSTNAME
fi
if [ -z "$CHROOTED" ]; then
export CHROOTED=yes
export HOME="/home/demo"
export USER="demo"
su demo
fi
' > "$MNT_PATH"/etc/profile.d/tweak.sh
fi
export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/system/xbin:/system/bin"
# Chroot
chroot "$MNT_PATH" /bin/bash
# Cleanup
echo "Umount everything (yes/NO)?"
read answer
if [ "$answer" = yes ]; then
for i in $MY_MOUNTS; do
umount -l $i
done
fi
Click to expand...
Click to collapse
what can we do with this file?
In badadroid vnc-viewer and terminal emulator You can run Tizen under android.
astronfestmon said:
In badadroid vnc-viewer and terminal emulator You can run Tizen under android.
Click to expand...
Click to collapse
sorry for the noobs questions, but how??
Edit 1:
I saw your tutorial just now, but I did not understand what to do in the terminal emulator?
There's no problem at all.
You need to copy the code into a file bash(.sh) with the name tizen_run.sh
Then in badadroid run it an app called terminal emulator to get into vnc-viewer.
As a loopback image inside android.
I'm trying to run it as an application like linuxonandroid.
astronfestmon said:
There's no problem at all.
You need to copy the code into a file bash(.sh) with the name tizen_run.sh
Then in badadroid run it an app called terminal emulator to get into vnc-viewer.
As a loopback image inside android.
I'm trying to run it as an application like linuxonandroid.
Click to expand...
Click to collapse
I think I am not smart enough to do understand you..
But thanks anyway..
Okay.
I'll upload here the file to run on terminal emulator.
I'm testing the app for android.
I'll upload it here.
Something wrong.There are no permission to tizen_run.sh
I can't test
New link for image tizen:
http://tizen-kernel-s8500.googlecode.com/files/tizen.7z.001
Try this command:
sh tizen_run.sh
or
./tizen_run.sh
Copied Tizen.img (latest one) to sd card
Copied tizen_run.sh to sd card
Then on Android (Nand Ver.) Emulator tried
sh tizen_run.sh ---> no such file or directory
./tizen_run.sh ---> not found
I'm going to check it out.
type this on terminal emulator:
cd /mnt/extsd - if exists
cd folder "where the Tizen.img and script is located"
then
sh tizen_run.sh
or
./tizen_run.sh
astronfestmon said:
I'm going to check it out.
type this on terminal emulator:
cd /mnt/extsd - if exists
cd folder "where the Tizen.img and script is located"
then
sh tizen_run.sh
or
./tizen_run.sh
Click to expand...
Click to collapse
Can't execute : Permission denied
I'll post a new file.
To see what happens.
in the first topic i have a txt file rename it on linux.
mv tizen_run.sh.txt tizen_run.sh
news??
Sorry about not saying any news.
Next week another build and a better script with an app for badadroid.

[SCRIPT][UPDATED 03.26.14] Fix Lag, Defrag/Free Memory with |=>TrimDropOff<=|

Updated 03.26.14 - Released v2.1 - bug fixes and code cleaned
Introduction:
I am by no means a developer. I am just an android enthusiast who has learned a bit of bash. The reason I made this script was that settings>>wifi>>advanced was not promptly turning wifi off when my device would sleep; sometimes it would not turn off at all. So I figured since I am making a script to resolve this issue I might as well add a couple of other functions as well. To this end I noticed some people saying THIS APP was helpful and I missed the Flush-O-Matic script from V6 SuperCharger so I added fstrim and drop_caches=3 to the script.
Click to expand...
Click to collapse
What will this do?
The script will allow you to sync wifi, fstrim, and/or drop_caches=3 with sleep and/or it will allow you to schedule fstrim and/or drop_caches=3 using crond. The scheduling option can work on either a hourly (you can choose to run desired programs every hour on the hour, every two hours on the hour, every 3 hours on the hour, etc) or daily basis (you can choose to run desired programs at a given time on the hour).
Both the sync and schedule options will load themselves in to memory each boot and each time your device goes to sleep and/or when scheduled the scripts will depending on your options: (1) sync your data so as to ensure no data is lost; (2) TRIM your /system, /data, and /cache partitions; (3) DROP CACHES = 3; and (4) turn off wifi.
In addition, there is also an on-the-fly script to manually trim partitions and drop caches when desired.
Click to expand...
Click to collapse
Benefits:
Reduce lag/improve i/o efficiency (see THIS and THIS).
Although android automatically invokes fstrim when certain conditions are met, these criteria could seldom if ever be met depending upon your usage style. The init.d script should ensure fstrim is invoked more frequently for most users.
Should use less ram than apps that perform similar functions (I say should because I have never used such apps, but I imagine they consume more that .2-.5 mb of ram).
Click to expand...
Click to collapse
Requirements:
root
init.d
busybox
fstrim (should be in all nexus 4.3+ roms)
Click to expand...
Click to collapse
Warning/Disclaimer:
Although these scripts function as intended on my device – Nexus 7 (2013), SlimKat (weekly), ElementalX...Use at your own risk. Neither I nor XDA are responsible for any possible deleterious effects.
Click to expand...
Click to collapse
Known Issues/Bugs:
If you use the sync option, scripts with a lower priority than Z99 will not execute.
The log files don't always display as intended...dunno why...any help/suggestions would be appreciated.
Let me know if you find any others .
Click to expand...
Click to collapse
Install, Usage/Verification, & Uninstall:
Install -
Note: If you use crond for other tasks, both the install and uninstall routine account for this potential contigency and should leave your other crond tasks uneffects.
make a nandroid backup
download the zip (<<NOT flashable) attached to this post
extract the zip’s contents
if you were/are using the first version of this script manually delete: /etc/init.d/07TrimDropOff, /data/TrimDropOff_Awake.log, and /data/TrimDropOff_Sleep.log
run TrimDropOffInstaller with superuser permission via terminal or script manager.
follow the scripts prompts
reboot
enjoy
Usage/Verification -
Assuming you have followed the install procedure, next, put your device to sleep and then wake it if you are using the sync option.
Now check the various logs in /data/TrimDropOff. The logs will show the time, the script’s PIDs, the path of the PIDs (just to double-check the PIDs are correct), the ram used by the PIDs, action(s) preformed (amount trimmed from each partition and/or if drop_cahes was run), or errors.
If you want verify manually via terminal do [pgrep -f TrimDrop] for the sync option or [pgrep crond] for the scheduling option to get the PIDs, do [cat /proc/PID/cmdline] for each PID to verify it truly belongs to Z99TrimDropOff or crond, and do [dumpsys meminfo | grep PID] for each PID to verify ram usage (this command will yield duplicates, which can be disregarded and may output undesired additional results, which can be filtered by looking through the results for the relevant PID).
To use the on-the-fly script to trim and/or drop as desired, in terminal do [su -c trimdrop].
Should you want to reconfigure your setup, uninstall before reinstalling to avoid potential issues.
Uninstall -
Note: If you use crond for other tasks, both the install and uninstall routine account for this potential contigency and should leave your other crond tasks uneffects.
Rerun TrimDropOffInstaller with superuser permission and use uninstall option at the beginning of the script.
Reboot and all will be back to as it was before.
Click to expand...
Click to collapse
To-Do List:
Make in to an AROMA package.
I don't know, you tell me .
Click to expand...
Click to collapse
Code:
#!/system/bin/sh
# This script was authored by Defiant07 @ xda. Feel free to use it as you see fit, but please give proper credits.
# Big thanks to zeppelinrox, dk_zero-cool, & gu5t3r @ xda for their contributions to portions of this script (see the code of my other script SwapItOn @ xda for detailed citations).
# Read Karl Marx.
input_error(){
echo "That is not a valid input...try again...bye ."
exit 69
}
mount_rw(){
mount -o remount,rw / 2>/dev/null
mount -o remount,rw rootfs 2>/dev/null
busybox mount -o remount,rw / 2>/dev/null
busybox mount -o remount,rw rootfs 2>/dev/null
mount -o remount,rw /system 2>/dev/null
busybox mount -o remount,rw /system 2>/dev/null
busybox mount -o remount,rw $(busybox mount | awk '/system /{print $1,$3}') 2>/dev/null
}
mount_ro(){
mount -o remount,ro / 2>/dev/null
mount -o remount,ro rootfs 2>/dev/null
busybox mount -o remount,ro / 2>/dev/null
busybox mount -o remount,ro rootfs 2>/dev/null
mount -o remount,ro /system 2>/dev/null
busybox mount -o remount,ro /system 2>/dev/null
busybox mount -o remount,ro $(busybox mount | awk '/system /{print $1,$3}') 2>/dev/null
}
clear
if [ ! "`busybox`" ]; then
echo "Missing busybox...try again...bye ."
exit 69
fi
id=$(id); id=${id#*=}; id=${id%%[\( ]*}
if [ "$id" = "0" ] || [ "$id" = "root" ]; then
echo "" 1>/dev/null
else
echo "Not running as root...try again...bye ."
exit 69
fi
if [ ! -d /etc/init.d ]; then
echo "Missing /etc/init.d...try again...bye ."
exit 69
fi
if [ ! "`grep -r fstrim /system/bin`" ] && [ ! "`grep -r fstrim /system/xbin`" ]; then
echo "Missing fstrim...try again...bye ."
exit 69
fi
echo "Do you want to install or uninstall TrimDropOff?"
echo "Note: If you are rerunning this script to"
echo "reconfigure your setup, uninstall first."
echo -n "Input (i)nstall or (u)ninstall: "
read install_uninstall
echo
case $install_uninstall in
i|I)mount_rw
if [ ! -d "/sqlite_stmt_journals" ]; then
mkdir /sqlite_stmt_journals
fi
if [ ! -d "/data/TrimDropOff" ]; then
mkdir /data/TrimDropOff
chmod 755 /data/TrimDropOff
fi;;
u|U)mount_rw
rm /system/etc/init.d/Z99TrimDropOff_Sync 2>/dev/null
rm /system/etc/init.d/07TrimDropOff_Cron 2>/dev/null
rm /system/xbin/trimdrop 2>/dev/null
rm -rf /data/TrimDropOff 2>/dev/null
echo "Are you using cron.d for any other services?"
echo -n "Input es or o: "
read crond_use
echo
case $crond_use in
y|Y)sed '/TrimDropOff/d' -i /system/etc/cron.d/crontabs/root 2>/dev/null;;
n|N)rm -rf /system/etc/cron.d 2>/dev/null;;
*)input_error;;
esac
mount_ro
echo "All done. You can close your app now."
echo "Reboot your device to stop all processes."
exit 0;;
*)input_error;;
esac
wifi_only(){
cat > /system/etc/init.d/Z99TrimDropOff_Sync << EOF
#!/system/bin/sh
tdo_time(){
while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done
while [ 1 ]; do
AWAKE=\`cat /sys/power/wait_for_fb_wake\`
if [ "\$AWAKE" = "awake" ]; then
exec 1>/data/TrimDropOff/Awake.log
svc wifi enable
echo "\$(date +"%r %Y.%m.%d"): Waiting for screen to sleep. Confirming script in memory..."
echo "PIDs:"
pgrep -f TrimDrop
pidls=\`pgrep -f TrimDrop\`
echo "Verify Correct PIDs:"
for i in \$pidls; do
cat /proc/\$i/cmdline
done
echo ""
echo "RAM Usage:"
for i in \$pidls; do
dumpsys meminfo | grep \$i | grep sh | grep -m 1 pid
done
fi
SLEEPING=\`cat /sys/power/wait_for_fb_sleep\`
if [ "\$SLEEPING" = "sleeping" ]; then
exec 1>/data/TrimDropOff/Sleep.log
echo "\$(date +"%r %Y.%m.%d"): Offing."
svc wifi disable
fi
done
}
if [ "\`ps | grep -m 1 [a]ndroid\`" ]; then tdo_time
else exec > /data/TrimDropOff/Sync_BootErrors.log 2>&1
tdo_time &
fi
exit 0
EOF
}
fstrim_only(){
cat > /system/etc/init.d/Z99TrimDropOff_Sync << EOF
#!/system/bin/sh
tdo_time(){
while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done
while [ 1 ]; do
AWAKE=\`cat /sys/power/wait_for_fb_wake\`
if [ "\$AWAKE" = "awake" ]; then
exec 1>/data/TrimDropOff/Awake.log
echo "\$(date +"%r %Y.%m.%d"): Waiting for screen to sleep. Confirming script in memory..."
echo "PIDs:"
pgrep -f TrimDrop
pidls=\`pgrep -f TrimDrop\`
echo "Verify Correct PIDs:"
for i in \$pidls; do
cat /proc/\$i/cmdline
done
echo ""
echo "RAM Usage:"
for i in \$pidls; do
dumpsys meminfo | grep \$i | grep sh | grep -m 1 pid
done
fi
SLEEPING=\`cat /sys/power/wait_for_fb_sleep\`
if [ "\$SLEEPING" = "sleeping" ]; then
exec 1>/data/TrimDropOff/Sleep.log
echo "\$(date +"%r %Y.%m.%d"): Trimming."
echo "/system:"
busybox sync
fstrim -v /system
echo "/data:"
busybox sync
fstrim -v /data
echo "/cache:"
busybox sync
fstrim -v /cache
fi
done
}
if [ "\`ps | grep -m 1 [a]ndroid\`" ]; then tdo_time
else exec > /data/TrimDropOff/Sync_BootErrors.log 2>&1
tdo_time &
fi
exit 0
EOF
}
drop_only(){
cat > /system/etc/init.d/Z99TrimDropOff_Sync << EOF
#!/system/bin/sh
tdo_time(){
while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done
while [ 1 ]; do
AWAKE=\`cat /sys/power/wait_for_fb_wake\`
if [ "\$AWAKE" = "awake" ]; then
exec 1>/data/TrimDropOff/Awake.log
echo "\$(date +"%r %Y.%m.%d"): Waiting for screen to sleep. Confirming script in memory..."
echo "PIDs:"
pgrep -f TrimDrop
pidls=\`pgrep -f TrimDrop\`
echo "Verify Correct PIDs:"
for i in \$pidls; do
cat /proc/\$i/cmdline
done
echo ""
echo "RAM Usage:"
for i in \$pidls; do
dumpsys meminfo | grep \$i | grep sh | grep -m 1 pid
done
fi
SLEEPING=\`cat /sys/power/wait_for_fb_sleep\`
if [ "\$SLEEPING" = "sleeping" ]; then
exec 1>/data/TrimDropOff/Sleep.log
echo "\$(date +"%r %Y.%m.%d"): Dropping."
echo "drop caches:"
busybox sync
busybox sysctl -w vm.drop_caches=3
fi
done
}
if [ "\`ps | grep -m 1 [a]ndroid\`" ]; then tdo_time
else exec > /data/TrimDropOff/Sync_BootErrors.log 2>&1
tdo_time &
fi
exit 0
EOF
}
wifi_fstrim(){
cat > /system/etc/init.d/Z99TrimDropOff_Sync << EOF
#!/system/bin/sh
tdo_time(){
while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done
while [ 1 ]; do
AWAKE=\`cat /sys/power/wait_for_fb_wake\`
if [ "\$AWAKE" = "awake" ]; then
exec 1>/data/TrimDropOff/Awake.log
svc wifi enable
echo "\$(date +"%r %Y.%m.%d"): Waiting for screen to sleep. Confirming script in memory..."
echo "PIDs:"
pgrep -f TrimDrop
pidls=\`pgrep -f TrimDrop\`
echo "Verify Correct PIDs:"
for i in \$pidls; do
cat /proc/\$i/cmdline
done
echo ""
echo "RAM Usage:"
for i in \$pidls; do
dumpsys meminfo | grep \$i | grep sh | grep -m 1 pid
done
fi
SLEEPING=\`cat /sys/power/wait_for_fb_sleep\`
if [ "\$SLEEPING" = "sleeping" ]; then
exec 1>/data/TrimDropOff/Sleep.log
echo "\$(date +"%r %Y.%m.%d"): Trimming, Offing."
echo "/system:"
busybox sync
fstrim -v /system
echo "/data:"
busybox sync
fstrim -v /data
echo "/cache:"
busybox sync
fstrim -v /cache
svc wifi disable
fi
done
}
if [ "\`ps | grep -m 1 [a]ndroid\`" ]; then tdo_time
else exec > /data/TrimDropOff/Sync_BootErrors.log 2>&1
tdo_time &
fi
exit 0
EOF
}
wifi_drop(){
cat > /system/etc/init.d/Z99TrimDropOff_Sync << EOF
#!/system/bin/sh
tdo_time(){
while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done
while [ 1 ]; do
AWAKE=\`cat /sys/power/wait_for_fb_wake\`
if [ "\$AWAKE" = "awake" ]; then
exec 1>/data/TrimDropOff/Awake.log
svc wifi enable
echo "\$(date +"%r %Y.%m.%d"): Waiting for screen to sleep. Confirming script in memory..."
echo "PIDs:"
pgrep -f TrimDrop
pidls=\`pgrep -f TrimDrop\`
echo "Verify Correct PIDs:"
for i in \$pidls; do
cat /proc/\$i/cmdline
done
echo ""
echo "RAM Usage:"
for i in \$pidls; do
dumpsys meminfo | grep \$i | grep sh | grep -m 1 pid
done
fi
SLEEPING=\`cat /sys/power/wait_for_fb_sleep\`
if [ "\$SLEEPING" = "sleeping" ]; then
exec 1>/data/TrimDropOff/Sleep.log
echo "\$(date +"%r %Y.%m.%d"): Dropping, Offing."
echo "drop caches:"
busybox sync
busybox sysctl -w vm.drop_caches=3
svc wifi disable
fi
done
}
if [ "\`ps | grep -m 1 [a]ndroid\`" ]; then tdo_time
else exec > /data/TrimDropOff/Sync_BootErrors.log 2>&1
tdo_time &
fi
exit 0
EOF
}
fstrim_drop(){
cat > /system/etc/init.d/Z99TrimDropOff_Sync << EOF
#!/system/bin/sh
tdo_time(){
while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done
while [ 1 ]; do
AWAKE=\`cat /sys/power/wait_for_fb_wake\`
if [ "\$AWAKE" = "awake" ]; then
exec 1>/data/TrimDropOff/Awake.log
echo "\$(date +"%r %Y.%m.%d"): Waiting for screen to sleep. Confirming script in memory..."
echo "PIDs:"
pgrep -f TrimDrop
pidls=\`pgrep -f TrimDrop\`
echo "Verify Correct PIDs:"
for i in \$pidls; do
cat /proc/\$i/cmdline
done
echo ""
echo "RAM Usage:"
for i in \$pidls; do
dumpsys meminfo | grep \$i | grep sh | grep -m 1 pid
done
fi
SLEEPING=\`cat /sys/power/wait_for_fb_sleep\`
if [ "\$SLEEPING" = "sleeping" ]; then
exec 1>/data/TrimDropOff/Sleep.log
echo "\$(date +"%r %Y.%m.%d"): Trimming, Dropping."
echo "/system:"
busybox sync
fstrim -v /system
echo "/data:"
busybox sync
fstrim -v /data
echo "/cache:"
busybox sync
fstrim -v /cache
echo "drop caches:"
busybox sync
busybox sysctl -w vm.drop_caches=3
fi
done
}
if [ "\`ps | grep -m 1 [a]ndroid\`" ]; then tdo_time
else exec > /data/TrimDropOff/Sync_BootErrors.log 2>&1
tdo_time &
fi
exit 0
EOF
}
wifi_fstrim_drop(){
cat > /system/etc/init.d/Z99TrimDropOff_Sync << EOF
#!/system/bin/sh
tdo_time(){
while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done
while [ 1 ]; do
AWAKE=\`cat /sys/power/wait_for_fb_wake\`
if [ "\$AWAKE" = "awake" ]; then
exec 1>/data/TrimDropOff/Awake.log
svc wifi enable
echo "\$(date +"%r %Y.%m.%d"): Waiting for screen to sleep. Confirming script in memory..."
echo "PIDs:"
pgrep -f TrimDrop
pidls=\`pgrep -f TrimDrop\`
echo "Verify Correct PIDs:"
for i in \$pidls; do
cat /proc/\$i/cmdline
done
echo ""
echo "RAM Usage:"
for i in \$pidls; do
dumpsys meminfo | grep \$i | grep sh | grep -m 1 pid
done
fi
SLEEPING=\`cat /sys/power/wait_for_fb_sleep\`
if [ "\$SLEEPING" = "sleeping" ]; then
exec 1>/data/TrimDropOff/Sleep.log
echo "\$(date +"%r %Y.%m.%d"): Trimming, Dropping, Offing."
echo "/system:"
busybox sync
fstrim -v /system
echo "/data:"
busybox sync
fstrim -v /data
echo "/cache:"
busybox sync
fstrim -v /cache
echo "drop caches:"
busybox sync
busybox sysctl -w vm.drop_caches=3
svc wifi disable
fi
done
}
if [ "\`ps | grep -m 1 [a]ndroid\`" ]; then tdo_time
else exec > /data/TrimDropOff/Sync_BootErrors.log 2>&1
tdo_time &
fi
exit 0
EOF
}
echo "Do you want to sync fstrim, drop_caches=3, and/or"
echo "wifi with sleep?"
echo "WARNING: This will cause init.d scripts with a"
echo "priority lower than Z99 to NOT execute."
echo -n "Input es or o: "
read TDOsync
echo
case $TDOsync in
y|Y)echo "Which function(s) would you like to sync with sleep?"
echo "Input 1 for wifi only, 2 for fstrim only,"
echo "3 for drop_caches only, 4 for wifi and fstrim"
echo "5 for wifi and drop, 6 for fstrim and drop, or"
echo -n "7 for all: "
read sync_opt
echo
case $sync_opt in
1)wifi_only;;
2)fstrim_only;;
3)drop_only;;
4)wifi_fstrim;;
5)wifi_drop;;
6)fsrim_drop;;
7)wifi_fstrim_drop;;
*)input_error;;
esac
chmod 755 /system/etc/init.d/Z99TrimDropOff_Sync;;
n|N);;
*)input_error;;
esac
only_fstrim(){
cat > /data/TrimDropOff/TrimDropOff_Cron << EOF
#!/system/bin/sh
# This script was authored by Defiant07 @ xda. Feel free to use it as you see fit, but please give proper credits.
# Read Karl Marx.
exec 1>/data/TrimDropOff/CronRan.log
echo "\$(date +"%r %Y.%m.%d"): Trimming."
echo "/system:"
busybox sync
fstrim -v /system
echo "/data:"
busybox sync
fstrim -v /data
echo "/cache:"
busybox sync
fstrim -v /cache
exit 0
EOF
}
only_drop(){
cat > /data/TrimDropOff/TrimDropOff_Cron << EOF
#!/system/bin/sh
# This script was authored by Defiant07 @ xda. Feel free to use it as you see fit, but please give proper credits.
# Read Karl Marx.
exec 1>/data/TrimDropOff/CronRan.log
echo "\$(date +"%r %Y.%m.%d"): Dropping."
echo "drop caches:"
busybox sync
busybox sysctl -w vm.drop_caches=3
exit 0
EOF
}
both_funct(){
cat > /data/TrimDropOff/TrimDropOff_Cron << EOF
#!/system/bin/sh
# This script was authored by Defiant07 @ xda. Feel free to use it as you see fit, but please give proper credits.
# Read Karl Marx.
exec 1>/data/TrimDropOff/CronRan.log
echo "\$(date +"%r %Y.%m.%d"): Trimming, Dropping."
echo "/system:"
busybox sync
fstrim -v /system
echo "/data:"
busybox sync
fstrim -v /data
echo "/cache:"
busybox sync
fstrim -v /cache
echo "drop caches:"
busybox sync
busybox sysctl -w vm.drop_caches=3
exit 0
EOF
}
cron_starter(){
cat > /system/etc/init.d/07TrimDropOff_Cron << EOF
#!/system/bin/sh
# This script was authored by Defiant07 @ xda. Feel free to use it as you see fit, but please give proper credits.
# Read Karl Marx.
tdo_time(){
while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done
crond
exec 1>/data/TrimDropOff/CronBoot.log
echo "\$(date +"%r %Y.%m.%d"): cron.d service started."
echo "PIDs:"
pgrep crond
pidls=\`pgrep crond\`
echo "Verify Correct PIDs:"
for i in \$pidls; do
cat /proc/\$i/cmdline
done
echo ""
echo "RAM Usage:"
for i in \$pidls; do
dumpsys meminfo | grep \$i | grep -m 1 crond
done
}
if [ "\`ps | grep -m 1 [a]ndroid\`" ]; then tdo_time
else exec > /data/TrimDropOff/Cron_BootErrors.log 2>&1
tdo_time &
fi
exit 0
EOF
}
echo "Do you want to run fstrim and/or drop_caches"
echo "on a schedule?"
echo -n "Input es or o: "
read sched_opt
echo
case $sched_opt in
y|Y)echo "Which function do you want to schedule?"
echo "Input (f)strim only, (d)rop_caches only,"
echo -n "or (b)oth: "
read funct_opt
echo
case $funct_opt in
f|F)only_fstrim;;
d|D)only_drop;;
b|B)both_funct;;
*)input_error;;
esac
chmod 755 /data/TrimDropOff/TrimDropOff_Cron
echo "Do you want to schedule the function(s)"
echo "on an hourly or daily basis?"
echo -n "Input (h)ourly or (d)aily: "
read sched_opt
echo
if [ ! -d "/system/etc/cron.d" ]; then
mkdir /system/etc/cron.d
chmod 755 /system/etc/cron.d
fi
if [ ! -d "/system/etc/cron.d/crontabs" ]; then
mkdir /system/etc/cron.d/crontabs
chmod 755 /system/etc/cron.d/crontabs
fi
cron_starter
chmod 755 /system/etc/init.d/07TrimDropOff_Cron
case $sched_opt in
h|H)echo "Input 1 to run every hour, 2 to run every two hours,"
echo -n "3 to run every three hours...etc: "
read hour_opt
echo
if [ ! "`echo $hour_opt | awk '!/[^0-9]/'`" ]; then
input_error
fi
if [ -f "/system/etc/cron.d/crontabs/root" ]; then
echo "0 */$hour_opt * * * nohup /data/TrimDropOff/TrimDropOff_Cron" >> /system/etc/cron.d/crontabs/root
else
echo "0 */$hour_opt * * * nohup /data/TrimDropOff/TrimDropOff_Cron" > /system/etc/cron.d/crontabs/root
fi
chmod 755 /system/etc/cron.d/crontabs/root;;
d|D)echo "Input 0 to run at midnight every day,"
echo "1 to run at 1:00 am...13 to run at 1:00 pm"
echo -n "...etc...up to 23: "
read daily_opt
echo
if [ ! "`echo $daily_opt | awk '!/[^0-9]/ && $1<=23'`" ]; then
input_error
fi
if [ -f "/system/etc/cron.d/crontabs/root" ]; then
echo "0 $daily_opt * * * nohup /data/TrimDropOff/TrimDropOff_Cron" >> /system/etc/cron.d/crontabs/root
else
echo "0 $daily_opt * * * nohup /data/TrimDropOff/TrimDropOff_Cron" > /system/etc/cron.d/crontabs/root
fi
chmod 755 /system/etc/cron.d/crontabs/root;;
*)input_error;;
esac;;
n|N);;
*)input_error;;
esac
cat > /system/xbin/trimdrop << EOF
#!/system/bin/sh
# This script was authored by Defiant07 @ xda. Feel free to use it as you see fit, but please give proper credits.
# Read Karl Marx.
clear
trimmer(){
echo "/system:"
busybox sync
fstrim -v /system
echo "/data:"
busybox sync
fstrim -v /data
echo "/cache:"
busybox sync
fstrim -v /cache
}
dropper(){
echo "drop caches:"
busybox sync
busybox sysctl -w vm.drop_caches=3
}
echo -n "Do you want to run (f)strim, (d)rop_caches=3, or (b)oth? "
read funct_opt
echo
case \$funct_opt in
f|F)trimmer;;
d|D)dropper;;
b|B)trimmer
dropper;;
*)echo "That is not a valid input...try again...bye ."
exit 69;;
esac
echo
echo "All done...enjoy! You can close your app now."
exit 0
EOF
chmod 755 /system/xbin/trimdrop
mount_ro
echo "In addition to making the files required by"
echo "your desired configuration, I have also made"
echo "an on-the-fly script to run fstrim and/or"
echo "drop_caches on-demand."
echo "To use it, in terminal do: su -c trimdrop"
echo
sleep 3
echo "Reboot your device to start your desired services."
echo
sleep 3
echo "If you want to know how to verify everything"
echo "is working, read the script's OP (FFS)!"
echo
sleep 5
echo "All done...enjoy! You can close your app now."
exit 0
Click to expand...
Click to collapse
Changelog:
v2.0
made in to installer script
added cron options
added bootloop precautions to the init.d scripts (should make it compatible with all devices that meet the requirments)
the on-the-fly script, trimdrop, now allows user to choose fstrim and/or drop_caches=3
added more syncs to further ensure no data is lost
a bunch of other stuff I probably forget
v2.1
bug fixes - fixed issue if using only sync option (missing directory); fixed display of irrelevant errors in uninstall routine
cleaned code a bit (reduced redundancy)
Click to expand...
Click to collapse
Download History:
Defiant07s_TrimDropOff.zip - [Click for QR Code] (1.6 KB, 162 views)
Defiant07s_TrimDropOff_v2.0_[NOT_FLASHABLE].zip - [Click for QR Code] (3.0 KB, 89 views)
Click to expand...
Click to collapse
Credits:
Big thanks to @zeppelinrox, @dk_zero-cool, & @gu5t3r for their contributions to portions of this script (see the code of my other script SwapItOn for detailed citations).
Much thanks to @mdamaged for spotting the issue with sync init.d script and his note regarding syncing data.
Click to expand...
Click to collapse
Don't forget to click THANKS and RATE 5 STARS if you found this useful :highfive:.
peep my other script SwapItOn
Update to v2.1 if you were only using the sync option.
If you were using both the sync and schedule options or only the schedule option there is no need to update; the bug I found would not effect you.​
reserved...on the off chance it will be needed
Thanks, sounds interesting. I'm assuming the zip can be flashed right after flashing a new rom?
MidnightDevil said:
Thanks, sounds interesting. I'm assuming the zip can be flashed right after flashing a new rom?
Click to expand...
Click to collapse
Not a flashable ZIP per line 2.
AnarchoXen said:
Not a flashable ZIP per line 2.
Click to expand...
Click to collapse
Oh, thanks
Is compatible with custom kernel? Franco in my case
vía n7II r-paco
Will performing trimming operations too frequently cause additional flash memory degradation?
MidnightDevil said:
Thanks, sounds interesting. I'm assuming the zip can be flashed right after flashing a new rom?
Click to expand...
Click to collapse
As you were informed the zip is NOT flashable. If there is sufficient interest (say a 100 downloads) I'll make it flashable/aroma.
jordirpz said:
Is compatible with custom kernel? Franco in my case
vía n7II r-paco
Click to expand...
Click to collapse
Yes, it should be compatible...the fstrim utility is part of the rom (it should be in all nexus 4.3+ roms).
creeve4 said:
Will performing trimming operations too frequently cause additional flash memory degradation?
Click to expand...
Click to collapse
No, to my limited knowledge it should not be harmful (in fact it should increase lifespan - google "fstrim lifespan"). Did a quick google search but could not find anything definitive/reliable regarding frequency...what I did see seemed to suggest 'no' though.
If you are concerned about the frequency, you could not install the init.d script and just use the on-the-fly script, trimdrop, to trim on-demand. Should there be interest and if I have the motivation and time, I have been thinking about making this in to an installer script and/or aroma zip with cron-based options so it could be scheduled hourly, daily, or weekly.
Scheduling options would be awesome!
creeve4 said:
Scheduling options would be awesome!
Click to expand...
Click to collapse
+1
creeve4 said:
Scheduling options would be awesome!
Click to expand...
Click to collapse
BUBA0071 said:
+1
Click to expand...
Click to collapse
Seems there is a decent amount of interest (almost 100 downloads already ...thanks peeps), as such I'll add options and make things more configurable.
Regarding scheduling, I was thinking of doing hourly, daily (with ability to choose time), and weekly (with ability to choose day and time) options. Would every other hour or some other setting be desirable?
Regarding installation, what would be the preferred method, an installer script (e.g. V6 SuperCharger) or AROMA? Flashable zips would be another option, but would have less options/be less configurable.
Gimme some feedback and I'll put something together in the next week or two depending on work and my motivation .
wasn't this a nexus 7 2012 issue and fixed in the new version 2013?
defiant07 said:
Seems there is a decent amount of interest (almost 100 downloads already ...thanks peeps), as such I'll add options and make things more configurable.
Regarding scheduling, I was thinking of doing hourly, daily (with ability to choose time), and weekly (with ability to choose day and time) options. Would every other hour or some other setting be desirable?
Regarding installation, what would be the preferred method, an installer script (e.g. V6 SuperCharger) or AROMA? Flashable zips would be another option, but would have less options/be less configurable.
Gimme some feedback and I'll put something together in the next week or two depending on work and my motivation .
Click to expand...
Click to collapse
My 2 cents:
I would choose a daily option for my device.
I prefer Aroma over a script, but if you cannot get the customization you want with Aroma, then by all means go with a script.
Thanks again for the script and willingness to make it even better!
Thanks for the scripts, I time my startup, and this improved startup time by about 3-4secs, among other noticible improvements, apparently the stock OS does not run fstrim enough, initial operations freed several gigs on the data partition, and hundreds of megs on the others...
creeve4 said:
My 2 cents:
I would choose a daily option for my device.
I prefer Aroma over a script, but if you cannot get the customization you want with Aroma, then by all means go with a script.
Thanks again for the script and willingness to make it even better!
Click to expand...
Click to collapse
+1
Im going to turn this into a cron job, that will take care of scheduling, unless anyone else gets there first ( please lol )
Will give it a go in its present form, whats its resource footprint just sitting there waiting for screen off ?
Can we trigger the action from the screen off event ? or some other interupt type way ?
Great script by the way, your bash is damn site better than mine, jealous lol
KiaraTheDragon said:
wasn't this a nexus 7 2012 issue and fixed in the new version 2013?
Click to expand...
Click to collapse
Yes, I think this is true to a degree...it was more of a problem on the 2012 and other nexus devices. See the links in the OP for the conditions that need to be met for fstrim to autorun...for some users (myself included) the conditions will seldom if ever be met. Also see @mdamaged post; I get similar results the first time fstrim is initiated by my script after each boot...subsequent runs normally only frees up memory on /data.
creeve4 said:
My 2 cents:
I would choose a daily option for my device.
I prefer Aroma over a script, but if you cannot get the customization you want with Aroma, then by all means go with a script.
Thanks again for the script and willingness to make it even better!
Click to expand...
Click to collapse
imfun said:
+1
Click to expand...
Click to collapse
Okay will get to making an AROMA package...it will be my first, but it looks easy enough :fingers-crossed:...gimme a week or two to put it together and fully test.
mdamaged said:
Thanks for the scripts, I time my startup, and this improved startup time by about 3-4secs, among other noticible improvements, apparently the stock OS does not run fstrim enough, initial operations freed several gigs on the data partition, and hundreds of megs on the others...
Click to expand...
Click to collapse
Thanks for the feedback. I get similar results.
jubei_mitsuyoshi said:
Im going to turn this into a cron job, that will take care of scheduling, unless anyone else gets there first ( please lol )
Will give it a go in its present form, whats its resource footprint just sitting there waiting for screen off ?
Can we trigger the action from the screen off event ? or some other interupt type way ?
Great script by the way, your bash is damn site better than mine, jealous lol
Click to expand...
Click to collapse
See the first post on this page and my response to @creeve4 and @imfun in this post. I will make an AROMA package with cron options for fstrim and drop_caches=3.
However, should you feel ambitious and beat me to it, props to you...I will give you full credit in the OP and link your post as the d/l source so you should get the 'thanks' too.
Regarding triggering with screen on/off or some other event: It can probably be done, but I it's beyond my knowledge (screen on/off was actually the first trigger event I looked in to using, but despite fairly extensive searching I could not find how to detect it).
Regarding resource footprint: Read the OP (usage section) it explains where to find the log which contains this info and how to do it via terminal (should you not trust me )...also see OP (benefits section): in all my testing I have never seen it use more that .8 mb, but most of the time it is less than .2 mb.
Okay will get to making an AROMA package...it will be my first, but it looks easy enough :fingers-crossed:...gimme a week or two to put it together and fully test.
Click to expand...
Click to collapse
Can't wait already, because after whole day or two, hard usage of my nexus 7 tablet, the tablet starts to get laggy. I can see this on web browsing, touch press delay time, and onyl rebooting seems to help... Hope after istaling this will solve the problems
ohhh no dont want any credit lol lol, i have turned it into a cron job quite simply by adding it to the cron initilising script
Code:
###########
# IMPORTS #
###########
. /system/etc/init.d.cfg
#############
# FUNCTIONS #
#############
symlink_system_bin() {
# crond has "/bin/sh" hardcoded
if busybox [ ! -h /bin ]
then
mount -o remount,rw rootfs /
busybox ln -s /system/bin /bin
mount -o remount,ro rootfs /
fi
}
export_timezone() {
# set timezone (if you're not between -0500 and -0800 you get PST)
# todo - support other timezones
timezone=`date +%z`
if busybox [ $timezone = "-0800" ]; then
TZ=PST8PDT
elif busybox [ $timezone = "-0700" ]; then
TZ=MST7MDT
elif busybox [ $timezone = "-0600" ]; then
TZ=CST6CDT
elif busybox [ $timezone = "-0500" ]; then
TZ=EST5EDT
else
TZ=PST8PDT
fi
export TZ
}
set_crontab() {
# use /data/cron, call the crontab file "root"
if busybox [ -e /data/cron/root ]
then
mkdir -p /data/cron
cat > /data/cron/root << EOF
0 20 * * * sync; echo 3 > /proc/sys/vm/drop_caches
0 20 * * * sync; fstrim -v /system
0 20 * * * sync; fstrim -v /data
0 20 * * * sync; fstrim -v /cache
01 * * * * busybox run-parts /system/etc/cron/cron.hourly
02 4 * * * busybox run-parts /system/etc/cron/cron.daily
22 4 * * 0 busybox run-parts /system/etc/cron/cron.weekly
EOF
fi
busybox crond -c /data/cron
}
########
# MAIN #
########
if $enable_cron -a is_busybox_applet_available crond
then
symlink_system_bin
export_timezone
set_crontab
fi
adding the lines
Code:
0 20 * * * sync; echo 3 > /proc/sys/vm/drop_caches
0 20 * * * sync; fstrim -v /system
0 20 * * * sync; fstrim -v /data
0 20 * * * sync; fstrim -v /cache
should drop the caches and fstrim every 8 hours, oviously set to anything you want.
i also stuck it in boot at the end
/system/etc/init.d/92jubei
Code:
#!/system/bin/sh
if $file_system_speedups
then
busybox mount -o remount,noatime,barrier=0,nobh /system
busybox mount -o remount,noatime /data
busybox mount -o remount,noatime,barrier=0,nobh /cache
else
busybox mount -o remount,noatime,nobh /system
busybox mount -o remount,noatime /data
busybox mount -o remount,noatime,nobh /cache
fi
echo "$(date +"%r %Y.%m.%d"): Trimming, Dropping."
busybox sync
echo "/system:"
fstrim -v /system
echo "/data:"
fstrim -v /data
echo "/cache:"
fstrim -v /cache
echo "drop caches:"
busybox sysctl -w vm.drop_caches=3
exit 0
For an aroma script you will prob have to stick the file in /system/etc/cron/cron.hourly, daily, weekly and just give peeps that choice, will be most simple way. Ps not a fan of aroma lol
Ok, I should have spotted this issue right away, but did not, so here goes. It seems the use of while loop in the script in the OP causes any scripts with a lower priority in init.d to never get ran, if the script in the OP is the only one in your init.d this does not matter, nor should it matter if you have at boot script with a higher priority (they get ran before the OPs script).
I run the ElementalX kernel which depends on a init.d to initialize some parameters for the kernel, with this script in init.d they never get initialized, in my case this resulted in some things not 'taking' such as the battery life extender, which on my device, is set to stop charging at 4100mv, however, since the while loop kept the ElementalX init.d from running, it kept charging to ~4300mv, this is how I noticed (actually none of my settings wrt ElementalX were being initialized, but this symptom was most pronounced).
A simple fix would be to move up the priority of the ElementalX init.d script, but this would have to be done after each flash, and frankly since I run Tasker anyway, I saw no need for this, what I did was remove the OPs script from init.d and simply made a very simple task in Tasker to run /system/xbin/trimdrop when display goes off, it could just as easily be a time event.
Anyways, hope that helps someone who may come across this with other kernels, or other at-boot scripts which depend on being ran before the OPs script.
Again, thanks to the OP for his work. Also, I added another sync just before the drop caches, since the state of dirtyness could change after the fstrims.

Using command echo .sh file doesn't work in recovery

I'm trying to understand why using echo command in sh file doesn't work in recovery.
I've made a flashable zip with 7-zip, it contains a shell script.
The updater-script is
Code:
ui_print("");
run_program("/sbin/busybox", "mount", "/system");
run_program("/sbin/busybox", "mount", "/data");
package_extract_dir("test", "/tmp");
set_perm(0, 0, 0777, "/tmp/test.sh");
run_program("/tmp/test.sh");
delete_recursive("/tmp");
unmount("/system");
unmount("/data");
and my test.sh is like this :
Code:
#!/sbin/sh
rm -rf /system/app/YouTube
echo "Delete Youtube"
test.sh deletes Youtube folder but echo command doesn't work.
I use TWRP 3.2.3.0 recovery
Echo is a command for windows command line. In recovery you use: ui_print("<message goes here");
In recovery the language used is called Edify.
Read a bit about it here:
https://forum.xda-developers.com/wiki/Edify_script_language
joluke said:
Echo is a command for windows command line. In recovery you use: ui_print("<message goes here");
In recovery the language used is called Edify.
Read a bit about it here:
https://forum.xda-developers.com/wiki/Edify_script_language
Click to expand...
Click to collapse
you use ui_print in updater-script ?
but in sh file how to print on screen if echo doesn't work in recovery ?
kramer04 said:
you use ui_print in updater-script ?
but in sh file how to print on screen if echo doesn't work in recovery ?
Click to expand...
Click to collapse
Sh use the commands you use in linux
And yes ui_print is for updater-script
joluke said:
Sh use the commands you use in linux
And yes ui_print is for updater-script
Click to expand...
Click to collapse
Ok trying to use echo in sh file doesn't work for me.
So I don't understand how to do .
Any suggestions?
kramer04 said:
Ok trying to use echo in sh file doesn't work for me.
So I don't understand how to do .
Any suggestions?
Click to expand...
Click to collapse
Use Linux commands only. Echo is for Windows command line.
I don't have the skills to help you but googling "Linux commands for console" should help
joluke said:
Use Linux commands only. Echo is for Windows command line.
I don't have the skills to help you but googling "Linux commands for console" should help
Click to expand...
Click to collapse
So googling linus commands but I don't find how to use echo in a sh file in recovery.
If you have time try yourself echo command .
I've no idea why it doesn't work.
ECHO is a command for windows command line dude! Why do you insist on using echo? Echo is for windows command line? Got it now?
You need to use other commands according to the system you are using. and in android you use bash language on .sh files!
joluke said:
ECHO is a command for windows command line dude! Why do you insist on using echo? Echo is for windows command line? Got it now?
You need to use other commands according to the system you are using. and in android you use bash language on .sh files!
Click to expand...
Click to collapse
but i don't understand why it doesn't work
else i don't know how to replace echo by an other command
Thanks for help
kramer04 said:
but i don't understand why it doesn't work
else i don't know how to replace echo by an other command
Thanks for help
Click to expand...
Click to collapse
Every programming language uses its own commands...
Maybe because of that?
After some research
i change a little my script to see if command echo works
code in updater-script
Code:
ui_print("*************************");
ui_print("sh10");
ui_print("*************************");
unmount("/system");
unmount("/data");
#ui_print("-- Montage partitions...");
run_program("/sbin/busybox", "mount", "/system");
run_program("/sbin/busybox", "mount", "/data");
package_extract_dir("test", "/tmp");
set_perm(0, 0, 0777, "/tmp/test.sh");
run_program("/tmp/test.sh");
#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");
#delete_recursive("/tmp*");
ui_print("END OF PROCESS");
ui_print("*************************");
unmount("/data");
unmount("/system");
code in test.sh file
Code:
#!/sbin/sh
#echo on
#function to display commands
exe() { echo "\$ [email protected]" ; "[email protected]" ; }
OUTFD=$2
ui_print() {
if [ $OUTFD != "" ]; then
echo "ui_print ${1} " 1>&$OUTFD;
echo "ui_print " 1>&$OUTFD;
else
echo "${1}";
fi;
}
#rm -rf /system/app/YouTube
echo "hello world !, using echo" >tong.txt
exe echo "Delete YouTube, using exe echo"
echo "Delete YouTube, using echo" >>tong.txt
printf "hello world, using printf" >>tong.txt
cat tong.txt
ui_print "hello world! using ui_print"
echo command doesn't print on screen but it creates tong.txt and pass in results.
We can see it works in recovery.log
I:Set page: 'install'
I:Set page: 'flash_confirm'
I:Set page: 'flash_zip'
Iperation_start: 'Flashing'
Installing zip file '/external_sd/Custom Rom/test.zip'
Checking for Digest file...
Skipping Digest check: no Digest file found
I:Update binary zip
Verifying package compatibility...
Package doesn't contain compatibility.zip entry
I:Zip does not contain SELinux file_contexts file in its root.
I:has_legacy_properties: Found legacy property match!
I:Legacy property environment initialized.
*************************
sh10
*************************
unmount of /system failed; no such volume
about to run program [/sbin/busybox] with 3 args
about to run program [/sbin/busybox] with 3 args
minzip: Extracted file "/tmp/test.sh"
about to run program [/tmp/test.sh] with 1 args
$ echo Delete YouTube, using exe echo
Delete YouTube, using exe echo
hello world !, using echo
Delete YouTube, using echo
hello world, using printfsh: : unknown operand
hello world! using ui_print
END OF PROCESS
*************************
script result was [/system]
I:Updater process ended with RC=0
I:Legacy property environment disabled.
I:Install took 0 second(s).
Updating partition details...
I:mount -o bind '/data/media/0' '/sdcard' process ended with RC=0
Someone has an idea why echo doesn't print on screen in TWRP recovery; else it works...
weird for me
kramer04 said:
After some research
i change a little my script to see if command echo works
code in updater-script
Code:
ui_print("*************************");
ui_print("sh10");
ui_print("*************************");
unmount("/system");
unmount("/data");
#ui_print("-- Montage partitions...");
run_program("/sbin/busybox", "mount", "/system");
run_program("/sbin/busybox", "mount", "/data");
package_extract_dir("test", "/tmp");
set_perm(0, 0, 0777, "/tmp/test.sh");
run_program("/tmp/test.sh");
#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");
#delete_recursive("/tmp*");
ui_print("END OF PROCESS");
ui_print("*************************");
unmount("/data");
unmount("/system");
code in test.sh file
Code:
#!/sbin/sh
#echo on
#function to display commands
exe() { echo "\$ [email protected]" ; "[email protected]" ; }
OUTFD=$2
ui_print() {
if [ $OUTFD != "" ]; then
echo "ui_print ${1} " 1>&$OUTFD;
echo "ui_print " 1>&$OUTFD;
else
echo "${1}";
fi;
}
#rm -rf /system/app/YouTube
echo "hello world !, using echo" >tong.txt
exe echo "Delete YouTube, using exe echo"
echo "Delete YouTube, using echo" >>tong.txt
printf "hello world, using printf" >>tong.txt
cat tong.txt
ui_print "hello world! using ui_print"
echo command doesn't print on screen but it creates tong.txt and pass in results.
We can see it works in recovery.log
I:Set page: 'install'
I:Set page: 'flash_confirm'
I:Set page: 'flash_zip'
Iperation_start: 'Flashing'
Installing zip file '/external_sd/Custom Rom/test.zip'
Checking for Digest file...
Skipping Digest check: no Digest file found
I:Update binary zip
Verifying package compatibility...
Package doesn't contain compatibility.zip entry
I:Zip does not contain SELinux file_contexts file in its root.
I:has_legacy_properties: Found legacy property match!
I:Legacy property environment initialized.
*************************
sh10
*************************
unmount of /system failed; no such volume
about to run program [/sbin/busybox] with 3 args
about to run program [/sbin/busybox] with 3 args
minzip: Extracted file "/tmp/test.sh"
about to run program [/tmp/test.sh] with 1 args
$ echo Delete YouTube, using exe echo
Delete YouTube, using exe echo
hello world !, using echo
Delete YouTube, using echo
hello world, using printfsh: : unknown operand
hello world! using ui_print
END OF PROCESS
*************************
script result was [/system]
I:Updater process ended with RC=0
I:Legacy property environment disabled.
I:Install took 0 second(s).
Updating partition details...
I:mount -o bind '/data/media/0' '/sdcard' process ended with RC=0
Someone has an idea why echo doesn't print on screen in TWRP recovery; else it works...
weird for me
Click to expand...
Click to collapse
You are probably going to have to go in a little different direction. See this thread where update-binary is used in place of update-script.
Tulsadiver said:
You are probably going to have to go in a little different direction. See this thread where update-binary is used in place of update-script.
Click to expand...
Click to collapse
Thanks for your answer but could you add the link
kramer04 said:
Thanks for your answer but could you add the link
Click to expand...
Click to collapse
Sorry, lol!
https://forum.xda-developers.com/an...-complete-shell-script-flashable-zip-t2934449
Tulsadiver said:
Sorry, lol!
https://forum.xda-developers.com/an...-complete-shell-script-flashable-zip-t2934449
Click to expand...
Click to collapse
Thanks, but this isn't exactly what i'm looking for even if it's very interesting.
I would like to know how to display on recovery screen
I tryed with echo command but it doesn't work
For example running this script in sh file on recovery TWRP
Code:
#!/sbin/sh
csc_id=`cat /efs/imei/mps_code.dat`
echo "==== Your active csc is $csc_id ====="
echo do displays this
==== Your active csc is BTU ====
on recovery screen
but not displays anything.
Is there a way to activate it ?
kramer04 said:
Thanks, but this isn't exactly what i'm looking for even if it's very interesting.
I would like to know how to display on recovery screen
I tryed with echo command but it doesn't work
For example running this script in sh file on recovery TWRP
Code:
#!/sbin/sh
csc_id=`cat /efs/imei/mps_code.dat`
echo "==== Your active csc is $csc_id ====="
echo do displays this
==== Your active csc is BTU ====
on recovery screen
but not displays anything.
Is there a way to activate it ?
Click to expand...
Click to collapse
Echo has never worked on my phones. ui_print works on my pixel and pixel 2. It stopped working on my pixel 3 XL but that is because I haven't found a way to mount system using toybox. Pixel 3 XL won't mount using BusyBox.
Tulsadiver said:
Echo has never worked on my phones. ui_print works on my pixel and pixel 2. It stopped working on my pixel 3 XL but that is because I haven't found a way to mount system using toybox. Pixel 3 XL won't mount using BusyBox.
Click to expand...
Click to collapse
I know echo works because i see it in recovery log but it doesn't display anything on recovery screen
And i don't understand why;
Maybe it's because of recovery ?
I use TWRP
kramer04 said:
I know echo works because i see it in recovery log but it doesn't display anything on recovery screen
And i don't understand why;
Maybe it's because of recovery ?
I use TWRP
Click to expand...
Click to collapse
Most everyone uses TWRP. I believe for recovery screen, echo must be passed on to ui_print. Try this for an explanation:
https://forum.xda-developers.com/showthread.php?t=1023150&page=1
Tulsadiver said:
Most everyone uses TWRP. I believe for recovery screen, echo must be passed on to ui_print. Try this for an explanation:
https://forum.xda-developers.com/showthread.php?t=1023150&page=1
Click to expand...
Click to collapse
yes. totaly true
finaly i resolved my problem using code from Chainfire
Code:
#!/sbin/sh
OUTFD=1
readlink /proc/$$/fd/$OUTFD 2>/dev/null | grep /tmp >/dev/null
if [ "$?" -eq "0" ]; then
# rerouted to log file, we don't want our ui_print commands going there
OUTFD=0
# we are probably running in embedded mode, see if we can find the right fd
# we know the fd is a pipe and that the parent updater may have been started as
# 'update-binary 3 fd zipfile'
for FD in `ls /proc/$$/fd`; do
readlink /proc/$$/fd/$FD 2>/dev/null | grep pipe >/dev/null
if [ "$?" -eq "0" ]; then
ps | grep " 3 $FD " | grep -v grep >/dev/null
if [ "$?" -eq "0" ]; then
OUTFD=$FD
break
fi
fi
done
fi
ui_print() {
echo -n -e "ui_print $1\n" >> /proc/self/fd/$OUTFD
echo -n -e "ui_print\n" >> /proc/self/fd/$OUTFD
}
Thanks to all
https://forum.xda-developers.com/android/software-hacking/dev-complete-shell-script-flashable-zip-t2934449/page37
kramer04 said:
yes. totaly true
finaly i resolved my problem using code from Chainfire
Code:
#!/sbin/sh
OUTFD=1
readlink /proc/$$/fd/$OUTFD 2>/dev/null | grep /tmp >/dev/null
if [ "$?" -eq "0" ]; then
# rerouted to log file, we don't want our ui_print commands going there
OUTFD=0
# we are probably running in embedded mode, see if we can find the right fd
# we know the fd is a pipe and that the parent updater may have been started as
# 'update-binary 3 fd zipfile'
for FD in `ls /proc/$$/fd`; do
readlink /proc/$$/fd/$FD 2>/dev/null | grep pipe >/dev/null
if [ "$?" -eq "0" ]; then
ps | grep " 3 $FD " | grep -v grep >/dev/null
if [ "$?" -eq "0" ]; then
OUTFD=$FD
break
fi
fi
done
fi
ui_print() {
echo -n -e "ui_print $1\n" >> /proc/self/fd/$OUTFD
echo -n -e "ui_print\n" >> /proc/self/fd/$OUTFD
}
Thanks to all
https://forum.xda-developers.com/android/software-hacking/dev-complete-shell-script-flashable-zip-t2934449/page37
Click to expand...
Click to collapse
That works on my pixel and pixel 2 but not my pixel 3 XL. But on my pixel 3 XL I also have to use toybox to mount instead of BusyBox
run_program("/sbin/toybox", "mount", "/system");

Categories

Resources