[DOS Util][Symlink code generator script] - Galaxy S II Android Development

DOS Script for creating SYMLINK code for updater-script
After searching and searching I found an usefull script for auto symlink text generation. One can use it with kitchen....
I modified it and put together in a single batch file.
It grabs APK list in directory you want (lets say C:\cygwin\home\user\kitchen\WORKING_030413_160037\preload\symlink\system\app)
and creates code and saves it to symlinks.txt
You can just copy-paste it in updater-script:
(rename sym_create.txt into sym_create.cmd)
Syntax is simple:
sym_create.cmd path_of_the_kitchen_working_directory_with_app_list
you get....
symlink("/preload/symlink/system/app/aplication_name.apk","/system/app/aplication_name.apk")
in symlinks.txt
Script:
Code:
@echo Listing APKs]
@echo .
@echo Choosen path = %1
for /r %1 %%g in (*.apk) do echo %%~nxg >> list.txt
@echo .
@echo [Preparing links]
echo .
for /f "tokens=*" %%A in (list.txt) do (echo.symlink("/preload/symlink/system/app/%%~nA.apk","/system/app/%%~nA.apk"^); >> symlinks.txt
)
I hope it saves you some time!

Sweet!
klemenSLO said:
DOS Script for creating SYMLINK code for updater-script
After searching and searching I found an usefull script for auto symlink text generation. One can use it with kitchen....
I modified it and put together in a single batch file.
It grabs APK list in directory you want (lets say C:\cygwin\home\user\kitchen\WORKING_030413_160037\preload\symlink\system\app)
and creates code and saves it to symlinks.txt
You can just copy-paste it in updater-script:
(rename sym_create.txt into sym_create.cmd)
Syntax is simple:
sym_create.cmd path_of_the_kitchen_working_directory_with_app_list
you get....
symlink("/preload/symlink/system/app/aplication_name.apk","/system/app/aplication_name.apk")
in symlinks.txt
Script:
Code:
@echo Listing APKs]
@echo .
@echo Choosen path = %1
for /r %1 %%g in (*.apk) do echo %%~nxg >> list.txt
@echo .
@echo [Preparing links]
echo .
for /f "tokens=*" %%A in (list.txt) do (echo.symlink("/preload/symlink/system/app/%%~nA.apk","/system/app/%%~nA.apk"^); >> symlinks.txt
)
I hope it saves you some time!
Click to expand...
Click to collapse
THANKS!!!!
Doing that by hand was REALLY getting old!!!
Mega Thanks

Related

[Q] Building script help

Hi guys...
I'm a translator for MIUI, so i edit apks a lot.
To make things easier, i made this small tool, to help me automate things.. Something like Android Utility and APK Multitool..
But, i'm no programmer, i just got a lot of help from various places, ending up with this tool.
It's far from perfect, needs a lot of improvement and here's where xda comes in
The script is running more or less fine as it is, but it has some (serious?) issues i can't figure out how to fix..
It's a little tricky to explain, but here goes..
First, i press c to clean everything, the operation completes fine.
I press e. to extract apks from a rom zip, operation completes.
Then i install frameworks, operation completes..
BUT, if i now press 2 to decompile all, i get an error:
Code:
/home/dan/buildtool/functions.sh: line 44: no match: *jar
Invalid choice
#?
Thing is, if i quit the tool and restarts it, press2, then it runs fine... ( the *.jar error is expected, it's the "invalid choice" which is interesting..)
So, it has to be something in the menu function, in a loop somewhere, i don't know..
I was hoping someone could run through the script and perhaps catch the error.. I'm really hoping for a simple answer
Other than that, i could use some good inputs about how to improve the script, add functionality and develop it in general...
The script is on github:
https://github.com/1982Strand/buildtool
I don't think you have a looping problem.
Code:
[COLOR=Gray]1067[/COLOR] [[ -z $zip ]] && echo "Invalid choice" && continue
Looks like you explicitly want it to echo "Invalid choice"
I think the problem lies in line #53
Code:
for file in *.apk *jar; do
...you will receive an error if *jar doesn't exist.
You may want to split it up with an if/then...for, for both *.apk and *jar like so:
Code:
if [ -f *.apk ]; then
for file in *.apk; do
...
done
fi
if [ -f *jar ]; then
for file in *jar; do
...
done
fi
[Edit:] Also, you should be aware of this if you aren't already....You can debug your bash scripts with the -vx switch in your shabang statement like so:
Code:
#!/bin/bash -vx
okay, i tried changing line #53 as you said, but now i get another error:
Code:
/home/dan/buildtool/functions.sh: line 53: [: too many arguments
/home/dan/buildtool/functions.sh: line 64: no match: *jar
Invalid choice
#?
And with the -vx set in the shebang:
Code:
/home/dan/buildtool/functions.sh: line 53: [: too many arguments
/home/dan/buildtool/functions.sh: line 64: no match: *.jar
++ [[ -z '' ]]
++ echo 'Invalid choice'
Invalid choice
++ continue
#?
Before i changed the code, it was normal that i threw the error with the *.jars not found, but it's supposed to continue anyway..
As i said, if i quit the tool when the error came up, start the tool again and press 2, it works. (it still gives me the error with the *.jar not found, but that was normal)
I don't understand why it takes me back to the prompt as if i were about to extract the apks??
It seems to me it's because i'm still "in" the "e. extract apks from zip" - function...?? I must admit,i don't fully understand the code in that function, so i'm having a hard time troubleshooting it..
1982Strand said:
okay, i tried changing line #53 as you said, but now i get another error:
Code:
/home/dan/buildtool/functions.sh: line 53: [: too many arguments
/home/dan/buildtool/functions.sh: line 64: no match: *jar
Invalid choice
#?
And with the -vx set in the shebang:
Code:
/home/dan/buildtool/functions.sh: line 53: [: too many arguments
/home/dan/buildtool/functions.sh: line 64: no match: *.jar
++ [[ -z '' ]]
++ echo 'Invalid choice'
Invalid choice
++ continue
#?
Before i changed the code, it was normal that i threw the error with the *.jars not found, but it's supposed to continue anyway..
As i said, if i quit the tool when the error came up, start the tool again and press 2, it works. (it still gives me the error with the *.jar not found, but that was normal)
I don't understand why it takes me back to the prompt as if i were about to extract the apks??
It seems to me it's because i'm still "in" the "e. extract apks from zip" - function...?? I must admit,i don't fully understand the code in that function, so i'm having a hard time troubleshooting it..
Click to expand...
Click to collapse
Sorry, I forgot using an 'if' statement in that way would produce the "too many arguments" error. This is from '*.apk' having more than one match, so this is what I came up with:
Code:
cd $IN
if [ "$(ls -1 | grep '.\+\.apk$' | wc -l)" -gt 0 ]; then #if there are more than 0 results of *.apk...
for file in *.apk ; do
echo "Decompiling $file" 2>&1 | tee -a $LOG/decompile_log.txt
apktool -q d -f $file $DEC/$file
done
cp -f $HJEM/sort.py $DEC
cd $DEC
python sort.py
rm -r sort.py
fi
if [ "$(ls -1 | grep '.\+\jar$' | wc -l)" -gt 0 ]; then #if there are more than 0 results of *jar...
for file in *jar; do
echo "Decompiling $file" 2>&1 | tee -a $LOG/decompile_log.txt
apktool -q d -f $file $DEC/$file
done
fi
After running options 'e' & 'c', then running option 2, there is no error and the script runs as it should (That is, assuming you chose option 2 of 'c' - "Clean all but apks in apk_in folder". Chosing option 1 of 'c' will obviously result in an error because no .apk or jar files will exist to decompile).
The reason you keep getting the "Invalid choice" error is because you're explicitly asking for it.
With the line #1067 mention earlier and others similar to it like the example below:
Code:
[COLOR=Gray]914[/COLOR] [[ -z $file ]] && echo "Invalid choice" && continue
When the variable string for '$file' has a zero length, as would be the case if '*jar' doesn't exist, the script will echo "Invalid choice". My example above ensures that the '$file' variable string will not have a zero length.
My suggestion would be to change "Invalid choice" to something more specific to the function for which it is being used, that way you can get a better idea of the source of your error.
As far as why you would get that error only after choosing options 'e' & 'c' and not after restarting the script, I couldn't say for sure without digging into it a little more, but at least this fixes your original problem.
I hope that helps.
Wow! That did the trick for option 2!!
But then it returns when i continue and get to option 4 "Fix sources":
Code:
[--- Fix MIUI sources ---]
...Fixing framework-miui-res.apk
patching file /home/dan/buildtool/apk_in/decompiled/framework-miui-res.apk/apktool.yml
/home/dan/buildtool/functions.sh: line 132: no match: *.rej
Invalid choice
#?
The point here is, that sometimes the patching fails and patch will generate some files (*.rej and *.orig) that needs to be deleted. But often, like most of the time really, the patching succeeds, so these files are not generated and my simple "remove" commands fail, obviously..
So, i'm guessing here that i get this zero-length issue and my script returns me to this code...
Well, this brings us back to
Code:
[[ -z $file ]] && echo "Invalid choice" && continue
From the "e" option..
This seems to be it.. I'm not entirely sure about what the code exactly means, except the "invalid choice" and continue..
The point with the option "e. Extract apks from zip", is that the user gets a list of zip files contained in the source_rom folder, then choose one.
Then a set of apks (defined in translation_list.txt) must be extracted to apk_in.
The function should simply give the options to choose a zip, x to return to the main menu, or write "invalid choice" if wrong key is entered...
But something seems broken in code, i just can't figure out what and where...
Btw, the code itself is from stackoverflow.com, so i didn't write it myself like that, i just used it for my script as it seemed to do what i needed, but i guess it needs some adjustment still
Okay, in the previous example, you had a 'for' loop that was written like this...
Code:
for file in *.apk *jar; do
this
and that
done
...which is saying, For every file (one at a time) in the current directory that matches the patterns *.apk and *jar, assign that filename to the variable '$file', then do..."this and that" while plugging in the value of '$file' for that particular iteration of the loop to the set of commands represented by "this and that". If for some reason, say, no files match the pattern *jar, then for each iteration of the loop regarding that pattern, $file will be equal to ' ' instead of something like 'filename.jar'. That is a variable string length of 0.
Code:
[[ -z $file ]] && echo "Invalid choice" && continue
...what that is, is a test to see if the string (or in this case filename) represented by '$file' has a zero length as with the example above where there were no jar files to assign to the variable '$file'. Similarly, it would most likely be the case with option 4 when there is no match for '*.rej' & '*.orig'.
In my example:
Code:
if [ "$(ls -1 | grep '.\+\.apk$' | wc -l)" -gt 0 ]; then
...I'm testing to see if the output of the command 'ls -1 | grep '.\+\.apk$' | wc -l' is greater than 0, before continuing with the 'for' loop.
The 'ls -1'command lists the contents of the current directory to one column, instead of the typical two or more. The 'wc -l' counts the number of lines in the resulting output. And grep '.\+\.apk$' is a regular expression that makes sure the resulting output only contains filenames that end in '.apk'. So if there are files that end in .apk, then the output of the command 'ls -1 | grep '.\+\.apk$' | wc -l' would be greater than 0, and the same would hold true for jar files. I'm sure there's a more elegant way of doing it, but it works.
Side note: Regular Expressions are powerful pattern matching tools that you definitely need to learn if you want to get the most our of your shell scripts. Google "regexp" or "Bash regexp" to learn more. It can be very confusing to understand at first, but once you get the hang of it, it is really pretty easy.
Anyway, getting back on track...
After running option 2 to decompile, then running option 4 to fix MIUI sources, everything runs fine...even with, or without '*.rej' & '*.orig'. I'll use the following debug as an example:
Code:
+ echo '...Fixing framework-miui-res.apk'
...Fixing framework-miui-res.apk
+ echo ''
+ patch -i /home/soup/buildtool/src_fix/framework-miui-res/apktool.diff /home/soup/buildtool/apk_in/decompiled/framework-miui-res.apk/apktool.yml
patching file /home/soup/buildtool/apk_in/decompiled/framework-miui-res.apk/apktool.yml
+ cd /home/soup/buildtool/apk_in/decompiled/framework-miui-res.apk/
[COLOR=Red]# notice there are no files that match '*.rej' or '*.orig' [/COLOR]
+ rm -f -r '*.rej'
+ rm -f -r '*.orig'
[COLOR=Red]# and there are no errors as a result of it[/COLOR]
+ echo ''
+ echo '...Fixing MiuiCompass.apk'
...Fixing MiuiCompass.apk
+ echo ''
+ patch -i /home/soup/buildtool/src_fix/MiuiCompass/apktool.diff /home/soup/buildtool/apk_in/decompiled/MiuiCompass.apk/apktool.yml
patching file /home/soup/buildtool/apk_in/decompiled/MiuiCompass.apk/apktool.yml
Hunk #1 FAILED at 4.
1 out of 1 hunk FAILED -- saving rejects to file /home/soup/buildtool/apk_in/decompiled/MiuiCompass.apk/apktool.yml.rej
[COLOR=Red]# here, there is now a match available for 'apktool.yml.rej' but not 'apktool.yml.orig'[/COLOR]
+ cd /home/soup/buildtool/apk_in/decompiled/MiuiCompass.apk/
+ rm -f -r apktool.yml.rej
+ rm -f -r apktool.yml.orig
[COLOR=Red]# still no error[/COLOR]
+ echo ''
...so I wouldn't know what to tell you without being able to recreate it on my end.
It may be helpful to give your variables $file and $zip in those functions a non-zero value after they are run to make sure there isn't any zero length hangover from a previous option, like so...
Code:
pull () {
shopt -s failglob
echo "[--- Choose rom zip to extract from, or x to exit ---]"
echo ""
echo ""
select zip in $SRC/*.zip
do
[[ $REPLY == x ]] && . $HJEM/build
[[ -z $zip ]] && echo "Invalid choice" && continue
echo
for apk in $(<$HJEM/translation_list.txt); do
unzip -j -o -q $zip system/app/$apk -d $IN 2&>1 > /dev/null;
done
unzip -j -o -q $zip system/framework/framework-res.apk -d $IN 2&>1 > /dev/null;
unzip -j -o -q $zip system/framework/framework-miui-res.apk -d $IN 2&>1 > /dev/null;
done
zip=dummy [COLOR=Red]<-- after the script is run, assign the string 'dummy' to $zip[/COLOR]
}
soupmagnet said:
In my example:
Code:
if [ "$(ls -1 | grep '.\+\.apk$' | wc -l)" -gt 0 ]; then
...I'm testing to see if the output of the command 'ls -1 | grep '.\+\.apk$' | wc -l' is greater than 0, before continuing with the 'for' loop.
The 'ls -1'command lists the contents of the current directory to one column, instead of the typical two or more. The 'wc -l' counts the number of lines in the resulting output. And grep '.\+\.apk$' is a regular expression that makes sure the resulting output only contains filenames that end in '.apk'. So if there are files that end in .apk, then the output of the command 'ls -1 | grep '.\+\.apk$' | wc -l' would be greater than 0, and the same would hold true for jar files. I'm sure there's a more elegant way of doing it, but it works.
Side note: Regular Expressions are powerful pattern matching tools that you definitely need to learn if you want to get the most our of your shell scripts. Google "regexp" or "Bash regexp" to learn more. It can be very confusing to understand at first, but once you get the hang of it, it is really pretty easy.
Click to expand...
Click to collapse
Really good stuff! Learning a lot from this, thanks! I'll dig into regular expressions right away
Anyways, i think i got around the missing *.rej and *.orig by approaching the operation with SED instead of PATCH..
First of all, it makes my code shorter and i don't need an external .diff file for the operation to succeed. (Given that i write the SED code correctly of course..)
It may be helpful to give your variables $file and $zip in those functions a non-zero value after they are run to make sure there isn't any zero length hangover from a previous option, like so...
Code:
pull () {
shopt -s failglob
echo "[--- Choose rom zip to extract from, or x to exit ---]"
echo ""
echo ""
select zip in $SRC/*.zip
do
[[ $REPLY == x ]] && . $HJEM/build
[[ -z $zip ]] && echo "Invalid choice" && continue
echo
for apk in $(<$HJEM/translation_list.txt); do
unzip -j -o -q $zip system/app/$apk -d $IN 2&>1 > /dev/null;
done
unzip -j -o -q $zip system/framework/framework-res.apk -d $IN 2&>1 > /dev/null;
unzip -j -o -q $zip system/framework/framework-miui-res.apk -d $IN 2&>1 > /dev/null;
done
zip=dummy [COLOR=Red]<-- after the script is run, assign the string 'dummy' to $zip[/COLOR]
}
Click to expand...
Click to collapse
Added the code
For now, the script runs through all options fine without halting. Great! But i still need to test it more thoroughly.
Now, i will look into refining the script. Especially the "5. mods" and "10. build flashable zip".
Here's how i'd like it to operate:
When option 4 is processed, i'd like to be able to add some modding to the files. I think it's better to do this before recompiling (option 6/12) because if an apk needs to be edited, it's already decompiled.
For the 3way reboot, it needs to modify some jars. I'd like the user to choose which zip from the source_roms folder to work with and extract the version number the zip filename. (The filename will ALWAYS contain a version number..) So that when the jars are processed, the output files will be placed in a folder with the version number (like /out/"version") This is because, when i want to build my flashable zip, i want the user to input which version number to build it for and then it would pull whatever mods are made for this version number. (Because the entire ROM would probably break if those version numbers don't match)
For the crt-off effect, it should do the same, but it has to check wether a jar file is already existing in /out/"version" and modify that one if it is. (Both mods need to modify the same file)
Right now, i have extra options for OFFICIAL roms. The mods are exactly the same, only the file naming in the function are different. I'd like to eliminate those options, by having the user choose what file to process, like i explain in the above..
Guess that gets a little complicated, hope you get what i mean.. It'll take some time to re-write my functions and the code, but eventually, i'll get there!
Ok, so I got it working, with the creation of the folder from the filename. Cool, one step further, I'll continue development tonight or tomorrow
Ok, next problem
In the following function, i want the script to check, if any apks exist in the folder. If yes, present the menu to choose which one to decompile. If no, display an error message and return to the main menu.
But something is up with the LS command, no matter if there are files or not in the folder, it returns the message "no files found"..
Having trouble figuring this one out..
Code:
decompile_single () {
shopt -s failglob
echo "[--- Choose apk number, or x to exit ---]"
echo ""
echo ""
cd $IN
if [ "$(ls -A $IN)" ]; then
echo ""
echo "No files found.."
echo ""
else
select file in *.apk
do
cat /dev/null > $LOG/decompile_log.txt
[[ $REPLY == x ]] && . $HJEM/build
[[ -z $file ]] && echo "Invalid choice for single decompiling" && continue
echo
echo "Decompiling $file" 2>&1 | tee -a $LOG/decompile_log.txt
apktool d -f "$file" $DEC/$file
cp -f $HJEM/sort.py $DEC/$file
python $DEC/$file/sort.py
rm -r $DEC/$file/sort.py
break
done
fi
}
Any ideas?
Okay...
The output of the command "ls -A $IN" exits with 0 if successful, otherwise it exits with 1. A good way to look at 'if' constructs is...(if "0" (goto)-> then.....if "anything else" (goto)-> else). If you're unsure of what the exit status of a command is, you can enter it in the terminal while piping it into the "echo $?" command. "$?" is a bash variable that represents the exit code of the previous command only.
For your example, you can test the exit status of that command like so...
Code:
ls -A ~/buildtool/apk_in | echo $?
Since the exit status is 0, then your output will be "No files found.." But here's where it gets tricky...The exit status of the 'ls' command will always be 0 unless the directory just cannot be accessed, which is why you will always get the same output..."No files found..". You can find out more about the exit status of a command by visiting its man page (man ls).
To get around this, you need to write the command in such a way that will give you an exit status of anything other than 0 if the condition is not met. Since you only want to check for the existence of ".apk" files you could expand on the command using a regular expression and the 'wc' command, like with my previous example...
Code:
if [ "$(ls -A $IN | grep '.\+\.apk$' | wc -l)" -eq 0 ]; then
echo ""
echo 'No ".apk" files found..'
echo ""
else
...
soupmagnet said:
Okay...
The output of the command "ls -A $IN" exits with 0 if successful, otherwise it exits with 1. A good way to look at 'if' constructs is...(if "0" (goto)-> then.....if "anything else" (goto)-> else). If you're unsure of what the exit status of a command is, you can enter it in the terminal while piping it into the "echo $?" command. "$?" is a bash variable that represents the exit code of the previous command only.
For your example, you can test the exit status of that command like so...
Code:
ls -A ~/buildtool/apk_in | echo $?
Since the exit status is 0, then your output will be "No files found.." But here's where it gets tricky...The exit status of the 'ls' command will always be 0 unless the directory just cannot be accessed, which is why you will always get the same output..."No files found..". You can find out more about the exit status of a command by visiting its man page (man ls).
To get around this, you need to write the command in such a way that will give you an exit status of anything other than 0 if the condition is not met. Since you only want to check for the existence of ".apk" files you could expand on the command using a regular expression and the 'wc' command, like with my previous example...
Code:
if [ "$(ls -A $IN | grep '.\+\.apk$' | wc -l)" -eq 0 ]; then
echo ""
echo 'No ".apk" files found..'
echo ""
else
...
Click to expand...
Click to collapse
Yes, thankyou!! Again, learning new stuff..
I just added your earlier code to this function.. Of course, it works like a charm! Facepalm on me! Hehe!
Been reading page after page about regular erxpressions, tests and all kinds of commands this weekend, i kinda stares blind at my code sometimes, haha!
1982Strand said:
Yes, thankyou!! Again, learning new stuff..
I just added your earlier code to this function.. Of course, it works like a charm! Facepalm on me! Hehe!
Been reading page after page about regular erxpressions, tests and all kinds of commands this weekend, i kinda stares blind at my code sometimes, haha!
Click to expand...
Click to collapse
I would say, the things you need to be comfortable with are (in order of importance IMO)...
man pages
exit statuses
debugging
regular expressions
pipes
data manipulation
loops
conditions
everything else
soupmagnet said:
I would say, the things you need to be comfortable with are (in order of importance IMO)...
man pages
exit statuses
debugging
regular expressions
pipes
data manipulation
loops
conditions
everything else
Click to expand...
Click to collapse
Got some more reading ahead of me
Anyways, i think the script is pretty good now, it suits my needs so far and most of the errors are taken care of..
I can always improve the code, so i'll probably continue developing on this.. Also because it's not perfect at all and still got some flaws here and there...

[Q] adb works but not extract-files.sh

I am trying to extract vendor files from an i8730 phone using extract-files.sh
I have Linux Mint 14 with android-tools-adb installed as the adb
adb works fine to a point
[email protected] ~ $ adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
333398202BDF00EC device
adb shell and ls shows files on the phone including the vendor folder
If I run ls from my working directly I can see extract-files.sh
Think the solution is in .bashrc but believe I am not doing it right. When I run extract-files.sh I get this
[email protected] ~ $ ./extract-files.sh
bash: ./extract-files.sh: Permission denied
[email protected] ~ $ sudo extract-files.sh
[sudo] password for megan:
sudo: extract-files.sh: command not found
[email protected] ~ $ sudo./extract-files.sh
bash: sudo./extract-files.sh: No such file or directory
location adb shows
/usr/share/doc/android-tools-adb
location bashrc shows
/etc/bash.bashrc
I have edit bashrc
[email protected] ~ $ sudo gedit /etc/bash.bashrc
[sudo] password for megan:
Have added this to the end
export PATH=${PATH}:/home/megan/usr/share/doc/android-tools-adb
Think this is where I have gone wrong. Any suggestions?
Thanks
Bazzan
http://forum.xda-developers.com/showpost.php?p=7146410&postcount=5
unable to create 99-android.rules
MoonBlade said:
http://forum.xda-developers.com/showpost.php?p=7146410&postcount=5
Click to expand...
Click to collapse
Thanks MoonBlade. Think you are suggesting the version on the link so have been working through it. Had to source the files elsewhere as original link is dead. May or may not be a problem.
Got as far as creating the file in /etc/udev/rules.d/ but am unable to create a file in that folder. I am logged in as root. I can view the folder through GUI but not able to create 99-android.rules
Get this mess in terminal
[email protected] ~ $ su
Password:
megan-901 megan # cd /etc/udev/rules.d/
megan-901 rules.d # ls
Traceback (most recent call last):
File "/usr/lib/command-not-found", line 21, in <module>
os.execvp("python3", [sys.argv[0]] + sys.argv)
File "/usr/lib/python2.7/os.py", line 344, in execvp
_execvpe(file, args)
File "/usr/lib/python2.7/os.py", line 380, in _execvpe
func(fullname, *argrest)
OSError: [Errno 2] No such file or directory
megan-901 rules.d #
Not sure the above is anything to do with not being able to write to that folder. Any ideas?
Bazzan
ok im not sure exactly what youre trying to do but it sounds like you want to get files from your phones /vendor/ directory and copy them to a directory on your computer. if this is correct then you need to stop playiing around with your .bashrc and your $PATH appends. all you need to use is adb
you dont have to adb shell. once you run adb shell it opens up a terminal inside your device so if youre trying to run a shell script on your computer from inside an adb shell it just wont work.
a simpler way to put this is, if you want to get /vendor/firmware/bcm4329.bin from your phone and put it on your computer in a folder on your desktop you would run it like this
$adb pull /vendor/firmware/bcm4329.bin /home/megan/Desktop/phonevendorfirmware/bcm439.bin
and the directory and file will automatically be created on your computer. from there you can do what ever you wanted to do to the files that you pulled from the phone.
the same works in reverse if you want to move a file to the phone using $adb push
bazzan said:
[email protected] ~ $ ./extract-files.sh
bash: ./extract-files.sh: Permission denied
Click to expand...
Click to collapse
You need to give execution permissions to the script, this way:
Code:
chmod +x extract-files.sh
And then, run your script like this (if the script doesn't need root permissions, run it without sudo):
Code:
sudo ./extract-files.sh
Many thanks haxin and RoberGalarga
I was given the extract-files.sh by a developer to extract vendor files for ROM development - i8730. He did not have the phone (I don't at the moment as has been wrapped for the kids to give to me for my birthday - practicing on an a Galaxy S)
From peeking inside the file it looks like a batch file that grabs all the content from the vendor folder. Did SQL 10 years ago and looks like that. Essentially does what you gave me haxim, but pulls the content of the entire folder. What is the best way to do that with adb pull?
Gave chmod +x extract-files.sh a try.
Without sudo I get
bash:./extract-files.sh : /bin/sh^M: bad interpreter: No such file or directory
With sudo
sudo: unable to execute ./extract-files.sh: No such file or directory.
Remember I am running this against a i9000, not the phone that I was given the sh file to run against. Get that back the begining of September. Not sure if that makes a difference but if it does not obvious to me.Seems to be falling over on the first line as that appears in the non sudo error message.
Have copied the content of extract-files.sh below.
Thanks again guys. Learning heaps and loving it.
Bazzan
#!/bin/sh
set -e
export DEVICE=express
export VENDOR=samsung
if [ $# -eq 0 ]; then
SRC=adb
else
if [ $# -eq 1 ]; then
SRC=$1
else
echo "$0: bad number of arguments"
echo ""
echo "usage: $0 [PATH_TO_EXPANDED_ROM]"
echo ""
echo "If PATH_TO_EXPANDED_ROM is not specified, blobs will be extracted from"
echo "the device using adb pull."
exit 1
fi
fi
BASE=../../../vendor/$VENDOR/$DEVICE/proprietary
rm -rf $BASE/*
for FILE in `egrep -v '(^#|^$)' ../$DEVICE/proprietary-files.txt`; do
echo "Extracting /system/$FILE ..."
DIR=`dirname $FILE`
if [ ! -d $BASE/$DIR ]; then
mkdir -p $BASE/$DIR
fi
if [ "$SRC" = "adb" ]; then
adb pull /system/$FILE $BASE/$FILE
else
cp $SRC/system/$FILE $BASE/$FILE
fi
done
./setup-makefiles.sh
Where did you get the script? This error:
bazzan said:
bash:./extract-files.sh : /bin/sh^M: bad interpreter: No such file or directory
Click to expand...
Click to collapse
is caused by a bad formatting in the file (Window$ editing... pfff....), so, make a new file using Gedit and paste this directly (don't copy&paste from the original script!!):
bazzan said:
#!/bin/sh
set -e
export DEVICE=express
export VENDOR=samsung
if [ $# -eq 0 ]; then
SRC=adb
else
if [ $# -eq 1 ]; then
SRC=$1
else
echo "$0: bad number of arguments"
echo ""
echo "usage: $0 [PATH_TO_EXPANDED_ROM]"
echo ""
echo "If PATH_TO_EXPANDED_ROM is not specified, blobs will be extracted from"
echo "the device using adb pull."
exit 1
fi
fi
BASE=../../../vendor/$VENDOR/$DEVICE/proprietary
rm -rf $BASE/*
for FILE in `egrep -v '(^#|^$)' ../$DEVICE/proprietary-files.txt`; do
echo "Extracting /system/$FILE ..."
DIR=`dirname $FILE`
if [ ! -d $BASE/$DIR ]; then
mkdir -p $BASE/$DIR
fi
if [ "$SRC" = "adb" ]; then
adb pull /system/$FILE $BASE/$FILE
else
cp $SRC/system/$FILE $BASE/$FILE
fi
done
Click to expand...
Click to collapse
Delete the old file, and try the new one (you can use any filename, it doesn't matter).
Many thanks RoberGalarga.
Got the script off a recognised developer along with proprietary-files.txt and setup-makefiles.sh
He is working a CWM and a rom for owners of the i8730 - he does not have the phone so community feed in content. Get the impression he is not a Windows user (he did not have a Windows script for this) so reckon I might have corrupted it.
I did as you advised and made some real progress. Now we get the following:
[email protected] ~ $ sudo ./extract-files.sh
[sudo] password for megan:
egrep: ../express/proprietary-files.txt: No such file or directory
: not foundefiles.sh: 3: ./setup-makefiles.sh:
: Directory nonexistentk ./setup-makefiles.sh: cannot create ../../../vendor/samsung/express
[email protected] ~ $
It breaks further down the script. In the home folder there is proprietary-files.txt which list the files to be extracted along with their file path. Does that message indicate it is looking for proprietary-files.txt in /home/express?
Setup-makefiles.sh is in the home folder as well and appears to be a Cyanogenmod Project file to create a blob from the the results of extract-files.sh
Bazzan
bazzan said:
Does that message indicate it is looking for proprietary-files.txt in /home/express?
Click to expand...
Click to collapse
Yes, that's it. Check again, seems like something is missing yet.
Thanks again. Got it to work by building the folder structure
/home/vendor/Samsung/express
And then running the files from there
Bazzan

A script to get a random file

Dear developers,
I have an issue in my script switching from Android 9 to 10 (devices from a Umidigi s3 Pro to a Umidigi F2)
I have installed Bosybox App on the first and Busybox Magisk module on the latter
Now the script does not work because the command
list=(`busybox find "$dirs" -type f -name *.$ext`)
returns an empty array
This is the complete script:
Bash:
#!/system/bin/sh
echo
if test "$1" = ""; then
echo "Randomfile script by Uranya <[email protected]> v1.4 01.01.2021"
echo "Usage:"
echo "sh randomfile.sh <sourcedir> <extension> <destdir>"
exit 1
fi
dirs=$1
ext=$2
dird=$3'/'
dest=$dird'random'
delim1=""
delim2=""
last='last.txt'
# create filename's array
IFS=$'\n'
# here we have the ISSUE
list=(`busybox find "$dirs" -type f -name *.$ext`)
# count number of files
num=${#list[@]}
# initialize random generator
RANDOM=$$
# generate random number in range 1-NUM
let "ran=(${RANDOM} % ${num})+ 1"
echo Random from $num files is $ran
sour=${list[ran]}
sourn=${sour#$dirs}
sourn=${sourn:1:${#sourn}}
date=$(date +"%Y.%m.%d %H:%M")
day=$(date +"%d")
hour=$(date +"%H")
minute=$(date +"%M")
message='---------------------------------------\n'$date' - '$num' >>> '$ran'\n'$delim1$sourn$delim2
if ([ "$day" = "01" ] && [[ "$minute" < "29" ]]) || [ ! -f $dird$last ]; then
echo >$dird$last $message
else
sed -i '1i'$message $dird$last
fi
echo $delim1$sourn$delim2
# rename the old file
cp $dest.$ext $dest'_back.'$ext
# copy the file
cat "$sour" >$dest.$ext
echo File copied as $delim1$dest.$ext$delim2
Can you please help me why this happens, and how to fix it?
Thank you very much for your attention!
Uranya said:
[...]
Click to expand...
Click to collapse
Having done some tests I have found this:
opening a root privileged terminal and executing
---
echo `find /storage/7BC3-1805/Music/MP3/Abba -type f -name *.mp3`
---
it returns two strings containing the names of files inside that folder, but putting it in my script continues to return an empty array, so the issue is not in the access to the folder, but in the syntax, I guess
try putting that *.$ext into quotes...
Dear friends, CXZa, after a couple of hours debugging the script, finally, I have found the mistake!
The line to be used is:
list=( `find "$dirs" -type f -name "*.$ext"` )
it is a very subtle difference: the space after and before the parenthesis!
(even the word busybox is useless)
Oddly in the Busybox app (I have had on my S3 Pro) the spaces are not mandatory, whilst in the Busybox Magisk module those spaces ARE mandatory!
I'm using that script for almost 8 years to have an every day different music for my wake up.
I'm using Tasker to call it just before my alarm get off, so the same file contains every day, a different song.
I have done a change also in the array index that did not began by 0...
So, here it is the right script:
Bash:
#!/system/bin/sh
echo
if test "$1" = ""; then
echo "Randomfile script by Uranya <@uranya7x> v1.5 26.03.2021"
echo "Usage:"
echo "sh randomfile.sh <sourcedir> <extension> <destdir>"
exit 1
fi
dirs=$1
ext=$2
dird=$3'/'
dest=$dird'random'
delim1=""
delim2=""
last='last.txt'
# create filename's array
IFS=$'\n'
list=( `find "$dirs" -type f -name "*.$ext"` )
# count number of files
num=${#list[@]}
# generate random number in range 1-NUM
let "ran=(${RANDOM} % ${num})+ 1"
echo Random from $num files is $ran
sour=${list[$ran-1]}
sourn=${sour#$dirs}
sourn=${sourn:1:${#sourn}}
date=$(date +"%Y.%m.%d %H:%M")
day=$(date +"%d")
hour=$(date +"%H")
minute=$(date +"%M")
message='---------------------------------------\n'$date' - '$num' >>> '$ran'\n'$delim1$sourn$delim2
if ([ "$day" = "01" ] && [[ "$minute" < "29" ]]) || [ ! -f $dird$last ]; then
echo >$dird$last $message
else
sed -i '1i'$message $dird$last
fi
echo $delim1$sourn$delim2
# rename the old file
cp $dest.$ext $dest'_back.'$ext
# copy the file
cat "$sour" >$dest.$ext
echo File copied as $delim1$dest.$ext
I hope it will be useful to someone else that loves to be waked up by music...
Peace everywhere!

XCOPY - Batch to copy directorys by drag and drop and dont loose directory tree or files propertys.

Hi!
So i create a simple batch so like that we can copy a directory by drag and drop to any location.
Nothing expecial untill now but, the bacth do this:
Spoiler: Copy Options
If Source is a directory or contains wildcards and Destination does not exist, xcopy assumes Destination specifies a directory name and creates a new directory. Then, xcopy copies all specified files into the new directory. By default, xcopy prompts you to specify whether Destination is a file or a directory.
Copies directories and subdirectories.
Copies all subdirectories, even if they are empty.
Verifies each file as it is written to the destination file to make sure that the destination files are identical to the source files.
Copies files and retains the read-only attribute on Destination files if present on the Source files. By default, xcopy removes the read-only attribute.
Copies files with read-only attribute.
Copies files with hidden and system file attributes. By default, xcopy does not copy hidden or system files.
Copies file ownership and discretionary access control list (DACL) information.
Copies file audit settings and system access control list (SACL) information (implies /o).
Copies files without buffering. Recommended for very large files.
Like this we can do full copy with full tree and files attributes.
Batch works like Drag and drop over the batch and only will request to write/paste destination.
This is the batch:
Spoiler: Xcopy_Full_directory.bat
Code:
@echo off & @echo.
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
)
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
@echo. & @echo [31mRequesting administrative privileges...[0m
goto UACPrompt
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params= %*
echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params:"=""%", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B
:gotAdmin
rem :To CD to the location of the batch script file (%0)
CD /d "%~dp0"
for %%a in (%*) do (
set "Sname=%~$PATH:1"
set "Dname=%~n1"
set /p root=" Write destination root here: "
)
@echo.
Xcopy /i /s /e /v /f /k /r /h /o /x /j "%Sname%" "%root%\%Dname%"
pause
I created so like this i can copy the files from Windows 11 that are in pendrived created by Media Creation Tool without lossing files propertys.
I hope this helps you to!
@jenneh check this bat, maybe helps you with something.
@persona78 You have no idea how much your posts have helped me. Some people do not understand that there are those of us that learn differently and are brand new, so you taking the time helps weirdos like me learn :>

How To Guide Add updated TOYBOX w/ ROOT to Windows Subsystem for Android™️

Preface​
Unfortunately Windows Subsystem for Android (WSA) is missing fully fledged Toybox ( This is a package of over 200 command-line tools, handy for advanced users - it's located in /usr/{bin,sbin} ) - though according to Microsoft WSA is meant to be used by app developers, as development platform, IIRC.
Toybox v0.8.4 ( released 2020-10-24 ) commands currently provided:
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
So IMO it's time to install latest fully-fledged version ( at time of this writing it's 0.8.8 released 2022-08-12 ) of Toybox on WSA:
As you can see currently the fully-fledged Toybox command suite contains the SU command ( Toybox as provided with WSA is missing it ) what allows you to root Android, will say give you elevated rights so you get complete access to everything in the operating system, and those permissions allow you to change it all.​
Remarks​USB-Debugging is by default enabled in WSA to implicitly give up your encryption secrets to the connected computer: WSA performs per-file encryption that is software-based.
This suggested updating doesn't replace / remove the pre-installed Toybox version.
Installation into Android's data partition ( recommended )​The roadmap
Connect PC to WSA
Save SELinux context of preinstalled Toybox
Download attached Toybox binary and extract it to any location on PC, e.g. C:\
Download attached SU binary and extract it to any location on PC, e.g. C:\
Next thing to do is to transfer the attached SU binary - assumed it got stored in C:\ - to /sdcard/Download because during the updating process we sometimes need elevated rights
and give executable rights to it
and set its file-ownership-UID 2000 is the default user on WSA
Create a directory named toybox under /data/local/tmp
Transfer the downloaded toybox binary to /sdcard/Download
Disable SElinux what by default in WSA is enabled
Copy the transferred toybox binary to /data/local/tmp what sets its owner to shell:shell
and give executable permission to it. (The default permissions set for other binaries is rwxr-xr-x)
Create symlinks for the all the various tools accessible by toybox binary
Set SELinux context on all files created
Re-enable SELinux because by default in WSA it's enabled
Do some housekeeping ...
and restart WSA
The script - it's a hybrid DOS / Linux coded one
@Echo off & setlocal ENABLEDELAYEDEXPANSION
popd "%CD%"
::
title WSA Toybox Updater
color f0 & mode con: cols=54 lines=40
echo(
echo ####################################
echo # #
echo # WSA Toybox Updater #
echo # #
echo # Updates existing Toybox to #
echo # version 0.8.8 what comes with #
echo # SU-function embeddedd #
echo # #
echo # (c) 2022 [email protected] #
echo # License: BSD 2-Clause #
echo # #
echo ####################################
echo(
echo Press 1 to Continue, 0 to Abort
choice /C 10 /M "Please select"
if !errorlevel! NEQ 1 ( goto :done )
cls
::
set "adb="
set "subin="
set "tbbin="
set "adb_org=adb_r33.0.3.exe"
set "tbbin_org=toybox-x86_64"
set "subin_org=su-x86_64"
set "wsa_svc=WsaService.exe"
set "address=127.0.0.1"
::
:: Sanity checks
echo(
echo Verifying availability of required files ..
for /F "tokens=*" %%t in ('fsutil fsinfo drives') do ( set "drives=%%t" )
:: 1st check folder we are running this bat from, 2nd search all drives
set "drive=%CD:~0,2%"
for /F "tokens=*" %%t in ('where /R !drive! !adb_org! 2^>nul') do ( set "adb=%%t" )
if defined adb ( goto :done_query_adb_org )
for /F "tokens=2* delims= " %%a in ("!drives!") do (
set "drive2=%%a"
for /F "tokens=*" %%t in ('where /R !drive2! !adb_org! 2^>nul') do ( set "adb=%%t" )
if defined adb ( goto :done_query_adb_org )
)
echo FATAL: !adb_org! not found on PC & goto :failed
:done_query_adb_org
for /F "tokens=*" %%t in ('where /R !drive! !subin_org! 2^>nul') do ( set "subin=%%t" )
if defined subin ( goto :done_query_subin_org )
for /F "tokens=2* delims= " %%a in ("!drives!") do (
set "drive2=%%a"
for /F "tokens=*" %%t in ('where /R !drive2! !subin_org! 2^>nul') do ( set "subin=%%t" )
if defined subin ( goto :done_query_subin_org )
)
echo FATAL: !subin_org! not found on PC & goto :failed
:done_query_subin_org
for /F "tokens=*" %%t in ('where /R !drive! !tbbin_org! 2^>nul') do ( set "tbbin=%%t" )
if defined tbbin ( goto :done_query_tbbin_org )
for /F "tokens=2* delims= " %%a in ("!drives!") do (
set "drive2=%%a"
for /F "tokens=*" %%t in ('where /R !drive2! !tbbin_org! 2^>nul') do ( set "subin=%%t" )
if defined subin ( goto :done_query_subin_org )
)
echo FATAL: !tbbin_org! not found on PC & goto :failed
:done_query_tbbin_org
echo OK
echo(
echo Checking if WSA emulator is running ...
for /F "tokens=1 delims= " %%t in ('tasklist /FI "IMAGENAME eq !wsa_svc!" 2^>nul ^| findstr /I /C:"!wsa_svc!"') do (
set "proc=%%t"
if NOT "!proc!"==[] ( goto :done_wsa_check )
)
echo FATAL: WSA is not running & goto :failed
:done_wsa_check
echo OK
tasklist /FI "IMAGENAME eq adb*" | findstr /I /C:"adb" >nul && goto :adb_running || goto :adb_not_running
:adb_running
!adb! disconnect >nul 2>&1
:: Force a fresh start of ADB
taskkill /FI "IMAGENAME eq adb*" /IM >nul 2>&1
:adb_not_running
echo(
echo Connecting Windows to WSA emulator ...
:: Ports are odd-numbered in the range 5555 to 5585,
:: the default port is 5555
for /L %%a in (5555,2,5585) do (
set "tcpport=%%a"
!adb! connect !address!:!tcpport! >nul 2>&1
:: Verify WSA emulator is connected
for /F "tokens=*" %%t in ('!adb! get-state 2^>nul') do (
set "state=%%t"
echo !state! | findstr /C:"device" >nul
if !errorlevel! EQU 0 ( goto :done_wsa_connection )
)
)
echo FATAL: WSA emulator got not connected & goto :failed
:done_wsa_connection
echo OK
::
::
::
set "subin_fn=su"
set "tbbin_fn=toybox"
set "dldir=/sdcard/Download"
set "sucmd=!dldir!/!subin_fn!"
set "tmpdir=/data/local/tmp"
set "tbdir=!tmpdir!/!tbbin_fn!"
::
::
set "sucmd=!dldir!/!subin_fn!"
set "tbbin=!dldir!/!tbbin_fn!"
:: Check if job already was done
echo(
echo Validating Toybox update already done ...
set /A fc=0
!adb! pull !sucmd! %TEMP%\!subin_fn! >nul 2>&1
if !errorlevel! EQU 0 ( set /A fc+=1 )
!adb! pull !tbbin! %TEMP%\!tbbin_fn! >nul 2>&1
if !errorlevel! EQU 0 ( set /A fc+=1 )
if exist "%TEMP%\!subin_fn!" ( del /F /Q "%TEMP%\!subin_fn!" )
if exist "%TEMP%\!tbbin_fn!" ( del /F /Q "%TEMP%\!tbbin_fn!" )
if !fc! EQU 2 ( echo OK & goto :done_files_transferred )
echo OK
echo(
echo Transferring files ...
:: Transfer SU binary to /sdcard/Download
:: because during the updating process we sometimes need elevated rights
!adb! push !subin_org! !dldir!/
if !errorlevel! NEQ 0 (
echo Failed: Transferring SU failed
goto :failed
)
:: Transfer the downloaded toybox binary to /sdcard/Download
!adb! push !tbbin_org! !dldir!/ >nul 2>&1
if !errorlevel! NEQ 0 (
echo Failed: Transferring Toybox failed
goto :failed
)
:done_files_transferred
echo OK
::
echo(
echo Updating Toybox ...
::
:: start Android shell on the WSA emulator
::
!adb! shell
set -e
#
#
DL_DIR=/sdcard/Download;
TB_DIR=/data/local/tmp/toybox;
TB_BIN=/data/local/tmp/toybox/toybox;
SU_BIN="$DL_DIR"/su;
SU_BIN_ORG=su-x86_64;
TB_BIN_ORG=toybox-x86_64;
cat < SCRIPT > "$DL_DIR"/cat.sh & chmod +x "$DL_DIR"/cat.sh & source < "$DL_DIR"/cat.sh; \
'# Save SELinux context of pre-installed Toybox' \
TOYBOX="$(which 'toybox')"; \
EXPR=$(ls -lZ "$TOYBOX"); \
TB_SECURITY_CONTEXT=$(cut -d " " -f 4 "$EXPR"); \
'# give SU binary executable rights' \
'# Get UID GID from pre-installed toybox' \
EXPR="$(ls -ld "$TOYBOX")"; \
TB_UID=$(cut -d " " -f 3 "$EXPR"); \
TB_GID=$(cut -d " " -f 4 "$EXPR"); \
'# Set these UID GID on SU too' \
chown -f "$TB_UID":"$TB_GID" "$SU_BIN"; \
'# Create a directory named toybox under /data/local/tmp' \
if [ ! -d "$TB_DIR" ]; then ( \
$SU_BIN -c 'mkdir -p "$TB_DIR" 2>/dev/null; touch "$TB_DIR" 2>/dev/null'; \
fi; \
'# rename SU and Toybox binaries provided if not already exist' \
if [[ (! -f "$SU_BIN" || ! -f "$TB_BIN") ]]; then { \
mv -T "$DL_DIR/$SU_BIN_ORG" "$SU_BIN" 2>/dev/null; \
mv -T "$DL_DIR/$TB_BIN_ORG" "$TB_BIN" 2>/dev/null; \
} \
fi; \
'# Temporarily disable SElinux what by default in WSA is enabled' \
$SU_BIN 0 setenforce 0; \
'# Copy the transferred toybox binary to /data/local/tmp/toybox what sets its owner to shell:shell' \
cp -Tp "$TB_BIN_ORG" "$TB_DIR/$TB_BIN" >/dev/null; \
'# and give executable permission to it' \
chmod -f +x "$TB_DIR"; \
'# Create symlinks for the various Linux applets provided by toybox binary' \
for i in $($TB_DIR/$TB_BIN --long); do ln -s $TB_DIR/$TB_BIN $i; done: \
'# Set SELinux context on all files created'
$SU_BIN -c 'chcon -R "$TB_SECURITY_CONTEXT toybox" "$TB_DIR"; \
'# Re-enable SELinux because by default in WSA it's enabled' \
$SU_BIN 0 setenforce 1; \
'# Do some housekeeping ...' \
rm -f "$SU_BIN","$TB_BIN" 2>/dev/null; \
SCRIPT
#
## exit the Android shell
exit
::
::
echo OK
:: and restart
echo(
echo Restarting WSA ...
!adb! reboot
echo OK
:failed
timeout /t 10 /nobreak >nul
::
:done
echo(
echo Job done. Exiting ...
pause
pushd
taskkill /FI "IMAGENAME eq adb*" /IM >nul 2>&1
endlocal & DISABLEDELAYEDEXPANSION
exit
Screenshot
Done​Enjoy your Toybox and its applets are ready to be executed.
Validation​
( using ADB code stored in a Windows .BAT-file )
Code:
@echo off & setlocal ENABLEDELAYEDEXPANSION
pushd "%CD%"
::
::
set "adb_exe=adb_r33.0.3.exe" & set "adb="
set "ip4_address=" & set "port=58526"
set "wsa_svc=WsaService.exe"
::
::
title WSA-TOYBOX-UPDATE-VALIDATOR
color f0 & mode con: cols=50 lines=40
echo(
echo ####################################
echo # #
echo # WSA Toybox Update Validator #
echo # #
echo # Verifies Toybox got updated to #
echo # version 0.8.8 what comes with #
echo # SU-function embeddedd #
echo # #
echo # (c) 2022 [email protected] #
echo # License: BSD 2-Clause #
echo # #
echo ####################################
echo(
echo Verifying presence of ADB executable ...
:: check folder we are running this bat from
set "drive=%CD:~0,2%"
for /F "tokens=*" %%t in ('where /R !drive! !adb_exe! 2^>nul') do ( set "adb=%%t" )
if defined adb ( goto :done_query_adb )
echo FATAL: !adb_exe! not found on PC & goto :failed
:done_query_adb
echo OK & echo(
echo Checking if WSA emulator is already up ...
for /F "tokens=1 delims= " %%t in ('tasklist /FI "IMAGENAME eq !wsa_svc!" 2^>nul ^| findstr /I /C:"!wsa_svc!"') do (
set "proc=%%t"
if NOT "!proc!"==[] ( goto :done_wsa_check )
)
echo FATAL: WSA is not running & goto :failed
:done_wsa_check
echo OK & echo(
:: Force a fresh start of ADBis
tasklist /FI "IMAGENAME eq adb*" | findstr /I /C:"adb" >nul 2>nul && goto :adb_is_running || goto :adb_isnot_running
:adb_is_running
:: disconnect all
!adb! disconnect >nul 2>&1
taskkill /FI "IMAGENAME eq adb*" /IM >nul 2>&1
:adb_isnot_running
::
:: get our IP4 address
echo Obtaining local IP4 address ...
rem for /F “tokens=1,2 delims=:" %%a in ('ipconfig ^| findstr /I /C:"ipv4" ^>nul') do (
rem if !errorlevel! EQU 0 ( set "ip4_address=%%b" )
rem )
if defined ip4_address ( goto :done_query_ip4_address )
:: workaround
set "ip4_address=127.0.0.1"
:done_query_ip4_address
echo OK ^[ !ip4_address!^] & echo(
echo Connecting to emulator ...
:: start using default port
!adb! connect !ip4_address!:!port! >nul
for /F "tokens=*" %%t in ('!adb! get-state ^>nul 2^>^&1 ^| findstr /C:"device" ^>nul 2^>nul') do (
set "retval=%%t"
if "!retval!"==[] ( echo Internal error occured & timeout /t 5 /nobreak >nul & goto :oops )
)
echo OK & echo(
echo Checking for SU applet is reachable ...
!adb! shell "PATH=/data/local/tmp/toybox:$PATH; su 2>/dev/null; STATUS=$?;[ $STATUS -eq 0 ] && echo "OK" || echo "Failed"; sleep 10s;"
:oops
taskkill /FI "IMAGENAME eq adb*" /IM >nul 2>&1
:failed
echo(
pause
popd
endlocal DISABLEDELAYEDEXPANSION
exit
Screenshot:
Download​
This package got attached for your convenience
Last Note​Toybox applets are for Terminal and shell scripts - you may use ScriptRunner2 for the latter.
BTW:
Before running a script edit your default shell's configuration file via adding in an DOS coded script saved to a .BAT-file
Code:
adb shell "PATH=/data/local/tmp/toybox:$PATH"
at script's begin what would cause the shell to look into /data/local/tmp/toybox first and execute the binary, if available.
Toybox command help​is here:
Toybox 0.8.9 command help
[reserved]
Can you provide an installer script? It would make it easer for all. Thanks in advance.
Sure. But needs some time. Stay tuned.
jwoegerbauer said:
if !su_found! EQU 1 ( echo SU binary found )
else ( echo SU binary not found )
Click to expand...
Click to collapse
"Else" needs to be on the same line as the "if" in order to be read by interpreter.
Or the ")" + "else" needs to drop to the line below it.
Should be:
if !su_found! EQU 1 ( echo SU binary found ) else ( echo SU binary not found )
OR
if !su_found! EQU 1 ( echo SU binary found
) else ( echo SU binary not found )
EDIT: Also, "@ECHO on" turns on verbose command output, does no good to place at the very end (no harm either)
Thanks for that error notice: implicitely corrected it by a complete revamp of the script.
can you provide a shell script command please

Categories

Resources