Hi All Dev's,
In all dev forums we generally face various challenges and as such need to ask users a lot of question's if you have done this or not etc.
I am thinking of creating a simple script which when run on the machine can give us all the details as much as required.
for example for my BT5 and ubuntu work i require output of following commands.
mount
which busybox
echo $PATH
busybox
need inputs from other developers what exact details do they require to debug so that we can make a custom debug script which we can ask user to run once and use that as input for all its queries.....
More i will keep on adding in here... need dev's input here.
Note to MOD : this thread is in Dev section coz work is going on i am working on script just crowdsourcing the content as i don't want to leave anything out....
u will need to check for the following most used commands:
Code:
cat /proc/mtd
which
busybox
mount
ls -l `which mount`
ls -l `which busybox`
ls -l `which sh`
ls -l `which chmod`
ls -l `which chwon`
ls -l `which grep`
ls -l `which sed`
ls -l `which awk`
and so on...
u get the idea...
so u get most info related to the device... MTD blocks, busybox location, mount points, location & symlink info (if any) of most used commands
Thanks for the inital tips ... working in this as i needed it for BT thread thought i would crowdsource the idea.
ohk so here is what i am doing right now.
creating a simple script which will generate all the debug output and dump it in /sdcard/debug_log.txt
then we can ask use to upload this debug_log.txt for our debugging.
To All Dev,
please suggest anything else you need to check frequently which we can add in here.
Will be uploading first version in few minutes.
@DooMLorD : might need your help in creating a recovery zip file of it.
anantshri said:
...
@DooMLorD : might need your help in creating a recovery zip file of it.
Click to expand...
Click to collapse
ya sure let me know...
till then something for u to read/check for creating update.zip
http://forum.xda-developers.com/showthread.php?t=1041064
also some examples of update-script:
http://forum.xda-developers.com/showthread.php?p=13522506#post13522506
First Set of code file
@DooMLorD : shamelessly copied your script to check type of Recovery, although added a bit of my logic in.
Code:
# DEBUG Log generation script created by Anant Shrivastava
# known as anantshri in XDA forum
# credit goes to B,J,Z and other developers.
# any specific code taken from other dev's have credit in place.
# incase i missed something send me a PM and i will add it.
debug()
{
#general debug listing.
echo "********** BUSYBOX *****************"
which busybox
busybox
echo "********** MOUNT *******************"
mount
cat /proc/mtd
echo "*************Command Permissions***************"
ls -l `which mount`
ls -l `which busybox`
ls -l `which sh`
ls -l `which chmod`
ls -l `which chwon`
ls -l `which grep`
ls -l `which sed`
ls -l `which awk`
echo "********** ROM SPECIFIC SETTINGS ***************"
cat /system/build.prop | grep "ro.build.id"
cat /system/build.prop | grep "ro.build.display.id"
cat /system/build.prop | grep "ro.build.version.incremental"
echo "************* KERNEL INFORMATION ****************"
uname -a
echo "************* DEFAULT PATH **********************"
echo $PATH
}
debug_bt()
{
echo "BackTrack Specific Log"
ls -l /sdcard/bt
}
chk_recovery()
{
#
# Script (v1) to check for type of Recovery
# by DooMLoRD
#
# For Xperia X10 users only
#
echo "Recovery disk's available"
if [ -e /system/bin/xrecovery.tar ]
then
echo "xRecovery FOUND!"
fi
if [ -e /system/recovtools/xrecovery.tar.gz ]
then
echo "FreeXperia Recovery FOUND! [TYPE 1]"
fi
if [ -e /system/recovery/recovery.tar.bz2 ]
then
echo "FreeXperia Recovery FOUND! [TYPE 2]"
fi
echo -n "Chargemon Configured Recovery : "
REC=`cat /system/bin/chargemon | grep tar | grep recovery | cut -f4 -d"/"`
if [ $REC == "xrecovery.tar" ]
then
echo "Xrecovery"
elif [ $REC == "xrecovery.tar.gz" ]
then
echo "FreeXperia Recovery"
elif [ $REC == "recovery.tar.bz2"]
then
echo "FreeXperia Recovery type 2"
fi
}
export LOG_FILE=/sdcard/debug_log.txt
echo "Creating DEBUG LOG please wait"
echo "Collection general information"
debug > $LOG_FILE 2>&1
echo "Checking Recovery installed on phone"
chk_recovery >> $LOG_FILE 2>&1
echo "Collecting BT specific information"
debug_bt >> $LOG_FILE 2>&1
I am right now just attaching the sh file we can add an icon on desktop using gscript lite.
Please suggest if anything i missed.
ooohhhh nice modular functions in shell script!!!
great will be using this trick later for some advance work...
btw do shell scripts allow for "include" commands/scripts
EDIT:
yups i was thinking of including grep code to search for exact "Active" recovery in chargmeon...
EDIT2:
Gscript is weird... the output for ur code will display on device screen:
stderr:
stderr:
stderr:
stderr:
....
lots of them too
DooMLoRD said:
ooohhhh nice modular functions in shell script!!!
great will be using this trick later for some advance work...
btw do shell scripts allow for "include" commands/scripts
EDIT:
yups i was thinking of including grep code to search for exact "Active" recovery in chargmeon...
EDIT2:
Gscript is weird... the output for ur code will display on device screen:
stderr:
stderr:
stderr:
stderr:
....
lots of them too
Click to expand...
Click to collapse
1) just pulling off old shell scripting tricks i used to use.
include bash do support need to check if android shell will support or not.
2) So your task half done...
3) Stderr is what i don't understand at all why they occur in gscript
anantshri said:
1) just pulling off old shell scripting tricks i used to use.
include bash do support need to check if android shell will support or not.
2) So your task half done...
3) Stderr is what i don't understand at all why they occur in gscript
Click to expand...
Click to collapse
u might also want to search for:
Code:
which
on FreeX10-beta4 its a part of busybox (symlinked to busybox)
also some additional stuff u might want to check from build.prop
Code:
echo "********** ROM SPECIFIC SETTINGS ***************"
cat /system/build.prop | grep "ro.build.version.sdk"
cat /system/build.prop | grep "ro.build.version.release"
cat /system/build.prop | grep "ro.product.model"
{
"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"
}
I think this is a great idea, as a standard user it will give me a chance to provide useful feedback (rather then just saying "that's a good idea!")
So, forgive me for my ignorance of development, but could you also use the routine to perform common tests. i.e, besides the bug reports are there other sub-routines that can be executed (harmlessly) to provide the dev's with additional info on the phones' make-up.
I suggest this assuming there are some common problems that could be identified by accessing additional date not currently found in the de-bug outputs..?
Hi All,
updated the script with some more codes ....
Please suggest if anything else is needed will try to see if i can make a flashable zip for this.
changelog
1)added logcat's for events main and radio. also added option to get stacktrace of dalvik.
EDIT : script updated.....
anantshri said:
Hi All,
updated the script with some more codes ....
Please suggest if anything else is needed will try to see if i can make a flashable zip for this.
changelog
1)added logcat's for events main and radio. also added option to get stacktrace of dalvik.
Click to expand...
Click to collapse
dude u posted output of script and not the updated script itself
@DooMLorD
thanks for pointing ... correct script updated....
Please check and suggest...
anantshri said:
@DooMLorD
thanks for pointing ... correct script updated....
Please check and suggest...
Click to expand...
Click to collapse
looking good so far....
few more sugestions:
dmesg
kmesg
last_kmesg
DooMLoRD said:
looking good so far....
few more sugestions:
dmesg
kmesg
last_kmesg
Click to expand...
Click to collapse
I DooMLoRD,
Checked about all three
dmesg gives runtime output of kerenel messages.
cat /proc/kmesg is a copy of dmesg output... with a twist. once cat /proc/kmesg is done the output goes out of file and it just keeps waiting for more input.
last_kmesg as i know is for the last session.
Script is done ... will just post the details. here.
Need your help in creating a zipable file for creating this script as a simple command on shell.
Version 1.0 debug script
Code:
# DEBUG Log generation script created by Anant Shrivastava
# known as anantshri in XDA forum
# credit goes to B,J,Z and other developers.
# any specific code taken from other dev's have credit in place.
# incase i missed something send me a PM and i will add it.
debug()
{
#general debug listing.
echo "********** BUSYBOX *****************"
which
which busybox
busybox
echo "********** MOUNT *******************"
mount
cat /proc/mtd
echo "*************Command Permissions***************"
ls -l `which mount`
ls -l `which busybox`
ls -l `which sh`
ls -l `which chmod`
ls -l `which chwon`
ls -l `which grep`
ls -l `which sed`
ls -l `which awk`
echo "********** ROM SPECIFIC SETTINGS ***************"
cat /system/build.prop | grep "ro.build.id"
cat /system/build.prop | grep "ro.build.display.id"
cat /system/build.prop | grep "ro.build.version.incremental"
cat /system/build.prop | grep "ro.build.version.sdk"
cat /system/build.prop | grep "ro.build.version.release"
cat /system/build.prop | grep "ro.product.model"
cat /system/build.prop | grep "ro.modversion"
cat /system/build.prop | grep "ro.rommanager.developerid"
cat /system/build.prop | grep "ro.build.description"
cat /system/build.prop | grep "ro.build.fingerprint"
echo "************* KERNEL INFORMATION ****************"
uname -a
echo "************* DEFAULT PATH **********************"
echo $PATH
}
debug_bt()
{
echo "************* BackTrack Specific Log ************"
ls -l /sdcard/bt
ls -l /data/local/bt
ls -l `which bt`
ls -l `which stopbt`
ls -l `which startbt`
echo "************* VNC Config File *******************"
cat /data/local/bt/root/.vnc/xstartup
}
chk_recovery()
{
#
# Script (v1) to check for type of Recovery
# by DooMLoRD
#
# For Xperia X10 users only
#
echo "*********************** RECOVERY DETAILS ***************"
echo "Recovery disk's available"
if [ -e /system/bin/xrecovery.tar ]
then
echo "xRecovery FOUND!"
fi
if [ -e /system/recovtools/xrecovery.tar.gz ]
then
echo "FreeXperia Recovery FOUND! [TYPE 1]"
fi
if [ -e /system/recovery/recovery.tar.bz2 ]
then
echo "FreeXperia Recovery FOUND! [TYPE 2]"
fi
echo -n "Chargemon Configured Recovery : "
REC=`cat /system/bin/chargemon | grep tar | grep recovery | cut -f4 -d"/"`
if [ $REC == "xrecovery.tar" ]
then
echo "Xrecovery"
elif [ $REC == "xrecovery.tar.gz" ]
then
echo "FreeXperia Recovery"
elif [ $REC == "recovery.tar.bz2"]
then
echo "FreeXperia Recovery type 2"
fi
}
logcats()
{
echo "========== LOGCAT : MAIN ==================="
logcat -b main -d
echo "========== LOGCAT : EVENTS ================="
logcat -b events -d
echo "========== LOGCAT : RADIO =================="
logcat -b radio -d
echo "******** DALVIK STACK TRACE *********************"
cat `cat /system/build.prop | grep "dalvik.vm.stack-trace-file" | cut -f2 -d"="`
echo "******** Kernel Messages DMESG ******************"
dmesg
echo "******** LOG LAST KMESG *************************"
cat /proc/last_kmsg
}
export LOG_FILE=/data/local/debug_log.txt
echo "Creating DEBUG LOG please wait"
echo "Collection general information"
debug > $LOG_FILE 2>&1
echo "Checking Recovery installed on phone"
chk_recovery >> $LOG_FILE 2>&1
echo "Collecting BT specific information"
debug_bt >> $LOG_FILE 2>&1
echo "Collecting logcat's : main, events, radio + stack trace"
logcats >> $LOG_FILE 2>&1
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...
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!