Related
WARNING! THIS SCRIPT REQUIRES YOU TO CREATE AND EDIT IT!!!!
Okay, for everyone who is having issues with root enabled apps not starting correctly, I have created a script that allows me to run it via Script Manager or the command line to kill MY root enabled apps. Please do not ask for a flashable zip or a downloadable file. You will need to CREATE the script for yourself. I am just going to outline the basic parameters that I use.
Now, you will need a GOOD text editor. I recommend one of the following: Jota Text Editor, 920 Text Editor, (or, if you are a Linux-centric kind of person) Vim Touch.
Now, open the text editor and create a file on your phone with the following lines (copy and paste is fine):
Code:
#!/system/xbin/sh
clear
echo "Kill Menu"
# Function to list selections
showMenu () {
clear
echo "1) Ad Free"
echo "2) Button Savior"
echo "3) Droid Wall"
echo "4) File Expert"
echo "5) Lightflow"
echo "6) Plume"
echo "7) Quick Boot"
echo "8) Tasker"
echo "9) Titanium Backup"
echo "Q) Quit (Either q or Q will work)"
echo ""
echo "Select which app to kill and press [ENTER]"
echo ""
}
while [ 1 ]
do
showMenu
read CHOICE
case "$CHOICE" in
"1")
clear
pkill com.bigtincan.android.adfree
pkill com.bigtincan.android.adfree
pkill com.bigtincan.android.adfree
echo "Ad Free has been killed. Please restart the process."
read -p "Press [Enter] to continue." nothing
;;
"2")
clear
pkill com.smart.swkey
pkill com.smart.swkey
pkill com.smart.swkey
echo "Button Savior has been killed. Please restart the process."
read -p "Press [Enter] to continue." nothing
;;
"3")
clear
pkill com.googlecode.droidwall.free
pkill com.googlecode.droidwall.free
pkill com.googlecode.droidwall.free
echo "Droid Wall has been killed. Please restart the process."
read -p "Press [Enter] to continue." nothing
;;
"4")
clear
pkill xcxin.filexpert
pkill xcxin.filexpert
pkill xcxin.filexpert
echo "File Expert has been killed. Please restart the process."
read -p "Press [Enter] to continue." nothing
;;
"5")
clear
pkill com.rageconsulting.android.lightflow
pkill com.rageconsulting.android.lightflow
pkill com.rageconsulting.android.lightflow
echo "Lightflow has been killed. Please restart the process."
read -p "Press [ENTER] to continue." nothing
;;
"6")
clear
pkill com.levelup.touiteur
pkill com.levelup.touiteur
pkill com.levelup.touiteur
echo "Plume has been killed. Please restart the process."
read -p "Press [ENTER] to contiue." nothing
;;
"7")
clear
pkill com.siriusapplications.quickboot
pkill com.siriusapplications.quickboot
pkill com.siriusapplications.quickboot
echo "Quick Boot has been killed. Please restart the process."
read -p "Press [ENTER] to contiue." nothing
;;
"8")
clear
pkill net.dinglisch.android.taskerm
pkill net.dinglisch.android.taskerm
pkill net.dinglisch.android.taskerm
echo "Tasker has been killed. Please restart the process."
read -p "Press [Enter] to continue." nothing
;;
"9")
clear
pkill com.keramidas.TitaniumBackup
pkill com.keramidas.TitaniumBackup
pkill com.keramidas.TitaniumBackup
echo "Titanium Backup has been killed. Please restart the process."
read -p "Press [Enter] to continue." nothing
;;
"q")
exit
;;
"Q")
exit
;;
esac
done
Save it in a directory on your sdcard (I use /sdcard/Scripts) and call it something memorable. I use "Kill_Menu.sh" (without the quotation marks).
The lines you MUST change are in the showmenu function to reflect YOUR root enabled apps. Remember, this is MY list.
You MUST also change the lines in the while/do loop. Each selection corresponds to a menu item. In order to get the full name of the task you want to kill, from a command line type the following:
Code:
pgrep -l PartOfProcessName
The PartOfProcessName is something like "tasker" or "Titan" (again, without the quotation marks).
tasker will bring up something like:
Code:
2443 net.dinglisch.android.taskerm
The numbers is the process ID and WILL BE DIFFERENT. The part that you are concerned with is "net.dinglisch.android.taskerm". Put this in the script in the correct section after the "pkill" command. This way you are killing ONLY that task, and not others. The process (app) is CASE SENSITIVE!!!!
I have the script kill the process three times to make sure it doesn't respawn itself before I have a chance to restart the app.
Please keep in mind that this is a bash shell script and must be run from Script Manager with root access (su) or from the command line with "/system/xbin/sh /sdcard/Scripts/Kill_Menu.sh" (or whatever folder you put it in).
The topic is now open for discussion.
Ciao!
Nice, forgive me if I overlooked, but do I start in Scriptmanager like other .sh / scripts.
This ISN'T my Transformer Prime
Pixelation said:
Nice, forgive me if I overlooked, but do I start in Scriptmanager like other .sh / scripts.
This ISN'T my Transformer Prime
Click to expand...
Click to collapse
You can. Either there or Terminal Emulator.
Sent from my DROID X2 using Tapatalk 2
Okay, I see a lot of devs that want to put out a "rom", and I am trying to do that for all the roms- leaks, roms, etc. I think I can accomplish what most rom devs do with small flashable zips-- I just need this help to make it possible!
The only thing that is hanging me up is - change A to B, if A doesn't exist add B. I've done lots of googling, but the sed command seems REALLY complicated for what I am trying to do- and I think there must be an easier way people are already using for android! Or is there a program people are using to make these insanely complicated scrips I see?!?!
Here is an example I know I can do, and works- but it is modifying a line I know IS there:
Code:
sed 's/^ro.product.version=*/ro.product.version=Revolutionized Nonsense 2.1Final/g' /system/build.prop
Like as simple as changing my build, no problem, I know that build is there, but what if I want to change "ro.ril.gprsclass=10" to "ro.ril.gprsclass=12"- but if it ISN'T there, I want to add that line??(I'm not saying it ISN'T there, this is just an example..)
Like I said, I am sure there is a simpler way, I know SED allows patterns and all of that- I am trying to keep this simple! I don't want to replace someone's build.prop, I want to modify it(and I will make a backup)- and for all non RO(read only) lines I plan to use local.prop..
Please, I have asked a few questions here that never got answered, I eventually found a workaround, but this one has TRULY stumped me! This is all a learning process for me, and I am trying to learn the simplest/best way, not just the long and complicated way..
Thanks in advance!
SBD
So from my understanding, you are looking to write a script that modifies the build.prop, yes?
If so, you'd want to do something like this. This is pseudo-code!
if entry exists ; then
replace entry
else if entry does not exist ; then
add entry
fi
For your test, use grep.
if grep ro.sample.prop build.prop ; then
sed -d CODE HERE TO REPLACE
else
echo CODE HERE >> build.prop
fi
Please let me know if you need further help.
Sent from my PG86100 using Tapatalk 2
tommytomatoe said:
So from my understanding, you are looking to write a script that modifies the build.prop, yes?
If so, you'd want to do something like this. This is pseudo-code!
if entry exists ; then
replace entry
else if entry does not exist ; then
add entry
fi
For your test, use grep.
if grep ro.sample.prop build.prop ; then
sed -d CODE HERE TO REPLACE
else
echo CODE HERE >> build.prop
fi
Please let me know if you need further help.
Sent from my PG86100 using Tapatalk 2
Click to expand...
Click to collapse
So with my example above would this work??
Code:
if grep ro.ril.gprsclass= /system/build.prop ; then
sed 's/^ro.ril.gprsclass=*/ro.ril.gprsclass=12/g' /system/build.prop
else
busybox echo "ro.ril.gprsclass=12" >> /system/build.prop
Your example makes me wonder if sed gets use differently aftergrep(or is that formatted correctly?) and what is the -d for?
I need to do this with a lot of lines, so if this does work I need to make sure that the formatting is correct.. because I just want to make a file that works, not troubleshoot it a million times!(My luck I'd leave a space in it somewhere that screws it all up)..
I'm sorry if these questions seem ridiculous, but this will help me get done what I am trying to do - I've already learned so much java, scripting, coding, unix- I don't even know what's what anymore.. I'm just trying to keep learning!
I would use busybox sed just I'm case.
You have two choices with sed.
sed -d will remove the line and then you would echo a new one.
sed -i would replace it inline. Your current script would not work. You need to use -i flag.
Sent from my PG86100 using Tapatalk 2
tommytomatoe said:
I would use busybox sed just I'm case.
You have two choices with sed.
sed -d will remove the line and then you would echo a new one.
sed -i would replace it inline. Your current script would not work. You need to use -i flag.
Sent from my PG86100 using Tapatalk 2
Click to expand...
Click to collapse
I would actually prefer it removed the original line if it will add the modified line at the end of the build.prop
So would this work:
if grep ro.ril.gprsclass= /system/build.prop ; then
busybox sed -d 's/^ro.ril.gprsclass=*/ro.ril.gprsclass=12/g' /system/build.prop
else
busybox echo "ro.ril.gprsclass=12" >> /system/build.prop
Click to expand...
Click to collapse
Or does the sed command have to be modified because of the -d or because of the grep command?
I appreciate you taking the time- I have had several questions get totally overlooked when trying to ask development questions, no matter where I post! You're awesome(and people will be thankful when I get this done, I'm sure!)
SBD
Code:
#!/bin/bash
arg="Cool ass rom bro!"
oldarg=`grep ro.product.version /system/build.prop |cut -d"=" -f2`
sed -i "s/^ro.product.version=*/ro.product.version=${arg}/g" /system/build.prop >> /tmp/tmp-prop
chknewarg=`grep ro.product.version /tmp/tmp-prop |cut -d"=" -f2`
if "$chknewarg" = "$arg"; then
mv /tmp/tmp-prop /system/build.prop
echo "File edited"
else
rm /tmp/tmp-prop
echo "Expected $arg, got $chknewarg instead"
exit 1
fi
exit 0
POC, piece not tested, but should be what you are looking for. This will indeed sed the file but output the file to tmp, then run a check to make sure it wrote it properly, if so it will replace your file. Simple enough.
lithid-cm said:
Code:
#!/bin/bash
arg="Cool ass rom bro!"
oldarg=`grep ro.product.version /system/build.prop |cut -d"=" -f2`
sed -i "s/^ro.product.version=*/ro.product.version=${arg}/g" /system/build.prop >> /tmp/tmp-prop
chknewarg=`grep ro.product.version /tmp/tmp-prop |cut -d"=" -f2`
if "$chknewarg" = "$arg"; then
mv /tmp/tmp-prop /system/build.prop
echo "File edited"
else
rm /tmp/tmp-prop
echo "Expected $arg, got $chknewarg instead"
exit 1
fi
exit 0
POC, piece not tested, but should be what you are looking for. This will indeed sed the file but output the file to tmp, then run a check to make sure it wrote it properly, if so it will replace your file. Simple enough.
Click to expand...
Click to collapse
Okay, if I get this right, the line that says
Code:
chknewarg=`grep ro.product.version /tmp/tmp-prop |cut -d"=" -f2`
is cutting the line that was taken out or modified by sed, or added by the grep command if it didn't exist, and it puts that line at the end of the original build.prop? I could just have this same script 10 times if I wanted to make 10 prop edits and all would be at the end of the original build.prop?
I plan on making a backup of the original build.prop in the script before doing any of this, I just want to make sure that I understand exactly what the outcome is(and this is all just trying to learn anyways, so I am trying to breakdown the commands to understand which line is doing what)..
And thanks for the reply, I'm trying to keep it simple, but I also want to do this as safely as possible too if this goes right, this might end up modifying many phones, and I don't want to screw up any of them!
EDIT: and is there a way I can test this on my pc before trying it on the phone? I would think there is a way to run the script on my pc with a test build.prop to make sure it makes the expected changes- THIS would be very helpful in getting the script perfect!
test it with this:
script
Code:
#!/bin/bash
file=$HOME/build.prop
tmpf=/tmp/tmp-prop
line=ro.product.version
arg="Cool ass rom bro!"
oldarg=`grep $line $file |cut -d"=" -f2`
sed "s/$line=.*/$line=${arg}/g" $file > $tmpf
chknewarg=`grep $line $tmpf |cut -d"=" -f2`
if [ "$chknewarg" = "$arg" ]; then
mv $tmpf $file
echo "File edited"
else
rm $tmpf
echo "Expected $arg, got $chknewarg instead"
exit 1
fi
exit 0
$HOME/build.prop
Code:
ro.product.version=Old Rom Name
ro.generic.type=ForSure
Btw. Do you plan on running this script from Android or from Linux?
Sent from my PG86100 using Tapatalk 2
tommytomatoe said:
Btw. Do you plan on running this script from Android or from Linux?
Sent from my PG86100 using Tapatalk 2
Click to expand...
Click to collapse
Yes, it does matter if your running from the linux OS or android. My example was more edited for him to test locally. There will need to be a few changes before he can run this via android. Plus he should think about getting his own busybox binary to run from, that way he knows that the version he has would work for him.
lithid-cm said:
Yes, it does matter if your running from the linux OS or android. My example was more edited for him to test locally. There will need to be a few changes before he can run this via android. Plus he should think about getting his own busybox binary to run from, that way he knows that the version he has would work for him.
Click to expand...
Click to collapse
Yeah I just wanted it to be clear for him. Since your sample script has /bin/bash I didn't want OP to be confused at why it didn't work
And definitely as lithid said you should build your own busybox so you know what all the applets are and what arguments they can receive.
If you need one I have one built with all features enabled. (v1.9.4) I need to download latest source.
lithid-cm said:
Yes, it does matter if your running from the linux OS or android. My example was more edited for him to test locally. There will need to be a few changes before he can run this via android. Plus he should think about getting his own busybox binary to run from, that way he knows that the version he has would work for him.
Click to expand...
Click to collapse
Well, I decided that I can try testing with script manager, the goal is to have an updater-script run this script to make a backup then the modifications to the build.prop that I need. I modified your last example to this
Code:
#!/bin/bash
file=/system/build.prop
tmpf=/tmp/tmp-prop
line=ro.product.version
arg="Cool ass rom bro!"
oldarg=`grep $line $file |cut -d"=" -f2`
sed "s/$line=.*/$line=${arg}/g" $file > $tmpf
chknewarg=`grep $line $tmpf |cut -d"=" -f2`
if [ "$chknewarg" = "$arg" ]; then
mv $tmpf $file
echo "File edited"
else
rm $tmpf
echo "Expected $arg, got $chknewarg instead"
exit 1
fi
exit 0
and I get a
Code:
failed on '/tmp/tmp-prop' - cross-device link
File edited
And yes I am running it as root.
But I imagine it is because commands in the script aren't using busybox? The final update already has the busybox binary to run from that SHOULD work - but I'll gladly take an updated one!
So for testing with script manager(or even in my flashable) what changes do I need to make? I figured I'd ask before I try flashing this..
EDIT: I did some googling, the only reason it didn't work with Script manager had to do with the mv command, I changed it to copy, and it executed beautifully.. since it deletes the tmp file anyways, shouldn't be an issue right?
Edit2: This is where my noobiness with scripts come in(especially when you involve if/then or variable statements)
I am trying to create probably 15 build.prop edits, I am sure there is just an error in the formatting(or worse), but I get a
test2.sh[11]: syntax error: 'if' unmatched
Click to expand...
Click to collapse
when I try to add the next build.prop edit:
#!/bin/bash
file=/system/build.prop
tmpf=/sdcard/tmp/tmp-prop
arg="Cool ass rom bro!"
oldarg=`busybox grep ro.product.version $file |cut -d"=" -f2`
sed "s/ro.product.version=.*/ro.product.version=${arg}/g" $file > $tmpf
chknewarg=`busybox grep ro.product.version $tmpf |cut -d"=" -f2`
if [ "$chknewarg" = "$arg" ]; then
cp $tmpf $file
echo "File edited"
else
rm $tmpf
echo "Expected $arg, got $chknewarg instead"
arg2="12"
oldarg2=`ro.ril.gprsclass $file |cut -d"=" -f2`
sed "s/ro.ril.gprsclass=.*/ro.product.version=${arg2}/g" $file > $tmpf
chknewarg=`busybox grep ro.ril.gprsclass $tmpf |cut -d"=" -f2`
if [ "$chknewarg" = "$arg2" ]; then
cp $tmpf $file
echo "File edited"
else
rm $tmpf
echo "Expected $arg2, got $chknewarg instead"
exit 1
fi
exit 0
Click to expand...
Click to collapse
Change #/bin/bash at the top to #/system/bin/sh
That was what my previous comment was referring to
Sent from my PG86100 using Tapatalk 2
tommytomatoe said:
Change #/bin/bash at the top to #/system/bin/sh
That was what my previous comment was referring to
Sent from my PG86100 using Tapatalk 2
Click to expand...
Click to collapse
Noted. I just realized this script doesn't create the line if the line isn't found.. how do I fix that?
For example this:
Code:
#!/sbin/sh
file=/system/build.prop
tmpf=/sdcard/tmp/tmp-prop
line=ro.ril.gprsclass
arg="12"
oldarg=`busybox grep $line $file |cut -d"=" -f2`
sed "s/$line=.*/$line=${arg}/g" $file > $tmpf
chknewarg=`grep $line $tmpf |cut -d"=" -f2`
if [ "$chknewarg" = "$arg" ]; then
cp $tmpf $file
echo "File edited"
else
rm $tmpf
echo "Expected $arg, got $chknewarg instead"
exit 1
fi
exit 0
Gives me "Expected 12, got instead"
so how do I make sure to insert the line if it isn't actually there? People rolling with stock won't have many of the tweaks I am trying to modify- I want to make sure they are covered(without possibly duplicating script)
Silentbtdeadly said:
Noted. I just realized this script doesn't create the line if the line isn't found.. how do I fix that?
For example this:
Gives me "Expected 12, got instead"
so how do I make sure to insert the line if it isn't actually there? People rolling with stock won't have many of the tweaks I am trying to modify- I want to make sure they are covered(without possibly duplicating script)
Click to expand...
Click to collapse
Code:
#/system/bin/sh
# Definitions
file=/system/build.prop
tmpf=/tmp/tmp-prop
line_list="ro.product.version=New ro.ril.gprsclass=12"
# Function to get args as needed for loop
getargs() {
par=$1
line=`echo $par |cut -d"=" -f1`
arg=`echo $par |cut -d"=" -f2`
}
# Loop to make all changes in line_list
for x in $line_lst; do
# Get all needed arguments
getargs $x
# Write this change to a tmp file to check on it
oldarg=`grep $line $file |cut -d"=" -f2`
sed "s/$line=.*/$line=${arg}/g" $file > $tmpf
# Check if the change was made
chknewarg=`grep $line $tmpf |cut -d"=" -f2`
if [ "$chknewarg" = "$arg" ]; then
cp $tmpf $file
if [ -f $tmpf ]; then
rm $tmpf
fi
echo "File edited"
else
if [ -f $tmpf ]; then
rm $tmpf
fi
echo "Expected $arg, got $chknewarg instead"
exit 1
fi
# If it doesn't exist at all append it to the file
chkexists=`grep -c $line $file`
if [ $chkexists -eq 0 ]; then
echo "$x" >> $file
fi
done
exit 0
lithid-cm said:
Code:
#/system/bin/sh
# Definitions
file=/system/build.prop
tmpf=/tmp/tmp-prop
line_list="ro.product.version=New ro.ril.gprsclass=12"
# Function to get args as needed for loop
getargs() {
par=$1
line=`echo $par |cut -d"=" -f1`
arg=`echo $par |cut -d"=" -f2`
}
# Loop to make all changes in line_list
for x in $line_lst; do
# Get all needed arguments
getargs $x
# Write this change to a tmp file to check on it
oldarg=`grep $line $file |cut -d"=" -f2`
sed "s/$line=.*/$line=${arg}/g" $file > $tmpf
# Check if the change was made
chknewarg=`grep $line $tmpf |cut -d"=" -f2`
if [ "$chknewarg" = "$arg" ]; then
cp $tmpf $file
if [ -f $tmpf ]; then
rm $tmpf
fi
echo "File edited"
else
if [ -f $tmpf ]; then
rm $tmpf
fi
echo "Expected $arg, got $chknewarg instead"
exit 1
fi
# If it doesn't exist at all append it to the file
chkexists=`grep -c $line $file`
if [ $chkexists -eq 0 ]; then
echo "$x" >> $file
fi
done
exit 0
Click to expand...
Click to collapse
Alright, I got some stuff to do now so I won't be able to play with it for a while, but extra thanks for including the #reasons for the lines, with that I will hopefully be able to get it working AND learn more about what it is I am doing..
Of course the frustrating part is that as a CONCEPT this seems so simple, and I was a little scared it would get fairly complicated to do it.. but this isn't as bad as I thought it would be. Thumbs up for the help!
Alright, let me ask you this, because I haven't decided yet what the final choice will be as far as future updates..
What if I did this - my original release has lines like this in the updater script:
ui_print(" Tweaking /system/build.prop...");
set_perm(0, 0, 0777, "/system/tmp/add_to_buildprop.sh");
run_program("/system/tmp/add_to_buildprop.sh");
set_perm(0, 0, 0777, "/system/tmp/tweak1.sh");
run_program("/system/tmp/tweak1.sh");
set_perm(0, 0, 0777, "/system/tmp/tweak2.sh");
Click to expand...
Click to collapse
The add_to_buildprop.sh script could be changed to a different script(to avoid duplicates), and each tweak.sh script would modify or add ONE line of code in the build.prop.
Calling up separate scripts, each modifying the build.prop like the code in post #14(except with code added to add a line when none exists)..
Then in the next update I add NEW tweaks - this way if someone is new to the "rom" they would flash the first update, then the second one - or I could offer a combined update for new users and old alike(as long as the scripts were written to modify or add missing lines in the build.prop it wouldn't create duplicate lines, and everything they've already flashed wouldn't duplicate)?
I'm just seeing how complicated the script in the last post would get as I continue to add more and more updates to the same script, rather than create more small flashable scripts and modifying the updater script to flash them? Does this make sense?
I am guessing this is why people put out full "roms" - but I am trying to find a way to accomplish the same task for EVERYONE - as long as I pick the right modifications(like specific to the ICS build) it WILL work on ANY rom..
If my logic makes sense, then what lines would I add to the code in post #14 to add lines when they don't already exist? I'm sorry if I am being a pain, but it seems easier to flash 14 scripts than make one incredibly complex script that makes 14 changes..(especially when you consider future updates)
Thanks in advance
SBD
Silentbtdeadly said:
Alright, let me ask you this, because I haven't decided yet what the final choice will be as far as future updates..
What if I did this - my original release has lines like this in the updater script:
The add_to_buildprop.sh script could be changed to a different script(to avoid duplicates), and each tweak.sh script would modify or add ONE line of code in the build.prop.
Calling up separate scripts, each modifying the build.prop like the code in post #14(except with code added to add a line when none exists)..
Then in the next update I add NEW tweaks - this way if someone is new to the "rom" they would flash the first update, then the second one - or I could offer a combined update for new users and old alike(as long as the scripts were written to modify or add missing lines in the build.prop it wouldn't create duplicate lines, and everything they've already flashed wouldn't duplicate)?
I'm just seeing how complicated the script in the last post would get as I continue to add more and more updates to the same script, rather than create more small flashable scripts and modifying the updater script to flash them? Does this make sense?
I am guessing this is why people put out full "roms" - but I am trying to find a way to accomplish the same task for EVERYONE - as long as I pick the right modifications(like specific to the ICS build) it WILL work on ANY rom..
If my logic makes sense, then what lines would I add to the code in post #14 to add lines when they don't already exist? I'm sorry if I am being a pain, but it seems easier to flash 14 scripts than make one incredibly complex script that makes 14 changes..(especially when you consider future updates)
Thanks in advance
SBD
Click to expand...
Click to collapse
The script I gave you already does everything. Just add edits to line_list
Sent from my Nexus S 4G using xda premium
lithid-cm said:
The script I gave you already does everything. Just add edits to line_list
Sent from my Nexus S 4G using xda premium
Click to expand...
Click to collapse
Alright, I just wasn't sure if this code was better for a one time flashable since I intended to put out future updates.. I'm gonna play with it now, and thanks again for taking the time to put so much work into it!(it is quite informative, and most of this is me trying to learn, to break into the next level of work).
Thanks again!
Oh also, in the script make sure you use busybox to mount system with rw (busybox mount -o remount,rw /system). It is not enough most of the time to Mont system in updater-script
Sent from my PG86100 using Tapatalk 2
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...
Hey there
Thought this might help some of you finding yourself in a huge mess because WhatApp restores all its media with the date the restore takes place. I wrote a little shellscript you can run in "adb shell". Just paste it into the shell and run it inside WhatsApps Folders.
In "WhatsApp Images" and it's subfolder "Sent" use this:
Code:
for file in *; do
if [ -f "$file" ]; then
timestamp=$(echo "$file" | sed 's/^IMG-\(.*\)-WA\(...\)\(.\)\..*/\10\2\.0\3/g')
echo $timestamp
echo $file
touch -m -t $timestamp $file
fi
done
For "WhatsApp Animated Gifs" and "WhatsApp Video" use this:
Code:
for file in *; do
if [ -f "$file" ]; then
timestamp=$(echo "$file" | sed 's/^VID-\(.*\)-WA\(...\)\(.\)\..*/\10\2\.0\3/g')
echo $timestamp
echo $file
touch -m -t $timestamp $file
fi
done
Keep the following in mind:
- This code works only if your version of Android allows you to change the modified date of files without root. As far as I know this is the case since Andoid 9
- This code doesn't work if you have files with a WA-Number higher than 0599 as my script doesn't take care to match the number with a proper timeformat.
- This code changes the last modified date of your files like this:
Filename: IMG-20190915-WA0039.jpg
Timestamp: 201909150003.09 -> 20190915 00:03:09
Feedbacks and comments welcome
Greets Air
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!