yashsingh1/xdaforums huggingface dataset:
[Asus Transformer TF700] becomingx:
Wow! This is very messy, no wonder you're trying to automate the cleanup.

Love the analogy here :laugh:

Looks to be `/data/.layout_version' [ref].

If we're going full steam ahead with the requirement of Busybox being installed, then this is pretty easy:

VAR="$(find */0 | sed -e 's!/0!!g' | sort -u)"

Sed is our Stream EDitor. The option `-e' tells sed that what follows is a sed script.

The script itself (s!/0!!g) breaks down like this:

* `s' means we are doing a substitution.

* The exclamation point (!) is just a delimeter; any character can be used. Typically a forward slash (/) is used, but since directory paths have forward slashes in them, we go with something else to make it easier to read. Otherwise we'd have to escape the forward slashes and it would look like this: s/\/0//g

* `/0' is what we are looking to match.

* Another exclamation point (!) indicates we are done with our "search" pattern and next begins our "replace" pattern.

* Since we are just looking to just get rid of all occurences of `/0', our replacement pattern is literally nothing.

* Another exclamation point (!) to indicate the end of the replacement pattern.

* Finally, `g' (for global) tells sed to keep applying the substitution until it no longer matches. This means a path like `/dir/0/0/0' gets each `/0' stripped away one at a time until there are none left.

The last command sorts our listing so that the `-u' (for unique) option can be applied to it, which removes duplicate lines.

The easiest way to do this is just check for the presence of a `0' dir at each level. If one exists then there's another level of nesting below us and we ignore the current level:

VAR1=""
for i in $(find */0); do
if [ ! -d $i/0 ]; then
VAR1="$VAR1 $i"
fi
done
[Asus Transformer TF700] elfaure:
Wow! Thanks!! But now I'm suffering from cognitive dissonance (dis-sed-ance). I knew it would require either find, grep, awk, or sed but using those commands without having any grip on regex is nearly impossible. Can you point me to a good resource for learning Android regex or is any GNU/Linux resource valid? Is this a good one?

http://www.linux.org/article/view/introduction-to-regular-expressions-within-a-shell
[Asus Transformer TF700] _that:
So does that mean you don't have any "0" directories in your /sdcard right now, and you are doing all this just for fun?

At least, after reading your additional material, I am now beginning to understand the problem. :)

However I don't understand how you get any useful output from "find */0" - I get either "No such file or directory", or a listing of thousands of files, depending on where I start this.

The nice thing with regular expressions is that the basics are the same everywhere.

But I don't know if you even need such powerful tools... Correct me if I am wrong, but your script should convert this structure:

/data/media/0

/data/media/0/stuff1

/data/media/0/0

/data/media/0/0/stuff2

/data/media/0/0/0

/data/media/0/0/0/stuff3

to

/data/media/0

/data/media/0/stuff1

/data/media/0/stuff2

/data/media/0/stuff3

?

So you'd basically need to run this inside /data/media/0:

1. If there is no subdirectory named "0", there is nothing to do, and we can exit

2. If there is a subdirectory named "0", move everything from inside one level out

2a. how do you want to handle conflicts, if the file or directory you want to move outside already exists in the parent directory?

3. go to step 1
[Asus Transformer TF700] elfaure:
[Reply to _that's last post. Getting lazy, I'm at lunch...]

Here is my output from

find */0

u0_a87@android:/ $ su

root@android:/ # find */0

data/0

sdcard/0

sdcard/0/0

root@android:/ # exit

u0_a87@android:/ $ find */0

data/0

find: data/0: Permission denied

sdcard/0

sdcard/0/0

1|u0_a87@android:/ $

I'm not sure about the structure I am looking for until I get some output from this code run on a 4.2 device with nested /0's so I can see all of them and their variations. I also want to see what happens to subsequent user directories nested starting with /data/media/10 (second user) and /data/media/11 (third user) and how they nest in comparison.

The only /0 directories that I have on my device were created by me to test this script. I am still on 4.1 and this is a 4.2 only issue so as you state its "just for fun" or rather "for the fun of learning" but at least its not a "hello world" script that does nothing useful. I'm hoping to automate someone's cleanup after installing 4.2 with this, maybe my own at some point, if required.

Here's some more info about the issue:

http://teamw.in/DataMedia

ps-I just discovered the equivalent to the stock browser "about:debug" for Chrome is "about:flags" which brings up an extensive list of experimental settings. I enabled all that were GPU and speed related and its a marked improvement (it feels 25-75% faster). With a 100MB Chrome cache I can have about 20 tabs open at the same time now and its still fast and snappy.
[Asus Transformer TF700] elfaure:
Not sure if this will work or not, but if you want to try to retain single user mode in 4.2 you can try this:

http://androidforums.com/verizon-ga...y-bean-roms-edited-3-24-13-a.html#post5806236

If anyone has a copy of the .layout_version file, please post it or a link to it so I can check it out.

Thks
[Asus Transformer TF700] elfaure:
Thanks again for your help and explanations. I find it amazing what a few (not so) simple lines of code can do with a complex task. Learning regex will take me until next year so for now I will go blindly forward with my plan. The next step would be to use BOTH of these variables in some call statement like [ ] to automate the process of backing up and moving data around. And combining it all into a script here it is below. Is the syntax in the main block I added correct?

#!/system/bin/sh

VAR="$(find */0 | sed -e 's!/0!!g' | sort -u)"

VAR1=""
for i in $(find */0); do
if [ ! -d $i/0 ]; then
VAR1="$VAR1 $i"
fi
done

for OBJ in $VAR and OBJ1 in $VAR1; do
#Backup $OBJ to SD
mkdir /Removable/MicroSD/$OBJ_BAK
cp -r /$OBJ /Removable/MicroSD/$OBJ_BAK
#Over write $OBJ with $OBJ1
cp -rf /$OBJ1 /$OBJ
#Merge backup and $OBJ
cp /Removable/MicroSD/$OBJ_BAK/*.* /$OBJ
#Remove $OBJ backup
rm -rf /Removable/MicroSD/$OBJ_BAK
done
[Asus Transformer TF700] becomingx:
lolz. Any resource on regexes should be applicable, just know that there are some small differences between the three main dialects (basic, extended, and perl). If you've got money to spend, Mastering Regular Expressions is considered *the* book to own on the subject. Also good is this pocket reference for sed and awk, which is a bit cheaper. I've used my copy so much the spine has completely gone out and it's just a collection of loose pages inside the cover now!

---------- Post added at 11:29 AM ---------- Previous post was at 11:00 AM ----------

This is what I was hinting at back in post #3.

Using `find' like this, the `*/0' will get expanded by the shell if there happens to exist at least one `SOMEDIR/0', which will result in `find' printing out every file/directory/etc. that exists under any and every `SOMEDIR/0'. Otherwise, if none exist, it will get passed to the `find' command as literally `*/0', which is where the "No such file or directory" comes from.

The proper way to do this is using a `find' option like `-name', to limit scope of what gets returned. Again, though, one still has to be careful because we could still get search matches that we don't want. Something like this might be a good starting point:

find -name '0' -type d

[MENTION=4197304]elfaure[/MENTION]: Try populating your self-created `0' directories with some files and directories, the output of `find */0' should become a bit surprising. ;)

Seems simple enough, but need a little time to think about it...

---------- Post added at 11:31 AM ---------- Previous post was at 11:29 AM ----------

Mine just contains the number "2", nothing else, not even a newline.

---------- Post added at 11:43 AM ---------- Previous post was at 11:31 AM ----------

Negatory, good buddy. Everthing after the `in' keyword till the semicolon gets treated as part of the (one and only) list. This would be a good place for two parallel arrays, but I suspect that might be overkill. Need a little time to think...

P.S. Never go blindly forward when working as user `root'. Much too dangerous. :cowboy:
[Asus Transformer TF700] elfaure:
Thanks for the tips! I will play with the script and see what happens with "find" and possibly changing the code and how it works. Regarding reference/resource material, I never pay for anything I can get for free. Found all the books you could ever want including the full ver for sed and awk but unfortunately no pocket guide listed there. See links below. It must feel omnipotent to know that armed with a terminal and a keyboard you could halt world trade.

Questions:

1. Will there be a 1:1 correspondence between the root names in VAR and VAR1 (or ARY and ARY1)?

2. How can I verify (MD5?, bitwise comparison to source?) the backup of /data/media before I copy from it or delete it

3. Check this link out on parallel lists. It may have our solution and not require using parallel arrays.

http://stackoverflow.com/questions/546817/iterating-over-two-lists-in-parallel-in-bin-sh

*************************************************************************************************************************************************************************

TOTALLY Free O'Reilly IT e-books (nearly all you could ever want, links 3,4. 70 pgs @ 5 books/pg=350 books worth! Free PDF's you can download/carry on device):

*The* book to have:

http://it-ebooks.info/book/341/

Sed & Awk, 2nd Ed. (no pocket guide available :crying:)

http://it-ebooks.info/book/218/

O'Reilly Start:

http://it-ebooks.info/publisher/3/page/1

O'Reilly End:

http://it-ebooks.info/publisher/3/page/70
[Asus Transformer TF700] elfaure:
[MENTION=2446267]becomingx[/MENTION]:

I tested your code out on my sample directory set and it works PERFECTLY as expected. You throw down some mean sed. Thanks a ton. :good:

But this substitution does not produce what I want. The output is in the form "./dir/0" and would need to be in the form "/dir/0" to use it as a variable. And I discovered something very strange with this code. If you run it as normal user the output is garbage, but if you run it as su the output is nearly what I am looking for. Why is that??? :confused:

find -name '0' -type d

But these directories are empty now, so when find */0 gets expanded there is nothing to expand. I will put some files and directories in these directories now and play with it till I get what I need, or more than likely post back when I need some more help to get there. But your code does exactly what it was designed to do. Its the find call that needs to be targeted correctly so the result is like it is now, being there is nothing to expand so I get exactly what I'm looking for (with a 1:1 correspondence between root directory names between 2 lists or 2 parallel arrays) and nothing more.

Re: .layout_version file What are the permissions? (octal reply OK) Also, thanks for the [Ref] link. Now that's definitely a link "right from the source".

If I made you think then I am making progress. :cool:

"Blindly forward" in the sense that I cannot understand some (sed, regex) of the code you supplied but not blind in the sense that you and _that are my guides and I couldn't ask for a better guides. Although the deft blind man at the intersection cannot hear or see the oncoming traffic hazard, with a good guide dog he functions as if he has both eyes and ears. :cowboy:

Initially I wish I could have communicated my intent better to both you and _that. From the beginning of this concept, I knew where I wanted to go and had no clear vision how I would get there, but I did have a pretty clear vision of where to start in terms of needing two parallel lists, and that implied using arrays. Its unfortunate that two value separated lists (effectively two arrays) cannot duplicate the function of two parallel arrays which is very limiting and makes an array much more flexible in my opinion.
[Asus Transformer TF700] elfaure:
[MENTION=2446267]becomingx[/MENTION]

Did you see these links?
[Asus Transformer TF700] becomingx:
Cool! (Sorry for the delayed reply, playing catch-up here.)

Try:

find /{data,sdcard} -name '0' -type d

Most likely because non-privileged users can't directly access much of the filesystem due to file and directory permissions.

I just noticed that your code back in post #19 has statements with paths like:

/Removable/MicroSD/$OBJ_BAK

An underscore (_) is a legal character in a variable name, so that won't work since $OBJ_BAK isn't defined to anything. To protect the variable name, enclose it in braces ({}) à la:

/Removable/MicroSD/${OBJ}_BAK

root@android:/ # ls -l /data/.layout_version
-rw------- root root 2 2013-04-07 07:25 .layout_version

Oh, and I was wrong about the contents of the file. It actually contains the number `2' followed by a NULL byte:

root@android:/ # hexdump -vC /data/.layout_version
00000000 32 00 |2.|
00000002

If arrays are what you need they certainly can be had, just need to write a little more code. :) Give this a try (untested):

ARRAY1=($(find /{data,sdcard} -name '0' -type d | sed -e 's!/0!!g' | sort -u)
ARRAY2=($(for i in $(find /{data,sdcard} -name '0' -type d); do if [ ! -d $i/0 ]; then echo $i; fi; done))

for (( i = 0; i < ${#ARRAY1[*]}; i++ )); do
echo ${ARRAY1[$i]}
echo ${ARRAY2[$i]}
done

Yeah, I'd be careful posting these around though. I'm not sure how this site can be legal (at least in the US). O'Reilly is open-source friendly, but I don't think their books are as permissively licensed. ;)
[Asus Transformer TF700] elfaure:
[MENTION=2446267]becomingx[/MENTION]: Thanks again code buddy. If there is a problem with those O'Reilly links I had no idea - blame Google. It just popped up as my consumer search result and I collect many free e-books. How's one to know what's legit and what's not? Linked in pushes me free e-books all the time from ourmumbaicity - now that sounds illegit! but it must be legal because they host a group for it (100% Free Engineering e-books). Thanks for the advice anyhow.
[Asus Transformer TF700] elfaure:
Quote: I just noticed that your code back in post #19 has statements with paths like:

Code:

/Removable/MicroSD/$OBJ_BAK

An underscore (_) is a legal character in a variable name, so that won't work since $OBJ_BAK isn't defined to anything. To protect the variable name, enclose it in braces ({}) à la:

Code:

/Removable/MicroSD/${OBJ}_BAK

************************************************************************

Equivalently you can do this:

Code:

/Removable/MicroSD/"$OBJ"_BAK
[Asus Transformer TF700] elfaure:
Lets go back to this simple example code

NEST=$(find */0)
for OBJ in $NEST; do
echo "$OBJ"
done

NEST is a variable containing a value separated list, right? The list gets expanded by the find command.

Why doesn't this work?

NEST=(OBJ1 OBJ2)
for OBJ in $NEST; do
echo "$OBJ"
done

But it only echo's OBJ1 not both.

Why? NEST is a variable containing a value separated list, right? Or if its a user-defined list not a command expanded list, does it need to then be an array? Why can't people have the same rights as commands?

****************************************************************************************************************************************************************

Quote:

VAR="$(find */0 | sed -e 's!/0!!g' | sort -u)"

Sed is our Stream EDitor. The option `-e' tells sed that what follows is a sed script.

