• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Root Self-built script lost my .apk files?

icoblue

Lurker
Nov 28, 2010
3
0
I've looked around and haven't found any thread which quite addresses my unique situation. Here it is. I've rooted my Droid X several times now, each time renaming those programs I didn't want running from .apk to .bak.

The long story short, it goes like this: Root, rename to .bak, rename to .apk, update to 2.2, root, rename to .bak, bad phone, rename to .apk, unroot, new phone, root (rinse, repeat. lol).

Now, having done this several times and being a very lazy person, I was looking for a way to save time and keystrokes, so I wrote a linux script for use inside adb shell. Here's the script:

mv /system/app/WorkContacts.apk WorkContacts.bak

mv /system/app/SocialShare.apk SocialShare.bak

mv /system/app/SocialMessaging.apk SocialMessaging.bak

mv /system/app/PhotoWidget.apk PhotoWidget.bak

mv /system/app/HelpCenter.apk HelpCenter.bak

mv /system/app/Mynet.apk Mynet.bak

mv /system/app/Blockbuster.apk Blockbuster.bak

mv /system/app/CityID.apk CityID.bak

mv /system/app/CarDock.apk CarDock.bak

mv /system/app/StatusWidget.apk StatusWidget.bak

mv /system/app/AdService.apk AdService.bak

mv /system/app/DLNA.apk DLNA.bak

mv /system/app/DlnaSystemService.apk DlnaSystemService.bak

mv /system/app/amazonmp3_1.8.11_signed_zipaligned.apk amazonmp3_1.8.11_signed_zipaligned.bak

mv /system/app/com.vznavigator.DROIDX.apk com.vznavigator.DROIDX.bak

mv /system/app/redding-7648-signed-zipped.apk redding-7648-signed-zipped.bak

mv /system/app/QuickOffice.apk QuickOffice.bak

echo "Rename Complete!"


I named this file droidxnamebak.sh and pushed it to the sd card using
: adb push droidxnamebak.sh /sdcard/droidxnamebak.sh

I entered shell and su, moved droidxnamebak.sh to /system/app:
: adb shell
$ su
# mount -o rw,remount -t ext3 /dev/block/mmcblk1p21 /system
# cd sdcard
# cp /sdcard/droidxnamebak.sh /system/app/droidxnamebak.sh

I attempted to cd to system/app, but it wouldn't let me without exit:
# exit
# cd system/app

Set permissions for file:
# chmod 0755 /system/app/droidxnamebak.sh

Ran the file:
# ./droidxnamebak.sh

Now when it ran, it gave me errors, which unfortunately I didn't have the good sense to save. Something to the effect of:

failed on mv [apk here] - no such file or directory

It gave me this error about 15 times, then told me "Rename Complete!", but continued to display 2 errors after that. Fully expecting this script to rename all 17 files, I ran ls *.bak, but it returned "No such file or directory." hmmm... so I ran ls and sure enough, all 17 had been renamed to *.bak.

Only problem is, while they've been renamed and they no longer run on the phone, adb shell now cannot do anything with them. It can't find them. All 17 of them appear under the system/app directory when I run "ls", but return "No such file or directory" when I run "ls *.bak" or when I try to rename them to ".apk", such as:

# mv /system/app/DLNA.bak DLNA.apk
mv /system/app/DLNA.bak DLNA.apk
failed on '/system/app/DLNA.bak' - No such file or directory:thinking:

So, I hope that I have fully explained the problem, and hopefully someone can help me figure out what I screwed up. :D

Thanks!
 
Well, It's been almost a month since you posted, but I just did the same thing. I wrote a script to rename Vvm.apk to Vvm.bak. It worked but I cant rename it back to .apk, move or delete it. The only fix was a nandroid restore of system.

the command I used in the script was:
mv /system/app/Vvm.apk /system/app/Vvm.bak

Maybe this bump will help figure out what went wrong.

Edit: I think I figured it out. I had an extra space at the end of the line. I removed it and now it works.
 
  • Like
Reactions: icoblue
Upvote 0
Sounds like you got it. I fixed mine as well with a little help from the Linux IRC guys. In my case, because I wrote the script in Windows (Notepad), it automatically added CR to the end of each filename.