The script itself (s!/0!!g) breaks down like this:

* `s' means we are doing a substitution.

* The exclamation point (!) is just a delimeter; any character can be used. Typically a forward slash (/) is used, but since directory paths have forward slashes in them, we go with something else to make it easier to read. Otherwise we'd have to escape the forward slashes and it would look like this: s/\/0//g

...[snipped]

Question: Why only the first delimiter was escaped above and not the two !! before g? Why isn't it s/\/0/\/\g?
[Asus Transformer TF700] becomingx:
Ah, OK. I didn't see $OBJ_BAK get defined to anything in the code you posted so I thought you were trying to do something else.

Not declared like that -- the parentheses declare it as an array. If you want a list, just use quotes instead.

Reading that statement makes me chuckle a little. It reminds me of when people talk about corporations having the same rights as people, usually as it regards to campaign contributions.

It'd actually be nice if people had the same rights as commands. The bootloader on my device can issue commands to get access to its secure boot key, why I can't get access to it? WTF?!? (OK, mini-rant over :))

:confused: You're referencing two different declarations.

In the first one (s!/0!!g), there is no escaping needed because our delimiter doesn't appear in either the search or replacement patterns.

In the second one (s/\/0//g), the search pattern (/0) contains a forward slash (which is our delimiter), so we must escape it by prefacing it with a backslash (\) so that sed doesn't interpret it as a delimiter.
[Asus Transformer TF700] elfaure:
Thanks for the reply. I think if you got an tattoo that reads "Asus RSA key 10.6.1.14.4" then you would be digitally signed and then could gain access to those commands just like the bootloader!

WRT Sed, I thought for each ! replaced with / needed to be escaped. Now I see its only the ones in the search or replacement patterns.

So for a user variable value separated list, its done like this?

LIST1="OBJ1 OBJ2 OBJ3"

If you might be so kind as to review my failing attempt at "cleaning up" the Multi-Browser2RAM script I would certainly appreciate it.

http://xdaforums.com/showthread.php?p=41899394#post41899394
[Asus Transformer TF700] becomingx:
lmfao ASUS definitely needs to offer a service where I can submit myself as a trusted entity to be signed by their RSA key!

Yup.

Sure will!
[Asus Transformer TF700] elfaure:
Disregard this request. You and [MENTION=4878287]_that[/MENTION] are soooo awesome that I now have the skills to figure it out by myself. Just took me a little while. "Triumph".
[Asus Transformer TF700] elfaure:
[MENTION=2446267]becomingx[/MENTION]

I have not been able to make an init.d script run at boot on stock ROM. I followed _that's guide, installed the appropriate install-recovery.sh script with the busybox run-parts line, it runs as root at boot, changed the init.d script name to prepend two digits before the name, natha. Any suggestions? You are locked on stock ROM and got this to work right? How??
[Asus Transformer TF700] becomingx:
You made sure that the `/system/etc/init.d/XXfile' is executable, right?

Here's my install-recovery.sh if it helps for comparision:

#!/system/bin/sh

if [ -d /system/etc/init.d ]; then
if [ -x /system/xbin/busybox ]; then
/system/xbin/busybox run-parts /system/etc/init.d
fi
fi
[Asus Transformer TF700] elfaure:
Absolutely. And my install-recovery.sh just has the line "/system/xbin/busybox run-parts /system/etc/init.d" But one thing I just noticed, not sure if its an issue or not, is my init.d permissions is drwx------ but my etc permissions is drwxr-xr-x. Is there any problem with this? Does this mean that even if a file is executable for all in init.d, it will only execute for the root user because of the directory permissions?
[Asus Transformer TF700] becomingx:
Clarification: *only* this line? i.e. no `#!/system/bin/sh' at the top?

Shouldn't be a problem. My init.d is chmod 0700 as well.

Yup.
[Asus Transformer TF700] elfaure:
Sorry, I need to remember to be explicit and exact in my communications. Its got the hash-bang line at the top too as every script needs. Are you on 4.2? That would be the only difference between our devices that I can see.
[Asus Transformer TF700] becomingx:
I am on 4.2, but there's no reason I can possibly think of as to why that would matter.

Do you know for sure that `install-recovery.sh' is getting executed at boot-time?
[Asus Transformer TF700] elfaure:
Yes it is. That part is working fine. As a matter of fact, I have already taken full advantage of that and copied my script into etc and renamed it install-recovery.sh and it runs at boot no problem (for a single script). I'm just trying now to get the same thing to happen in init.d (for multiple scripts) with the script's original name and the "run-parts" install-recovery.sh

[Edit] I even tried prepending two digits to the script name - no difference. Just doesn't fly for some reason.
[Asus Transformer TF700] becomingx:
Try running the `run-parts' command from the command-line and see what happens.
[Asus Transformer TF700] elfaure:
What would be the indication that it did something? How to test that?? I can't just reboot.
[Asus Transformer TF700] becomingx:
Manually unmount any browser mounts, run the `run-parts', see if any browser mounts get created.
[Asus Transformer TF700] becomingx:
So busybox is dropping the ball? For fun, try executing with the `-l' (ell) option.
[Asus Transformer TF700] elfaure:
Well that was interesting. The last diagnostic, after installing superSU, put me into a boot-loop I just recovered from! Back to superuser X now. The new superSU detects other supersu's and wants to uninstall them. I tell it no. This is its reply. I'll have to try it later. Gotta go bring in the bacon.
[Asus Transformer TF700] elfaure:
"/system/xbin/busybox run-parts -l /system/etc/init.d" made no difference.
[Asus Transformer TF700] becomingx:
:sigh: It looks like the busybox run-parts implementation thinks that any filename with a dot in it is not a valid filename. I'm guessing your script has an extension?

For reference, valid filename characters are: alphanumeric, underscores, and hyphens. No idea why this is, but having to spend half an hour parsing the code to figure it out just adds to the stupidity of it all.
[Asus Transformer TF700] elfaure:
Problem solved!! Hey man, I can't thank you enough. Been fighting with this far too long and I've dotted all my i's and crossed all my t's. Guess I shouldn't have dotted my script. Sorry you had to parse the source to figure it out but I'm sure it'll come up again for someone else. Great job. The excellence at XDA never ceases to impress me. :good:

[Edit] I am kicking myself in the head a bit. I had the clue but failed to realize it. Steve Niemitz original script I found on Github also uses no extension. I thought it was bad practice as a beginner to not use the .sh extension for scripts so I added it on my own.

[Edit] Having a two digit prefix is not a requirement.
[Asus Transformer TF700] becomingx:
lol at dotting your script. No prob though. I'm surprised it's even an issue, what's wrong with dots in a filename? I'll probably wind up querying the developers as to why it isn't allowed.

Historically it may have been good practice to use an extension, but I think it probably only matters for the purpose of editing, or if the person executing the script needs to know exactly what kind of a executable it is (i.e. compiled, shell script, perl script, etc.) rather than just being a "program" that can be run. :shrug: (I'm pretty inconsistent with using extensions on scripts myself.)

The number prefix is used just for ordering. If you need one script to run before another, you can give the first a lower number than the second.
[Galaxy S 5 Q&A, Help & Troubleshooting] awesomedeals88:
Now that the Galaxy S4 is out, lets speculate on the Galaxy S5?
[Galaxy S 5 Q&A, Help & Troubleshooting] Galactus:
No lag
[Galaxy S 5 Q&A, Help & Troubleshooting] ChronoReverse:
Make breakfast for me.

A non-laggy Touchwiz with updated UI (read: not looking like Gingerbread) would be nice too.
[Galaxy S 5 Q&A, Help & Troubleshooting] ap3604:
A built in taser that automatically shocks the user anytime they start a thread already speculating about next years version ;)