I had to use bash string manipulation to remove the CR from the end of each line and it worked like a champ. If you have any more trouble, you can post here and I'll try to help. I think I have a pretty good handle on things now.

Thanks for posting, though!
 
Upvote 0
So the question then is, once we have all these screwed up apps that show up using "ls" in terminal (and in root explorer for that matter) but cant be renamed moved or copied, is there a way to fix it from there without a nandroid restore?

By the way I found a Windows program called jEdit (through a google search) it makes scripts with out adding the CR.
 
Upvote 0
Yes, there are probably several ways to fix this without doing a nandroid restore. Probably the easiest involves using bash string manipulation. This is how I fixed mine, as I posted earlier.

Let me start by saying that all of the following assumes that you disable your APKs by renaming them (or attempting to rename them ;)) to .bak . If you renamed them to something else, then you need to substitute that string for bak in all of the below commands.

The command I used follows and needs to be input EXACTLY as written in the triple carets, including all special characters EXCEPT the 3 carets. Such as:

<<<all* of this<#NeedS%2BE {input*}>>>
all* of this<#NeedS%2BE {input*}

Understand that you also need to be rooted, inside the SU permission, and have the system mounted as read/write and not as read only (something I would assume you already know).

The following is a single line command which essentially does 2 things:

1. Begin an operation on all files in the current directory ( the ./ part) which are named Something.bak with ANY characters trailing the .bak (the *.bak?* part).

2. Renames each file (using the mv [move command], stripping the old .bakCRap extension off and replacing in with a usable .bak extension (the "do mv "$f" "${f%.bak?*}.bak" " part).

Now, if you don't understand that, you can look at BashFAQ/100 - Greg's Wiki
That, along with my limited knowledge of C and VBA string operations, is what helped me understand how and why this is working.

Or you can just take my word for it and run the command, but understand that I am still very new to both bash and adb, and that what worked for me may not work for you without some modification. I provide no warranty. LOL.

All that said, here's the command:

<<<for f in ./*.bak?*; do mv "$f" "${f%.bak?*}.bak"; done>>>
for f in ./*.bak?*; do mv "$f" "${f%.bak?*}.bak"; done


Incidentally, with minor modification, this one command can be used to rename all of your .bak files back to .apk with one line, as follows:

<<<for f in ./*.bak; do mv "$f" "${f%.bak}.apk"; done>>>
for f in ./*.bak; do mv "$f" "${f%.bak}.apk"; done

Notice the lack of wildcard modifiers (the ? and * characters) following the %.bak in the above command. This trims only the .bak from the filename, NOT the .bakCRap . This means you would have to use the command to fix them first, then use the command to rename them. If you ran the second command without running the first, you would get the following result:

CityID.bakCRap > CityID.apkCRap

Yes, it's been renamed to .apk, but the extension still isn't usable.

Alternatively, you could modify the commands to perform both at the same time, but I could rewrite the line all night and never reach the end of what you could do with it.

Hope this helps you. A nandroid backup is a long road to travel when the shortcut through the woods keeps all your data and programs intact. :D
 
Upvote 0
Thanks! That was very helpful! Apparently I don't have notifications turned on, and I forgot to come back here and check for an answer.

But now that I am here

Here's the script I came up with.

Typical Disclaimer: Use at your own risk...

The attached version runs through Clockwork recovery (easier than typing in terminal) and installs the script to /system/xbin at the same time as renaming bloatware to .bak.

run it again (through clockwork) and it removes the script from /system/xbin and renames bloatware back to .apk.

Alternatively, after you run it the first time, you can run the script manually through terminal (that is until you run it through clockwork and it gets uninstalled)

terminal commands are:

bloat -rm

bloat -add

Pretty self explanatory but -rm removes and -add puts it back.

To view the script itself, or manually install it, you can extract it from the /xbin folder in Moto_Bloat_Update.zip

Thanks again for your help!
 

Attachments

  • Moto_Bloat_Update.zip
    162.1 KB · Views: 34
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones