Possible [How To] Moving all caches to SD? - G1 Android Development

Hi i have rooted successfully recently and was wondering how to move my caches to the SDcard, i have search around and stumble upon these 2 script that completely relocate anything with a cache to the SDcard.
Being a total noob with unix command, i can't be sure how perfect these commands are and was wondering if anyone can improve upon it, or notice if there is any problem in applying it?
Lastly, i was wondering if there is a method to activate the code easily then typing it all out?
I have done some searches but none or no one commented on how useful or practical these commands are?
Some of the searches brought me to multiple threads, and i was wondering if my suggestion would make it easier for people to look for it later on.
Again thanks in advance, i don't mind being the first to try any of these commands but wanted a error check first to see the feasibility of such codes.
Thanks to the coders who prepared the 2 code below.
daeglo said:
What it does (allegedly):
Searches /data/data for any file containing the string 'cache' which is not already a simlink.
Moves files to the supplied new cache directory.
Creates simlinks in place of the old files to the new files.
What you need to do:
Save the attached file (recache.zip)
Extract the two shell files (recache, relocate)
Examine the files to be certain I am not malicious/stupid (the latter is quite possible)
Push the files to a directory in the default path on your phone (/system/xbin works for me)
Make the files executable (chmod 555 /system/xbin/{recache,relocate})
Run the command: recache <new_cache_directory>
Synopsis
recache <new_cache_directory>
Moves all files matching /data/data/*/*cache* to new_cache_directory and creates a symlink from the old location of the file.
new_cache_directory - optional - defaults to '/sdcard/cache'
relocate file new_directory
Moves the named file to new directory, encoding the original path in the new file name and creates a symlink from the original file location.
file - required - the file to move
new_directory - required - the directory to move the file to.
edit: emphasized the need to examine the files -- I make no claim of fitness or usefulness of this script for any reason. Many eyes make deep cracks small. If anybody sees a problem with my script, post the problem and PM me about it.
Click to expand...
Click to collapse
Fnorder said:
This one should catch everything that uses 'webviewCache' - provided it's already created it's cache directory. It also has a configurable list for those that hog space in other ways.
Code:
#!/system/xbin/bb/ash
TARGET="/sdcard/cache"
CACHE="
/data/data/com.imeem.gynoid/cache
/data/data/com.google.android.street/cache
/data/data/com.android.vending/cache
/data/data/com.android.browser/app_thumbnails
/data/data/*/cache/webviewCache
"
sdtotal=0;mmctotal=0;successtotal=0;failtotal=0
if [ ! -d "$TARGET" ]; then
mkdir $TARGET
fi
for i in $CACHE; do
local odir=$(echo "$i"|sed s,^/data/data/,,)
local app=$(echo "$odir"|cut -d / -f1)
if [ -d "$i" ]; then
if [ ! -L "$i" ]; then
let mmctotal++
echo -e "$app:\n\t* Moving '$odir'..."
mkdir -p "$TARGET/$odir"
if [ ! -d "$TARGET/$odir" ]; then
echo -e "\t- Error creating directory: $TARGET/$odir"
let failtotal++
else
rm -r "$i"
ln -s "$TARGET/$odir" "$i"
if [ -L "$i" ]; then
echo -e "\t+ Success"
let successtotal++
else
echo -e "\t- Failure! Please investigate $i"
let failtotal++
fi
fi
else
let sdtotal++
fi
fi
done
echo "Matched cache dirs: $sdtotal symlinked, $mmctotal on mmc.";
if [ "$sdtotal" ]; then
echo "Successful moves: $successtotal, Failures: $failtotal"
fi
Click to expand...
Click to collapse

No one willing to look at the codes?

if you are asking on how to use that code there..
1. needs to be saved with an .sh extention eg: recache.sh and located at /usr/local/bin or you can just leave it in the root and esecute it with ./recache path/to/where/u/want/it eg: /sdcard/cache
2. need to give ti permisions.. chmod 555 recache.sh
if thats what u are looking to know?

Nitro212 said:
if you are asking on how to use that code there..
1. needs to be saved with an .sh extention eg: recache.sh and located at /usr/local/bin or you can just leave it in the root and esecute it with ./recache path/to/where/u/want/it eg: /sdcard/cache
2. need to give ti permisions.. chmod 555 recache.sh
if thats what u are looking to know?
Click to expand...
Click to collapse
No actually i was wondering if the codes are correct, and both says they do the same thing however the codes seems different. Was wondering which one should i run, and is the code correct.
Since i am a noob in Linux, i can't be sure what is happening.
I have been looking around and every other cache to sdcard method, are limited to certain programs, the code quoted by me earlier finds any cache and put it into Sdcard automatically, however other then wondering if the codes is correct, i was wondering if there is any possible drawback? And if possible, is there a method so that i can easily clear my caches too?
So my request to sum it up would be :
1)Is the code correct, and will it run?
2)Which of the 2 code is practical?
3)Anydrawback when i transfer all known cache? (Since settings to have cahce right?)
4)Last but not least, a code to clear the caches on my SDcard?

naTTan said:
No actually i was wondering if the codes are correct, and both says they do the same thing however the codes seems different. Was wondering which one should i run, and is the code correct.
Since i am a noob in Linux, i can't be sure what is happening.
I have been looking around and every other cache to sdcard method, are limited to certain programs, the code quoted by me earlier finds any cache and put it into Sdcard automatically, however other then wondering if the codes is correct, i was wondering if there is any possible drawback? And if possible, is there a method so that i can easily clear my caches too?
So my request to sum it up would be :
1)Is the code correct, and will it run?
2)Which of the 2 code is practical?
3)Anydrawback when i transfer all known cache? (Since settings to have cahce right?)
4)Last but not least, a code to clear the caches on my SDcard?
Click to expand...
Click to collapse
basically he created a repeating loop for cache .. the line you are interested in is the first part:
CACHE="
/data/data/com.imeem.gynoid/cache
/data/data/com.google.android.street/cache
/data/data/com.android.vending/cache
/data/data/com.android.browser/app_thumbnails
/data/data/*/cache/webviewCache
"
these are the only cache files at which he's looking .. now the /*/ would potentially mean all programs using /cache/webviewCache under their folder would also be moved .. there are other script and method out there that do the same thing
me personally .. i would change the target to /system/sd/cache and put them on the EXT2 partition .. it also appears he is deleting the existing cache and starting over .. i have a script that copies the existing cache before creating the link
bottom line .. should work ok

Thx for your help but one uses webview cahce while the other uses cahce alone in their command any significant difference?
There are other scripts? Mine linking me? If it not too much of a trouble?
Thanks again for all your help/.

Related

Few EXt2 questions

Is it possible to veiw the files in the EXt2 partition from our G1 terminal? If so, can we also delete files? If so, someone explain how, thanks.
asuming is mounted on /system/sd
just
cd /system/sd
ls -la /system/sd
to list the files
is their a way to erase those files
There are commands for deleting files on Android. Look up the Linux Command prompt commands for performing those functions.
If you've rooted your phone and don't know the commands already, you haven't been paying attention to the instructions.
ls = directory listing
cp = copy
mv = move/rename
rm = remove
Those are the very basics. Remember that Unix-like operating systems are case-sensitive and file.txt is different from File.txt or file.TXT.
If you're using wildcards to delete everything, take a precaution and use the dot-slash. It could save you a lot of trouble by ensuring you're only deleting files in the current working directory. To remove all text files in a directory, for example, you'd type rm ./*.txt
god, i hate how rude people are. I grew up with DOS, so dir, and del come more naturally to me than linux commands. So just ease up on the ppl that don't know linux. I didn't know linux til i started to IRC and wanted to run an eggdrop bot. Not like everyone has irc'd or compiled, or whatever. Heck, it has been so long now, I could not write an irc script or egg addon, and I think i was the first to develop some scripts in IRC 20 years ago. So all I can say is chill.
Shaggy
??huh??
whats the beef all about?
you can google the command and linux and probably have a ton of sites that list and explain the usage and stuff like that for *nix commands unix is a very old OS linus torvalds just woke up 1 day at age 15 or sumthin and said im gonna make a unix kernal that runs on my intel based pc and then instead of selling it and making a fortune I'll give it away and still make a fortune.
LINUS is the greatest man of our time, when the other OS was charging BIG $ to run Apache web servers in the .com boom (even more so now) linux was FREE and gave better throughput on the same hardware
Now if you want a pretty box booklet and packaging as you have become accustomed they have them to, some just feel better if they pay for it, free must not be as good as the one that costs right?
why did I bother just rambling, please ignore the babbling lunatic in the corner he is harmless
bhang
beartard said:
If you've rooted your phone and don't know the commands already, you haven't been paying attention to the instructions.
ls = directory listing
cp = copy
mv = move/rename
rm = remove
Those are the very basics. Remember that Unix-like operating systems are case-sensitive and file.txt is different from File.txt or file.TXT.
If you're using wildcards to delete everything, take a precaution and use the dot-slash. It could save you a lot of trouble by ensuring you're only deleting files in the current working directory. To remove all text files in a directory, for example, you'd type rm ./*.txt
Click to expand...
Click to collapse
if you dontknow how to be polite to the noobz then dont say anything at all. let someone else answer their questions.
Hi Beartard,
Thanks for the info.
This site has such a wealth of information, that it can be overwhelming to many members.
Can you tell me how to copy my apps-private from my ext2 partition to my sd card partition so I can back them up?
Thanks
beartard said:
If you've rooted your phone and don't know the commands already, you haven't been paying attention to the instructions.
ls = directory listing
cp = copy
mv = move/rename
rm = remove
Those are the very basics. Remember that Unix-like operating systems are case-sensitive and file.txt is different from File.txt or file.TXT.
If you're using wildcards to delete everything, take a precaution and use the dot-slash. It could save you a lot of trouble by ensuring you're only deleting files in the current working directory. To remove all text files in a directory, for example, you'd type rm ./*.txt
Click to expand...
Click to collapse
uh you wan't to copy your "app-private" folder as a backup in to yoru sdcard correct? well try this
busybox cp -a /system/sd/app-private /sdcard/app-private
if it don't allows you to copy do this command to re mount the system as read-write
mount -oremount,rw /dev/block/mtdblock3 /system
Hi Nitro .
I tried it both ways and it says operation not permitted.
-------------------
Update:
But wait, I connected my phone to the computer and the app-private is copied to the sdcard.
Your procedure worked!
I erased the folder that was copied to test it again.
Then I used just this set of commands and it worked again:
busybox cp -a /system/sd/app-private /sdcard/app-private
So you still get the same error, but it works.
Thanks alot Nitro!!!
Nitro212 said:
uh you wan't to copy your "app-private" folder as a backup in to yoru sdcard correct? well try this
busybox cp -a /system/sd/app-private /sdcard/app-private
if it don't allows you to copy do this command to re mount the system as read-write
mount -oremount,rw /dev/block/mtdblock3 /system
Click to expand...
Click to collapse
u tried it as root? what error u got?
well glad it worked.
Hi,
The error says:
"cannot preserve ownership of ... cannot preserve permissions of ... operation not permitted"
for every file it tries to transfer.
But then when you look in your sdcard the app-private is there.
So it is a false error.
Thanks again.
Nitro212 said:
uh you wan't to copy your "app-private" folder as a backup in to yoru sdcard correct? well try this
busybox cp -a /system/sd/app-private /sdcard/app-private
if it don't allows you to copy do this command to re mount the system as read-write
mount -oremount,rw /dev/block/mtdblock3 /system
Click to expand...
Click to collapse
It's not working for me...
My error is this:
cp: cannot stat '/system/sd/app-private': No such file or directory
Hi,
Use terminal emulator jf 1.41 or better
type su enter
then the busybox commands
Connect your phone to your computer and look on your memory card.
app-private is there
Proxin said:
It's not working for me...
My error is this:
cp: cannot stat '/system/sd/app-private': No such file or directory
Click to expand...
Click to collapse
bestwebs said:
Hi,
Use terminal emulator jf 1.41 or better
type su enter
then the busybox commands
Connect your phone to your computer and look on your memory card.
app-private is there
Click to expand...
Click to collapse
hey guys need some help here i have the same problem, (as far as the error saying 'no such file or dir') and i tried your suggestion about typing su first then the busybox commands.
i have the most current terminal emulator, unfortunately i still continue to get the same error every time i try to run the busybox commands. it just simply say 'no such file or directory"
you guys have any suggestions for me to try ?
any help would be great.
the error i get is "cannot preserve permissions of" i think that error is not something harmful im n o *nix expert but is just saying it wont save the permision of that folder i think...
Code:
# mkdir /sdcard/bk
mkdir /sdcard/bk
# busybox cp -rf /data/app-private/ /sdcard/bk
busybox cp -rf /data/app-private/ /sdcard/bk
cp: cannot preserve permissions of '/sdcard/bk/app-private': Operation not permi
tted
# ls /sdcard/bk
ls /sdcard/bk
app-private
thats what i did.. worked for me.. moved the app-private in to a folder named bk inside the sdcard
Hi,
We are assuming that you have already moved your apps and caches to the memory in a ext2 partition, correct?
Otherwise this will not work.
I 1st followed all the instructions in this post:
http://forum.xda-developers.com/showthread.php?t=468959
All this has to be done 1st including the 2 step 13's
onikus said:
hey guys need some help here i have the same problem, (as far as the error saying 'no such file or dir') and i tried your suggestion about typing su first then the busybox commands.
i have the most current terminal emulator, unfortunately i still continue to get the same error every time i try to run the busybox commands. it just simply say 'no such file or directory"
you guys have any suggestions for me to try ?
any help would be great.
Click to expand...
Click to collapse
nitro all i can say is thank you very much, i was looking through a 15 yr old unix book looking up commands, and it's just been so damn long ago i couldn't put it together.
thanks a ton. i'm sure you saved me at least a few hours.
@bestwebs ya i have done everything else including moving things to the ext2 partition i was just stuck on a few comands here and there.
but again thanks to both of you, and i'm all setup up now.
Hi,
Nitro is a real blast!
Glad it's working.

[DEV][SCRIPT] First-Boot App Install

First-Boot Install System​
I have searched Far and wide for something like this since i first put out SleeperROM in November and always come up empty.
So with the latest release, i decided it was finally time to do it myself.
All you have to do is, using the following package as a template either on its own or in your ROM, make sure your batch folder with the .apk's to install are in /data/.firstboot/
Why
Some apps like QuickPic, ConnectBot, TinyFlashlight, Flash, Google Goggles and others that rely on linked libs don't like to simply be copied to their install dir because many won't install their own libs unless the PackageManager does it and/or they won't add themselves to the packages list (like QuickPic). The old solution is to include the lib either in the /data/data/appdir/lib with the rom install OR in /system/lib but this is quite wasteful especially in the case of big apps like Flash where including the libs separately from the app effectively doubles the space taken up on the rom by that single app since the apk still contains the lib files within.
So the solution is to install on first boot by including the apps in a batch folder for the script to process.
How it works
What it does is run from the init scripts, as one of the last scripts to run, it waits until the Android core system is up (checks to be sure by waiting for the SystemUI process is running then waits for an additional 10 seconds)
Then runs /data/.firstboot.sh, which is where you should put your first boot routines. Included in this script is the batch app installer which looks for the apps in /data/.firstboot/ and stores temporary app backups in /cache/tmp -- so be mindful that on MTD roms, the cache partition is smaller so may have to modify the $tmp variable to wherever you want to store temporaries
After installing, it sleeps for a proportional number of seconds (5 seconds per app installed) to ensure there is no race condition between installs or the final permissions_fix, zipalign and tmp cleanup. The /data/.firstboot.sh script removes itself when everything is complete.
The remaining components are kept in there for additional use by the /etc/init.d/Y02firstboot script in the future, so then all that needs to be put on the phone is a new /data/.firstboot/ dir and replacement /data/.firstboot.sh to run a batch of updates.
The Apps MUST be named by their package name.
I.e. Titanium Backup MUST be named com.keramidas.TitaniumBackup.apk
the file name must correspond with the name of the data dir in /data/data/ the script is lazy in that way, i didn't feel like keeping a file manifest of installs, instead just like to drop in apps to install.
The installer
consists of the following components:
- /system/etc/init.d/Y02firstboot
- /system/xbin/rsync
- /system/xbin/fix_permissions
- /system/xbin/batch_zipalign
- /system/xbin/sleeperlog (echos, logcats, and writes a log of activity to /sdcard/sleeperlog.txt)
- /data/.firstboot.sh
- /data/.firstboot/ (batch app directory)
- NOT INCLUDED, there must be a busybox bin somewhere in $PATH - this is not a problem for most roms
See the package link for a ready to use first-boot installer [CWM] flashable. Just drop your apks into /fs/data/.firstboot/ for a batch app updater
Download the template/usable package
DOWNLOAD MOD_CWM-FirstBoot-20120112.zip
File size: 341.07 KB / MD5 23d88c349b8d2fa3cd2f9958ae99a1f6
​
THE MAIN COMPONENTS:
/system/etc/init.d/Y02firstboot
Code:
#!/system/bin/sh
# execute post-install script on First boot
# 01022012 SENSEISIMPLE
SLEEP=3
FBSCR="/data/.firstboot.sh"
BB="busybox"
pg () {
$BB ps | $BB grep "[email protected]" | $BB grep -v "$( echo $BB grep [email protected] )"
}
if [ -f "$FBSCR" ]; then
#install apps on first boot after system services have started
sleeperlog "Found $FBLOC"
sleeperlog "Waiting for system"
$BB chmod 0755 $FBSCR
while : ; do
if pg systemui; then
$BB sleep 10
sleeperlog "system loaded."
log -p i -t boot "Executing $FBSCR script"
sleeperlog "Running FirstBoot init"
$FBSCR
break
fi
sleeperlog "WAITING FOR SYSTEM SERVICE: sleeping for $SLEEP s..."
$BB sleep $SLEEP
done
fi
/data/.firstboot.sh
Code:
#!/system/bin/sh
#
# 20120107 - SENSEISIMPLE
#
log -p i -t init:firstboot "INIT.firstboot BEGIN: USER SCRIPT $FBLOC.sh"
sleeperlog "FirstBoot Script OK TO RUN"
FBLOC="/data/.firstboot"
tmp="/cache/tmp/firstboot"
bak="$tmp/bak/data/data/"
BB="busybox"
RM="$BB rm"
CP="$BB cp"
MV="$BB mv"
MKDIR="$BB mkdir"
LS="$BB ls"
CHMOD="$BB chmod"
SLEEP="$BB sleep"
GREP="$BB grep"
pg () {
$BB ps | $BB grep "[email protected]" | $BB grep -v "$( echo $BB grep [email protected] )"
}
$CHMOD 0777 /data
#install apps on first boot
if [ -d $FBLOC ]; then
sleeperlog "Found $FBLOC"
if [ "$($LS $FBLOC)" ]; then
cd $FBLOC
$MKDIR -p $bak
for pkg in *.apk; do
log -p i -t init:firstboot "INIT.firstboot INSTALLING: $pkg"
sleeperlog "PREPARING: $pkg"
pkgname=${pkg%.*}
sleeperlog "BACKING UP APP DATA - $pkgname"
#back up data, delete the original data dir to prevent install errors (pm isn't very good at what it does)
if [ -d /data/data/$pkgname ]; then
$CP -a /data/data/$pkgname $bak/$pkgname
$RM -rf /data/data/$pkgname
fi
#WAIT, then install, then WAIT SOME MORE
$SLEEP 2
sleeperlog "INSTALLING $pkgname"
pm install -r $FBLOC/$pkg &
$SLEEP 10
#REIntegrate application data
if [ -d "$bak/$pkgname" ]; then
sleeperlog "\nSYNCING APP DATA \n\n$(/system/xbin/rsync -auv --exclude=lib $bak/$pkgname/ /data/data/$pkgname/)\n"
fi
i=$((i+1))
#Move the install .apk to tmp
if $LS /data/app | $GREP "$pkgname"; then
sleeperlog "Package appears to have installed."
$MV "$pkg" $tmp/
fi
#If the firstboot batch dir is empty, delete it now
! [ "$($LS $FBLOC)" ] && $RM -rf $FBLOC
done
#WAIT for [#ofapps x 5 seconds each] to avoid a race condition
waitsecs=$(( i * 5 ))
sleeperlog "Waiting for ${waitsecs}s before Fixing Permissions"
$SLEEP $waitsecs
sleeperlog "Fixing Permissions $(/system/xbin/fix_permissions)"
sleeperlog "Running batch zipalign \n\n $(/system/xbin/zipalign)"
sleeperlog "Clearing tmp $tmp"
fi
fi
sleeperlog "FIRSTBOOT SCRIPT COMPLETE"
log -p i -t init:firstboot "INIT.firstboot SELF DESTRUCT FIRSTBOOTSCRIPT"
if ! [ "$($LS $FBLOC)" ]; then
$MV $0 $tmp/.firstboot
# COMMENT THIS OUT FOR DEBUGGING, TO NOT REMOVE THE TMP DIR
$RM -r $tmp
echo ""
fi
echo -e "#\n#COMPLETED ON $(date)\n#" >> $0
sleeperlog "FirstBoot Apoptosis"
log -p i -t init:firstboot "INIT.firstboot END: USER SCRIPT $FBLOC.sh"
THANKS
CyanogenMod team for the Fix_permissions script
DarkyROM for the Batch Zipalign script
Saving this seat . . .
does this work with a bml rom?
^^^^In theory, it would work with an NTFS rom, if one existed - different filesystems don't [usually] create any changes on the surface... if you try to copy a file from a partition of any file system to a partition of any other file system, you don't have to explicitly tell the system the fs types involved. I haven't looked through the entire script, but if there are any commands that must specify the partition type, it would be a simple matter of changing any occurances of EXT4 to YAFFS2, etc.
This could be a great way to make a clean reinstall with all of your apps intact (minus app data, do a separate backup with your backup app of choice) - first, backup your installed apps by copying them to the appropriate directory, then do a full wipe and install, with the script automatically reinstalling your apps on first boot...
EDIT: I just looked through the script more closely. First, it appears that data is backed up. Second, I can confirm that the standard, non-file system-specific linux commands are used for file operations (cp to copy, etc), so this script shouldn't need any adjustment to accomodate different file systems
Sent from my SPH-D700 using XDA App
Is it possible for someone to develop an application to backup your personal apps and then running a script in clockwork or on first boot that does the same thing as this, alllowing for personal apps to be in the rom directly after flashing. I understand that sometimes apps may not be compatible, but can randomroms rdu script be modified to choose to do this?
Sent From My Cyan4g
Good looking script SenseiSimple!!
Okay, I'm trying to use this script, but you said to put the apps in fs/data/firstboot/ but where is "fs"? I found the "firstboot.sh" file, but I'm sure I can't put the apk's in there...
In loving memory of my son "Jeffrey Ryan Giles" 11/17/1992 to 11/25/2011 :'(
sniperkill said:
Okay, I'm trying to use this script, but you said to put the apps in fs/data/firstboot/ but where is "fs"? I found the "firstboot.sh" file, but I'm sure I can't put the apk's in there...
In loving memory of my son "Jeffrey Ryan Giles" 11/17/1992 to 11/25/2011 :'(
Click to expand...
Click to collapse
If you look at the folder structure inside the SleeperROM zip, you'll see he uses an fs directory to hold his system and data folders for installation. If you're developing a ROM, you can adapt the script to point to wherever your data folder is (most other ROMs just have system and data in the root directory of the zip, so the path would just be data/firstboot/).
EDIT: no need to look in SleeperROM zip, the firstboot zip in the OP has the same folder structure. It just doesn't seem to have the firstboot directory inside data. You'll need to add that.
Sent from my SPH-D700 using XDA App
bbelos said:
If you look at the folder structure inside the SleeperROM zip, you'll see he uses an fs directory to hold his system and data folders for installation. If you're developing a ROM, you can adapt the script to point to wherever your data folder is (most other ROMs just have system and data in the root directory of the zip, so the path would just be data/firstboot/).
EDIT: no need to look in SleeperROM zip, the firstboot zip in the OP has the same folder structure. It just doesn't seem to have the firstboot directory inside data. You'll need to add that.
Sent from my SPH-D700 using XDA App
Click to expand...
Click to collapse
Thanks for the reply buddy, so what I THINK your saying is to create a folder called "first boot" in my data folder?
In loving memory of my son" Jeffrey Ryan Giles" 11/17/1992 to 11/25/2011 - RIP :'(
sniperkill said:
Thanks for the reply buddy, so what I THINK your saying is to create a folder called "first boot" in my data folder?
In loving memory of my son" Jeffrey Ryan Giles" 11/17/1992 to 11/25/2011 - RIP :'(
Click to expand...
Click to collapse
Are you trying to do this in a ROM or on the phone? Sorry if that's a dumb question, but I just want to be sure we're on the same page.
Sent from my SPH-D700 using XDA App
sniperkill said:
Thanks for the reply buddy, so what I THINK your saying is to create a folder called "first boot" in my data folder?
In loving memory of my son" Jeffrey Ryan Giles" 11/17/1992 to 11/25/2011 - RIP :'(
Click to expand...
Click to collapse
bbelos said:
Are you trying to do this in a ROM or on the phone? Sorry if that's a dumb question, but I just want to be sure we're on the same page.
Sent from my SPH-D700 using XDA App
Click to expand...
Click to collapse
i hadn't noticed my zip routine apparently skips empty .folders
in the zip, there SHOULD have been /fs/data/.firstboot into which you place whatever apk files named according to their actual package name i.e. com.keramidas.TitaniumBackup.apk for Titanium Backup, com.alensw.PicFolder.apk for QuickPic and so on...
you can find out this info in Titanium Backup by finding the app in the list and tapping its name to show the data store location.
it HAS to correspond to the actual package name in order to properly back up the data files because the package manager binary as run from a script won't overwrite the data dir so the old data has to be synced back into the new install (rsync)
I am currently refactoring the script to reduce the number of dependencies... the system will then consist of the init.d script, zipalign and rsync bins, and the /data/.firstboot.sh, /data/.firstboot dir all in one place rather than scattered throughout the system.
irule9000 said:
Is it possible for someone to develop an application to backup your personal apps and then running a script in clockwork or on first boot that does the same thing as this, alllowing for personal apps to be in the rom directly after flashing. I understand that sometimes apps may not be compatible, but can randomroms rdu script be modified to choose to do this?
Sent From My Cyan4g
Click to expand...
Click to collapse
it would be possible to create an app to do this, and i considered it because of the need to make sure the android system is fully loaded for package manager to work, but given the requirement for full root access to start running before the system is up without having to worry about android permissions or getting SuperUser approval it's easier/more effective to do it as part of the system init in a script.
as far as randomking's rdu script, they would be compatible, but they exist separately as in one shouldn't interfere with the other, because the firstboot script runs long after install once the system is up and running.
you could modify the rdu setup to include/exclude the /data/.firstboot dir and .firstboot.sh script based on the selected config, since the init script does nothing if it doesn't see the /data/.firstboot.sh file, and the .firstboot.sh script does nothing if it doesn't see the .firstboot dir
SenseiSimple said:
it would be possible to create an app to do this, and i considered it because of the need to make sure the android system is fully loaded for package manager to work, but given the requirement for full root access to start running before the system is up without having to worry about android permissions or getting SuperUser approval it's easier/more effective to do it as part of the system init in a script.
as far as randomking's rdu script, they would be compatible, but they exist separately as in one shouldn't interfere with the other, because the firstboot script runs long after install once the system is up and running.
you could modify the rdu setup to include/exclude the /data/.firstboot dir and .firstboot.sh script based on the selected config, since the init script does nothing if it doesn't see the /data/.firstboot.sh file, and the .firstboot.sh script does nothing if it doesn't see the .firstboot dir
Click to expand...
Click to collapse
Expanding on the rdu script idea, how about a prop variable in the config to specify a user apps directory on the sdcard (best if standardized)? The user can store the apks to be installed after a clean flash in this directory. The rdu script would be modified to copy those apks to the firstboot directory. Although how to handle data? Maybe another script to be run before flashing that checks the apks in the sdcard folder, and copies the current data folder to the sdcard. This data is then restored somehow with the firstboot script. This all can be in addition to the firstboot apps included with the rom.
Sent from my SPH-D700 using XDA App
app
I honestly have no developing experience. To clarify, I was I simply asking if the app could back up the users personal apps/data to the specified folders, to make this script fool proof. Then when a rom is flashed the randomromkings rdu script which currently decides on lite roms or full roms could be modified to either install apps or not install apps depending on the rom compatibility. Finally data is wiped, rom flashes, and your script runs on boot allowing the apps to all be there. Expanding on that if the ROM allows apps to be re installed via your script, through the modified rdu, your script could be moved from one directory to another allowing the process to happen and at the end moves itself back to the original directory. This means that the end user who has no clue how to do anything but flash roms (like myself, but I want to learn) has done nothing accept backing up their apps. I know this is all hypothetical, but would this be possible, and also I have another idea that is probably impossible. If a script could be written so that the apps are backed up when the rom flashes, then the rom automatically does a factory restore and wipes the various caches, meaning that less people are going to have force close issues or other avoidable bugs because they didnt wipe. thanks for all your hard work
Clear Me Here !!
You said that the script (.firstboot.sh) removes itself, but does it remove Y02firstboot script from init.d?? I don't think so, also, there are no disadvantages of this after first boot, as it won't find .firsboot.sh and skip the operation, but why shud it execute unneccesarily everytime??
@OP--Plz. tell me if i am right or wrong.......If right, plz. add a function to remove that script from init.d. However files in /xbin are OK though, so no need to remove them............
Everybody is writing and making this appear as complicated as possible! So let me clarify what I believe the idea is here. First of all, the 'RDU script' I assume you're referring to is simply a flash-able zip to set you phone for a lite or full installation. It sets a config file. I use it in my rom, and I also currently use that config file to set several other features upon installation, and changeable at anytime one of my themes is flashed.
RDU was simply meant to jump start the idea of developers making installations more uniform. Which has happened to various extents, for example, I've used this first-boot install to solve my quickpic(I love the app) and flash pre-install problems. It also fixes usb tether, vlingo, terminal, etc.
SO, what are we saying here? We'd like to be able to backup our apps to the sd card, as many apps can do for us. Then, we'd like to either:
A. Build a script into a rom to restore these apps prior to or upon installation.
or
B. Build a separate script which would be run AFTER a rom installation to restore these apps from CWM.
Yes?
P.S. I see this is very late to the game, didn't realize this thread was being revived...
Still. Neat idea, sorry I hadn't noticed it yet.
+1 Thanks
After integrating this into my custom ROM, my phone (Galaxy S 4G) would only install the first .apk file in the .firstboot directory. After I removed the code which tells it to backup/restore the /data/data directories, it worked fine. I won't need that code since the ROM does a full wipe of /data every time anyway, but I'm not sure why it doesnt work when it's there. I'm not well versed enough with Java's syntax yet to comprehend why.
Also, your first post says that it should record logs to \sdcard\sleeperlog.txt but the script tries to record it to \sdcard\sleeperromlog.txt and neither one of those files actually appear on the sd card.
Edit: I had to remove the check to make sure the .firstboot directory is empty before deleting it, but it works fine on my Galaxy S 4G ROM as long as there are no /data/data directories for the programs I am installing.
does anyone still have a template of this? The link is down.
Edit: nevermind I don't need it anymore.

JB 4.2 Nested /0 Fix Script

Hey-
I was wondering if I could get some help and feedback on a script I conceived to help 4.2 multi-user tree structure to work with pre 4.2 backups (Device, ROMs, Recoveries, Nandroids, Titaniums). Can one of you guru's (_that, becomingx, etc.) chime in and let me know if this seems logical and a good solution, what syntax errors I have, and partially test the theory and code as I am still on 4.1 and locked.
Assuming you have no stock /*/0 directories this script finds all instances of /*/0 (created from the 4.2 multi-user tree structure). /* is "the parent directory" and /*/0 is the "nested directory". First it backs up the parent directory then copies the nested directory (overwrites) into their parent directory. It also combines the backup and the parent directory in the parent directory at the end. This script assumes the user to be single-nested and after running it allows pre-4.2 backups to find their data and targets for restoration. Maybe its OK to combine before the restoration, or after, or not at all? Please give me your feedback on this and don't beat me up too hard as this is my first script with a variable and an array.
Code:
#!/system/bin/sh
nests=( grep ! /*/0 )
for NEST in "${nests[@]}"
do
mkdir /Removable/MicroSD/$NEST_bak
cp -r /$NEST /Removable/MicroSD/$NEST_bak
cp -rf /$NEST/0 /$NEST
#[Restore Pre-4.2 backups]
cp /Removable/MicroSD/$NEST_bak/*.* /$NEST
#[Backup in 4.2]
rm -rf /Removable/MicroSD/$NEST_bak
done
[Edit] Yup, this script needs some serious help. The first line doesn't even work. But when you type it as a command from the prompt it does what I'm looking to capture. How can I put this output in an array?
Code:
grep ! /*/0
Why after running the code above does my prompt which was "[email protected]: #" now show "1|[email protected]: #"? When I was trying to debug the script I even got a 2 and 3|[email protected]: #" Are these some kind of grep shells?
I've now read your post twice, and I still have no idea what you want to do - neither from the script itself nor from the textual description. The confusion starts with the fact that I have no "0" directories on my MicroSD card.
The first step in software development is always to clearly define the problem that should be solved by the software. As long as I don't understand what you want to do, I can't help you with the script - except maybe a hint: "grep" searches for text inside files, "find" searches for files or directories.
Why after running the code above does my prompt which was "[email protected]: #" now show "1|[email protected]: #"? When I was trying to debug the script I even got a 2 and 3|[email protected]: #" Are these some kind of grep shells?
Click to expand...
Click to collapse
The number is the last exit code from the previous command. It indicates that something went wrong.
_that said:
I've now read your post twice, and I still have no idea what you want to do - neither from the script itself nor from the textual description. The confusion starts with the fact that I have no "0" directories on my MicroSD card.
Click to expand...
Click to collapse
No, but you do have some in `/storage/emulated' and `/mnt/shell/emulated' , which I *think* might be what elfaure is referring to (confirm?).
The first step in software development is always to clearly define the problem that should be solved by the software. As long as I don't understand what you want to do, I can't help you with the script - except maybe a hint: "grep" searches for text inside files, "find" searches for files or directories.
Click to expand...
Click to collapse
True words indeed. Although, just telling someone what you want to do and having them show you how to do it, or having them do it for you, is never as much fun as trying to do it for yourself first.
elfaure said:
Hey-
I was wondering if I could get some help and feedback on a script I conceived to help 4.2 multi-user tree structure to work with pre 4.2 backups (Device, ROMs, Recoveries, Nandroids, Titaniums). Can one of you guru's (_that, becomingx, etc.) chime in and let me know if this seems logical and a good solution, what syntax errors I have, and partially test the theory and code as I am still on 4.1 and locked.
Assuming you have no stock /*/0 directories this script finds all instances of /*/0 (created from the 4.2 multi-user tree structure). /* is "the parent directory" and /*/0 is the "nested directory". First it backs up the parent directory then copies the nested directory (overwrites) into their parent directory. It also combines the backup and the parent directory in the parent directory at the end. This script assumes the user to be single-nested and after running it allows pre-4.2 backups to find their data and targets for restoration. Maybe its OK to combine before the restoration, or after, or not at all? Please give me your feedback on this and don't beat me up too hard as this is my first script with a variable and an array.
Code:
#!/system/bin/sh
nests=( grep ! /*/0 )
for NEST in "${nests[@]}"
do
mkdir /Removable/MicroSD/$NEST_bak
cp -r /$NEST /Removable/MicroSD/$NEST_bak
cp -rf /$NEST/0 /$NEST
#[Restore Pre-4.2 backups]
cp /Removable/MicroSD/$NEST_bak/*.* /$NEST
#[Backup in 4.2]
rm -rf /Removable/MicroSD/$NEST_bak
done
Click to expand...
Click to collapse
This is indeed a bit confusing. First I need to know what you're expecting `(grep ! /*/0)' to evaluate to before I can comment on the rest of the code.
[Edit] Yup, this script needs some serious help. The first line doesn't even work. But when you type it as a command from the prompt it does what I'm looking to capture.
Click to expand...
Click to collapse
To capture the output of a command into a variable, you need a dollar sign in front of the opening parenthesis, i.e.:
Code:
nests=$(grep ! /*/0)
But, as _that mentioned, the `grep' call probably isn't the right one to use here. `find' can surely do what you want, but requires busybox to be installed and usually needs to have a bunch of options supplied to it to make sure it's giving you exactly what you want and expect. A simple `ls' command might be all that's needed.
How can I put this output in an array?
Click to expand...
Click to collapse
I, and most other people based on the code I've seen, don't use arrays much in shell scripts. Usually a value separated list is used instead, where the separator value is a space, tab, or newline. Take the example:
Code:
ROOT_LISTING=$(ls /)
for OBJ in $ROOT_LISTING; do
...
done
When the variable $ROOT_LISTING gets expanded at execution time it winds up looking like:
Code:
for OBJ in Removable acct cache [snipped for brevity]; do
and so the `for' loop will iterate through each value after the `in' keyword that is seperated from the next one by a space, tab, or newline. (If we have files, directories, etc. with spaces (possible), tabs (unlikely), or newlines (also unlikely) in the name, we have to be trickier, but I won't get into that here. )
Hopefully this helps. If there's anything else technical that I can yammer on about for the betterment of your understanding, just holler. :good:
Hi Guys-
Thanks for the reply. What service! I simply call for the two guys I need most and like rubbing a magic lamp my genies appear.
When _that reads it twice and still has no clue what you are trying to do you know you need some serious schooling. That's why I'm here - to listen twice as often as I speak and learn something useful.
So here's what I am trying to do. JB 4.2 implemented a radical depart from previous Android versions to the directory tree structure for multi-users as you know, similar to the way Windows uses user profiles to separate users desktops, accessible installed apps, etc. This new structure created /0 subdirectories for certain directories like /sdcard and /sdcard/0 (/data/media and /data/media/0, /clockworkmod and /clockworkmod/0) and others. Playing with grep I discovered I could find all instances of any directory containing a /0 subdirectory (pair). "Find" seems a better approach than "grep" and works exactly the same with no fancy options required.
Code:
find */0
For these directory pairs I'll call them from the above output, the data that was in /directory in 4.1 is now located and pointed to in /directory/0 in 4.2. I figured if I could find all these pairs, and copy /directory/0 into /directory (after backing up /directory to SD) then 4.1 backups looking for data in /directory could now find their data and targets. Then I could copy the SD backup of /directory into /directory (now overwritten by /directory/0) to merge everything into a single folder. But after thinking about this again, this is incorrect. What I meant to do at this step is copy all /0 subdirectories of a given /directory/0 into that folder [ /directory/0/0 into /directory/0 and directory/0/0/0 into /directory/0 and /directory/0/0/0/0... into /directory/0 ] to combine all these sub-nested directories into a single /0 directory. Deep subnesting causes by crack flashing custom ROMs over and over on JB 4.2. This is the concept and I'm trying to implement a script to do it.
So I will attempt to replace grep with find and the array with a variable value space separated list and see what I come up with. Becomingx, you are right about wanting to use my brain a bit to figure it out on my own, even if it sends me down a one-way road to a dead end. If I learned something in the process then its all good and I can always ask for directions at the locked gate if I arrive there, but even with 4 flat tires and a broken axle I'm still moving (forward hopefully) as long as there's still road to travel on.
Thks
So you want to write a script to downgrade from 4.2 to 4.1?
Test new avitar
How do you delete a post? Under Edit/Delete I only find Edit??
_that said:
So you want to write a script to downgrade from 4.2 to 4.1?
Click to expand...
Click to collapse
No, I want to write a script that lets you restore a pre 4.2 backup (Nandroid, Titanium, Recovery, ROM) on 4.2 without having to move/copy files.
elfaure said:
No, I want to write a script that lets you restore a pre 4.2 backup (Nandroid, Titanium, Recovery, ROM) on 4.2 without having to move/copy files.
Click to expand...
Click to collapse
Are you sure that this is not already handled by TWRP, or by TB?
Recovery and ROM themselves are not affected by the /0 move in /data anyway.
Thanks becomingx, getting somewhere now but I still have problems.
When I type this at the terminal I get what i am looking for as output
Code:
su
cd /
find */0
Output: (These are test directories I created)
data/0
sdcard/0
sdcard/0/0
But when I run this script, the above output is repeated 3 times? Why is that?? One for each file system /(rootfs), /data, and /sdcard? How can I rewrite the script to produce the same output as from the terminal?
Code:
#!/system/bin/sh
cd /
NEST=$(find */0)
for OBJ in $NEST; do
echo "$NEST"
done
_that said:
Are you sure that this is not already handled by TWRP, or by TB?
Recovery and ROM themselves are not affected by the /0 move in /data anyway.
Click to expand...
Click to collapse
Long story short, yes if you had all the latest and greatest installed before you upgraded to 4.2 then its a transparant issue. But if you're already "nested" because you used an older custom recovery and factory reset a few times to crack flash some some 4.2 ROMs or need to recover to a previous Android version then there is a use for this script. If I can learn how to script variables and help some nested folks out at the same time then _that's what I call a win-win. I'm not on 4.2 nor do I plan on going there anytime soon so this won't help me out less what I learn by doing it, although it is interesting and challenging to try to implement an automated solution for. Plus I'm like you guys, I just really enjoy rooted Android and helping people with it when I can (within my very limited but expanding skill set).
By the way, what is the name and /data path to that special file?
****************************************************************************************************
http://androidforums.com/verizon-ga...t/649940-4-2-sdcard-sdcard-0-observation.html
http://androidforums.com/verizon-ga...y-bean-roms-edited-3-24-13-a.html#post5796630
Quoted from Androidspin.com -
"With Android 4.2, Google introduced multiple users as a new feature. In order to accommodate multiple users, Google is now giving each user a their own folder for storage. If you upgraded to 4.2 from 4.1, then the 4.2 ROM will look for a certain file in /data to determine whether it needs to migrate all of your files to the new multi-user data structure. By default, 4.2 migrates all of /data/media to /data/media/0.
A problem arose though with custom recoveries. A custom recovery retains the /data/media folder during a factory reset. When you factory reset and then boot a 4.2 ROM again, the 4.2 ROM will migrate everything in /data/media again. It will migrate your files every time you factory reset. This multiple migration is what resulted in some people having their files moved to /sdcard/0 or even /sdcard/0/0 etc.
In TWRP 2.3.2.0 we have corrected this problem by ensuring that we do not delete the special file during a factory reset. However, if ended up having your files upgraded you will need to move or merge them back into /sdcard. Also, if you have moved your TWRP folder from /data/media/0 to /data/media so that you could restore backups while using prior TWRP versions, you may now need to move the TWRP folder back into /data/media/0.
As a special note, if you restore a backup to a prior version of Android, you may have to move your files out of /data/media/0 and into /data/media to be able to see them again."
elfaure said:
TBut when I run this script, the above output is repeated 3 times? Why is that?? One for each file system /(rootfs), /data, and /sdcard? How can I write the script to produce the same output as from the terminal?
Code:
#!/system/bin/sh
cd /
NEST=$(find */0)
for OBJ in $NEST; do
echo "$NEST"
done
Click to expand...
Click to collapse
Read your script - for each item in $NEST you output all of $NEST instead of the single item $OBJ.
_that said:
Read your script - for each item in $NEST you output all of $NEST instead of the single item $OBJ.
Click to expand...
Click to collapse
Ah ha. Lost sight of the fact that a multi-object variable really behaves like an array and you can call its objects as independent variables (syntax wise; I thought that was what I was doing with echo $NEST). Variables in a variable. That's why I started with an array. Thanks.
Code:
#!/system/bin/sh
cd /
NEST=$(find */0)
for OBJ in $NEST; do
echo "$OBJ"
done
Output:
data/0
sdcard/0
sdcard/0/0
New Questions:
How can I strip off all the "/0's" from each object variable and store it in a new mutil-variable until there are no more "/0's to strip off and consolidate duplicates? The desired result here would be VAR=$(data, sdcard).
If two or more object variables have the same root directory name, how can I select only the object variable with the most /0's between two variables (sdcard/0 and sdcard/0/0; I would want only the latter) then store those object variable in a new variable including all other object variables? The desired result here would be VAR1=$(data/0, sdcard/0/0)
Code:
#!/system/bin/sh
nests=( grep ! /*/0 )
for NEST in "${nests[@]}"
do
mkdir /Removable/MicroSD/$NEST_bak
cp -r /$NEST /Removable/MicroSD/$NEST_bak
cp -rf /$NEST/0 /$NEST
#[Restore Pre-4.2 backups]
cp /Removable/MicroSD/$NEST_bak/*.* /$NEST
#[Backup in 4.2]
rm -rf /Removable/MicroSD/$NEST_bak
done
becomingx said:
To capture the output of a command into a variable, you need a dollar sign in front of the opening parenthesis, i.e.:
Code:
nests=$(grep ! /*/0)
[snipped]
I, and most other people based on the code I've seen, don't use arrays much in shell scripts. Usually a value separated list is used instead...[snipped]
Click to expand...
Click to collapse
"nests" in my original code here refers to an array not a variable. Assuming that, is the syntax correct (for reference)? I like the multi-item(object) variable value separated list you showed me and _that corrected my use of and will use that instead for this script.
elfaure said:
For these directory pairs I'll call them from the above output, the data that was in /directory in 4.1 is now located and pointed to in /directory/0 in 4.2. I figured if I could find all these pairs, and copy /directory/0 into /directory (after backing up /directory to SD) then 4.1 backups looking for data in /directory could now find their data and targets. Then I could copy the SD backup of /directory into /directory (now overwritten by /directory/0) to merge everything into a single folder. But after thinking about this again, this is incorrect. What I meant to do at this step is copy all /0 subdirectories of a given /directory/0 into that folder [ /directory/0/0 into /directory/0 and directory/0/0/0 into /directory/0 and /directory/0/0/0/0... into /directory/0 ] to combine all these sub-nested directories into a single /0 directory. Deep subnesting causes by crack flashing custom ROMs over and over on JB 4.2. This is the concept and I'm trying to implement a script to do it.
Click to expand...
Click to collapse
Wow! This is very messy, no wonder you're trying to automate the cleanup.
So I will attempt to replace grep with find and the array with a variable value space separated list and see what I come up with. Becomingx, you are right about wanting to use my brain a bit to figure it out on my own, even if it sends me down a one-way road to a dead end. If I learned something in the process then its all good and I can always ask for directions at the locked gate if I arrive there, but even with 4 flat tires and a broken axle I'm still moving (forward hopefully) as long as there's still road to travel on.
Click to expand...
Click to collapse
Love the analogy here :laugh:
elfaure said:
By the way, what is the name and /data path to that special file?
Click to expand...
Click to collapse
Looks to be `/data/.layout_version' [ref].
elfaure said:
Code:
#!/system/bin/sh
cd /
NEST=$(find */0)
for OBJ in $NEST; do
echo "$OBJ"
done
Output:
data/0
sdcard/0
sdcard/0/0
New Questions:
How can I strip off all the "/0's" from each object variable and store it in a new mutil-variable until there are no more "/0's to strip off and consolidate duplicates? The desired result here would be VAR=$(data, sdcard).
Click to expand...
Click to collapse
If we're going full steam ahead with the requirement of Busybox being installed, then this is pretty easy:
Code:
VAR="$(find */0 | sed -e 's!/0!!g' | sort -u)"
Sed is our Stream EDitor. The option `-e' tells sed that what follows is a sed script.
The script itself (s!/0!!g) breaks down like this:
* `s' means we are doing a substitution.
* The exclamation point (!) is just a delimeter; any character can be used. Typically a forward slash (/) is used, but since directory paths have forward slashes in them, we go with something else to make it easier to read. Otherwise we'd have to escape the forward slashes and it would look like this: s/\/0//g
* `/0' is what we are looking to match.
* Another exclamation point (!) indicates we are done with our "search" pattern and next begins our "replace" pattern.
* Since we are just looking to just get rid of all occurences of `/0', our replacement pattern is literally nothing.
* Another exclamation point (!) to indicate the end of the replacement pattern.
* Finally, `g' (for global) tells sed to keep applying the substitution until it no longer matches. This means a path like `/dir/0/0/0' gets each `/0' stripped away one at a time until there are none left.
The last command sorts our listing so that the `-u' (for unique) option can be applied to it, which removes duplicate lines.
If two or more object variables have the same root directory name, how can I select only the object variable with the most /0's between two variables (sdcard/0 and sdcard/0/0; I would want only the latter) then store those object variable in a new variable including all other object variables? The desired result here would be VAR1=$(data/0, sdcard/0/0)
Click to expand...
Click to collapse
The easiest way to do this is just check for the presence of a `0' dir at each level. If one exists then there's another level of nesting below us and we ignore the current level:
Code:
VAR1=""
for i in $(find */0); do
if [ ! -d $i/0 ]; then
VAR1="$VAR1 $i"
fi
done
Wow! Thanks!! But now I'm suffering from cognitive dissonance (dis-sed-ance). I knew it would require either find, grep, awk, or sed but using those commands without having any grip on regex is nearly impossible. Can you point me to a good resource for learning Android regex or is any GNU/Linux resource valid? Is this a good one?
http://www.linux.org/article/view/introduction-to-regular-expressions-within-a-shell
elfaure said:
I'm not on 4.2 nor do I plan on going there anytime soon so this won't help me out less what I learn by doing it
Click to expand...
Click to collapse
So does that mean you don't have any "0" directories in your /sdcard right now, and you are doing all this just for fun?
At least, after reading your additional material, I am now beginning to understand the problem.
However I don't understand how you get any useful output from "find */0" - I get either "No such file or directory", or a listing of thousands of files, depending on where I start this.
elfaure said:
Can you point me to a good resource for learning Android regex or is any GNU/Linux resource valid?
Click to expand...
Click to collapse
The nice thing with regular expressions is that the basics are the same everywhere.
But I don't know if you even need such powerful tools... Correct me if I am wrong, but your script should convert this structure:
/data/media/0
/data/media/0/stuff1
/data/media/0/0
/data/media/0/0/stuff2
/data/media/0/0/0
/data/media/0/0/0/stuff3
to
/data/media/0
/data/media/0/stuff1
/data/media/0/stuff2
/data/media/0/stuff3
?
So you'd basically need to run this inside /data/media/0:
1. If there is no subdirectory named "0", there is nothing to do, and we can exit
2. If there is a subdirectory named "0", move everything from inside one level out
2a. how do you want to handle conflicts, if the file or directory you want to move outside already exists in the parent directory?
3. go to step 1
[Reply to _that's last post. Getting lazy, I'm at lunch...]
Here is my output from
Code:
find */0
[email protected]:/ $ su
[email protected]:/ # find */0
data/0
sdcard/0
sdcard/0/0
[email protected]:/ # exit
[email protected]:/ $ find */0
data/0
find: data/0: Permission denied
sdcard/0
sdcard/0/0
1|[email protected]:/ $
I'm not sure about the structure I am looking for until I get some output from this code run on a 4.2 device with nested /0's so I can see all of them and their variations. I also want to see what happens to subsequent user directories nested starting with /data/media/10 (second user) and /data/media/11 (third user) and how they nest in comparison.
The only /0 directories that I have on my device were created by me to test this script. I am still on 4.1 and this is a 4.2 only issue so as you state its "just for fun" or rather "for the fun of learning" but at least its not a "hello world" script that does nothing useful. I'm hoping to automate someone's cleanup after installing 4.2 with this, maybe my own at some point, if required.
Here's some more info about the issue:
http://teamw.in/DataMedia
ps-I just discovered the equivalent to the stock browser "about:debug" for Chrome is "about:flags" which brings up an extensive list of experimental settings. I enabled all that were GPU and speed related and its a marked improvement (it feels 25-75% faster). With a 100MB Chrome cache I can have about 20 tabs open at the same time now and its still fast and snappy.
Not sure if this will work or not, but if you want to try to retain single user mode in 4.2 you can try this:
http://androidforums.com/verizon-ga...y-bean-roms-edited-3-24-13-a.html#post5806236
If anyone has a copy of the .layout_version file, please post it or a link to it so I can check it out.
Thks
becomingx said:
Wow! This is very messy, no wonder you're trying to automate the cleanup.
Love the analogy here :laugh:
Looks to be `/data/.layout_version' [ref].
If we're going full steam ahead with the requirement of Busybox being installed, then this is pretty easy:
Code:
VAR="$(find */0 | sed -e 's!/0!!g' | sort -u)"
Sed is our Stream EDitor. The option `-e' tells sed that what follows is a sed script.
The script itself (s!/0!!g) breaks down like this:
* `s' means we are doing a substitution.
* The exclamation point (!) is just a delimeter; any character can be used. Typically a forward slash (/) is used, but since directory paths have forward slashes in them, we go with something else to make it easier to read. Otherwise we'd have to escape the forward slashes and it would look like this: s/\/0//g
* `/0' is what we are looking to match.
* Another exclamation point (!) indicates we are done with our "search" pattern and next begins our "replace" pattern.
* Since we are just looking to just get rid of all occurences of `/0', our replacement pattern is literally nothing.
* Another exclamation point (!) to indicate the end of the replacement pattern.
* Finally, `g' (for global) tells sed to keep applying the substitution until it no longer matches. This means a path like `/dir/0/0/0' gets each `/0' stripped away one at a time until there are none left.
The last command sorts our listing so that the `-u' (for unique) option can be applied to it, which removes duplicate lines.
The easiest way to do this is just check for the presence of a `0' dir at each level. If one exists then there's another level of nesting below us and we ignore the current level:
Code:
VAR1=""
for i in $(find */0); do
if [ ! -d $i/0 ]; then
VAR1="$VAR1 $i"
fi
done
Click to expand...
Click to collapse
Thanks again for your help and explanations. I find it amazing what a few (not so) simple lines of code can do with a complex task. Learning regex will take me until next year so for now I will go blindly forward with my plan. The next step would be to use BOTH of these variables in some call statement like [ ] to automate the process of backing up and moving data around. And combining it all into a script here it is below. Is the syntax in the main block I added correct?
Code:
#!/system/bin/sh
VAR="$(find */0 | sed -e 's!/0!!g' | sort -u)"
VAR1=""
for i in $(find */0); do
if [ ! -d $i/0 ]; then
VAR1="$VAR1 $i"
fi
done
for OBJ in $VAR and OBJ1 in $VAR1; do
#Backup $OBJ to SD
mkdir /Removable/MicroSD/$OBJ_BAK
cp -r /$OBJ /Removable/MicroSD/$OBJ_BAK
#Over write $OBJ with $OBJ1
cp -rf /$OBJ1 /$OBJ
#Merge backup and $OBJ
cp /Removable/MicroSD/$OBJ_BAK/*.* /$OBJ
#Remove $OBJ backup
rm -rf /Removable/MicroSD/$OBJ_BAK
done
elfaure said:
Wow! Thanks!! But now I'm suffering from cognitive dissonance (dis-sed-ance). I knew it would require either find, grep, awk, or sed but using those commands without having any grip on regex is nearly impossible. Can you point me to a good resource for learning Android regex or is any GNU/Linux resource valid? Is this a good one?
http://www.linux.org/article/view/introduction-to-regular-expressions-within-a-shell
Click to expand...
Click to collapse
lolz. Any resource on regexes should be applicable, just know that there are some small differences between the three main dialects (basic, extended, and perl). If you've got money to spend, Mastering Regular Expressions is considered *the* book to own on the subject. Also good is this pocket reference for sed and awk, which is a bit cheaper. I've used my copy so much the spine has completely gone out and it's just a collection of loose pages inside the cover now!
---------- Post added at 11:29 AM ---------- Previous post was at 11:00 AM ----------
_that said:
So does that mean you don't have any "0" directories in your /sdcard right now, and you are doing all this just for fun?
At least, after reading your additional material, I am now beginning to understand the problem.
However I don't understand how you get any useful output from "find */0" - I get either "No such file or directory", or a listing of thousands of files, depending on where I start this.
Click to expand...
Click to collapse
This is what I was hinting at back in post #3.
Using `find' like this, the `*/0' will get expanded by the shell if there happens to exist at least one `SOMEDIR/0', which will result in `find' printing out every file/directory/etc. that exists under any and every `SOMEDIR/0'. Otherwise, if none exist, it will get passed to the `find' command as literally `*/0', which is where the "No such file or directory" comes from.
The proper way to do this is using a `find' option like `-name', to limit scope of what gets returned. Again, though, one still has to be careful because we could still get search matches that we don't want. Something like this might be a good starting point:
Code:
find -name '0' -type d
@elfaure: Try populating your self-created `0' directories with some files and directories, the output of `find */0' should become a bit surprising.
But I don't know if you even need such powerful tools... Correct me if I am wrong, but your script should convert this structure:
/data/media/0
/data/media/0/stuff1
/data/media/0/0
/data/media/0/0/stuff2
/data/media/0/0/0
/data/media/0/0/0/stuff3
to
/data/media/0
/data/media/0/stuff1
/data/media/0/stuff2
/data/media/0/stuff3
?
So you'd basically need to run this inside /data/media/0:
1. If there is no subdirectory named "0", there is nothing to do, and we can exit
2. If there is a subdirectory named "0", move everything from inside one level out
2a. how do you want to handle conflicts, if the file or directory you want to move outside already exists in the parent directory?
3. go to step 1
Click to expand...
Click to collapse
Seems simple enough, but need a little time to think about it...
---------- Post added at 11:31 AM ---------- Previous post was at 11:29 AM ----------
elfaure said:
If anyone has a copy of the .layout_version file, please post it or a link to it so I can check it out.
Thks
Click to expand...
Click to collapse
Mine just contains the number "2", nothing else, not even a newline.
---------- Post added at 11:43 AM ---------- Previous post was at 11:31 AM ----------
elfaure said:
Thanks again for your help and explanations. I find it amazing what a few (not so) simple lines of code can do with a complex task. Learning regex will take me until next year so for now I will go blindly forward with my plan. The next step would be to use BOTH of these variables in some call statement like [ ] to automate the process of backing up and moving data around. And combining it all into a script here it is below. Is the syntax in the main block I added correct?
Code:
#!/system/bin/sh
VAR="$(find */0 | sed -e 's!/0!!g' | sort -u)"
VAR1=""
for i in $(find */0); do
if [ ! -d $i/0 ]; then
VAR1="$VAR1 $i"
fi
done
for OBJ in $VAR and OBJ1 in $VAR1; do
#Backup $OBJ to SD
mkdir /Removable/MicroSD/$OBJ_BAK
cp -r /$OBJ /Removable/MicroSD/$OBJ_BAK
#Over write $OBJ with $OBJ1
cp -rf /$OBJ1 /$OBJ
#Merge backup and $OBJ
cp /Removable/MicroSD/$OBJ_BAK/*.* /$OBJ
#Remove $OBJ backup
rm -rf /Removable/MicroSD/$OBJ_BAK
done
Click to expand...
Click to collapse
Negatory, good buddy. Everthing after the `in' keyword till the semicolon gets treated as part of the (one and only) list. This would be a good place for two parallel arrays, but I suspect that might be overkill. Need a little time to think...
P.S. Never go blindly forward when working as user `root'. Much too dangerous.

Duplicate Binaries

I just made an alarming discovery. There are some duplicate binaries installed on our system. rm is one example. I found this out using the rm command. Here is what I found. It exists in BOTH /system/bin AND /system/xbin. If you need proof, I can show you that too.
*********************************************************
Busybox installs its binaries to /system/xbin. Your $PATH is constructed from the /system/etc/mkshrc file that gets executed at boot. The path construct outputs PATH=/system/bin:/system/xbin. Notice that /system/bin comes before /system/xbin in your PATH.
So then the problem with duplicate binaries is that when commands are run from the terminal (without a full path specified to the command call), they are executed from the first directory found in the $PATH which is /system/bin not /system/xbin.
I could do some more **** Tracy and find all the duplicate binaries but I have an easier solution. The solution (for me) is to edit my mkshrc file, and force /system/xbin to come before /system/bin in the $PATH construct. That way I'm not getting jipped with a full Busybox installed by using their less functional Android counterparts. I will post the edited file here in case anyone needs it.
[Edit] On second thought after reviewing some feedback, I will not post this file modification. It has other unintended consequences. Read. Oops, I thought this was posted in the Help & TS section.
elfaure said:
I just made an alarming discovery. There are some duplicate binaries installed on our system. rm is one example. I found this out using the rm command. Here is what I found. It exists in BOTH /system/bin AND /system/xbin.
Click to expand...
Click to collapse
Well, the one in /system/bin is part of stock Android, and the one in xbin is from busybox. No surprise here. In many cases it does not matter which one you actually call, but the versions from busybox are usually more feature-rich. If you need the busybox version, the easiest and safest way to ensure you get the correct one is to explicitly call "busybox rm".
If you modify your PATH, you risk writing scripts that don't work on other devices.
_that said:
If you modify your PATH, you risk writing scripts that don't work on other devices.
Click to expand...
Click to collapse
Please explain.
[Edit] I just discovered other unintended problems with changing my $PATH in mkshrc. Because I have multiple superusers installed [I like to switch between them sometimes; one in /system/bin (active) and the other in /system/xbin (other one)] and by doing that when I rebooted it changed my superuser app. Interesting. So I will not post up the file then - bad idea.
[Edit] It just gets worse. After doing that I now can't sign into my Google account, and I just got a suspicious sign-in email from Google. Really bad idea.
[Edit] Yup. Just verified that my Google account was disabled due to suspicious activity and I had to reset my password. That email was not spam.
elfaure said:
Please explain.
Click to expand...
Click to collapse
I think I get what _that is saying.
For the same reasons that rm was causing some unexpected behavior in your Brower2Ram script, the same thing could happen if a system binary is not as feature-rich as the busybox version. It just so happens for the case of rm that the system binary has more switches than busybox, but who can say for other binaries?
shardsx said:
[Snipped] It just so happens for the case of rm that the system binary has more switches than busybox, but who can say for other binaries?
Click to expand...
Click to collapse
I think you have that backwards. Busybox binary is more feature rich, has more switches, and is the one we want to use. That is why I am suggesting pointing the PATH to busybox (/system/xbin) rather than Android (/system/bin). The one that does NOT have the -f option is the Android one; the default one that gets called from a terminal or my script.
elfaure said:
Please explain.
Click to expand...
Click to collapse
Just think what could happen:
1. You have modified your PATH.
2. You write a script that works on your device.
3. You publish your script.
4. I try running your script and it calls the wrong binary because my PATH is not modified.
elfaure said:
I think you have that backwards. Busybox binary is more feature rich, has more switches, and is the one we want to use. That is why I am suggesting pointing the PATH to busybox (/system/xbin) rather than Android (/system/bin). The one that does NOT have the -f option is the Android one; the default one that gets called from a terminal or my script.
Click to expand...
Click to collapse
Oops, you're right!
_that said:
Just think what could happen:
1. You have modified your PATH.
2. You write a script that works on your device.
3. You publish your script.
4. I try running your script and it calls the wrong binary because my PATH is not modified.
Click to expand...
Click to collapse
Gotcha. This is what I didn't understand @shardsx how modifying my local path in any way could affect anyone else running my script but @_that clearly shows why above. If I can't test it on the user's binary then I'm only testing it for operation on MY device which would be different than YOUR device. So like you said @_that, I need to specifically call the busybox binary for the rm command if I want to use the -f option by either:
1. /system/xbin/rm
or
2. busybox rm
instead of just simply rm (which calls /system/bin/rm). Drama concludes with effective solution.
Find duplicate binaries script
Here is a script to find all the duplicate binaries between /system/bin and /system/xbin. There are quite a few.
[Edit] The attached script was REMOVED because it is WRONG. Once I fix the problems and @_that has approved of the corrections I will post it back up.
elfaure said:
Here is a script to find all the duplicate binaries between /system/bin and /system/xbin.
Click to expand...
Click to collapse
Nice, short and sweet ... and wrong. You should test your scripts before publishing.
Read this: http://en.wikipedia.org/wiki/Test_(Unix) to find how to fix it.
This line is wrong:
Code:
if [ "OBJ"="$XBIN" ]; then
The "[" command (yes, that's a command also called "test") does not understand "=". In this invocation it will simply return true if the string between [ and ] is not empty, which is always. Edit: It does understand " = " though.
Even if test did understand "=" in the normal way of comparing for equality it wouldn't work. First, you forgot the $ before OBJ - you want to compare with the current file name, not with the fixed name "OBJ". Then, if you compare the current $OBJ with the whole list of the files in xbin, it will always be false.
You don't even need the list of all files in xbin - you only need to check for each file in bin if an equally named file in xbin exists. "test" (or "[") has an operator for that.
a working solution:
Code:
for OBJ in $(ls /system/bin)
do
if [ -e /system/xbin/$OBJ ]; then
echo $OBJ
fi
done
_that said:
Nice, short and sweet ... and wrong. You should test your scripts before publishing.
Read this: http://en.wikipedia.org/wiki/Test_(Unix) to find how to fix it.
This line is wrong:
Code:
if [ "OBJ"="$XBIN" ]; then
The "[" command (yes, that's a command also called "test") does not understand "=". In this invocation it will simply return true if the string between [ and ] is not empty, which is always.
Even if test did understand "=" in the normal way of comparing for equality it wouldn't work. First, you forgot the $ before OBJ - you want to compare with the current file name, not with the fixed name "OBJ". Then, if you compare the current $OBJ with the whole list of the files in xbin, it will always be false.
You don't even need the list of all files in xbin - you only need to check for each file in bin if an equally named file in xbin exists. "test" (or "[") has an operator for that.
a working solution:
Code:
for OBJ in $(ls /system/bin)
do
if [ -e /system/xbin/$OBJ ]; then
echo $OBJ
fi
done
Click to expand...
Click to collapse
Ouch! Busy at day job now but I felt that slap all the way from the E. Coast. Is _that called SIP - slap over IP?.
Agreed, I'm still too much of a newb to be QCing my own work. Won't publish anything else without your approval. I will investigate and fix it but it seemed to work when I ran it. Maybe it just listed all the contents of /system/bin?
[Edit] I just wanted to say until I look this over that I did run it and the output looked reasonable for matching binaries. I did not check more than a few.
Note: I have not opened your solution because I am not yet convinced I need to or this structure is wrong. But historically speaking you've never been wrong so I expect to be wrong and learn something from this, but for now I just don't see your point, I believe these work, so I will hold my ground.
Here is a simple test example with identical structure. I see no difference (besides forgetting the $). Comment?
Code:
#!/bin/sh
string1="blah"
string2="blah"
if [ $string1=$string2 ]; then
echo "$string1 $string2"
fi
and here is the code block from my sniper method script after which you called for a cleanup. This code compared a single variable (like $OBJ) to a list variable (like $XBIN).
Code:
If [ -d "${CACHE_NAME1}"=${BROWSER_LIST} ];
then...
[Edit] I put the $ infront of OBJ and re-ran my script and it produces identical output as without it. So every file in /system/bin is getting echoed and the script does not work you are (always) correct. But the test example script I provided does work. Hmm...thats a single variable not a list. But my sniper method worked. Hmm...hmm...
Nor did this make any difference
Code:
if [ "${OBJ}"="${XBIN}" ]; then
Conclusion: My sniper method never worked as intended. It just mounted all of the browser list without ever making the match to all /cache dirs. But it seemed to work as intended. Again, I state that it is difficult to impossible to know when you are doing something wrong in the code when you get your desired output thru a flawed code block which further substantiates your point about needing review. Because then we convince ourselves something worked and try to use the same method again and again only later to find out the method is flawed.
I'm going to follow your links and read up a bit before I take the bait and peek at your solution.
elfaure said:
Here is a simple test example with identical structure. I see no difference (besides forgetting the $). Comment?
Code:
#!/bin/sh
string1="blah"
string2="blah"
if [ $string1=$string2 ]; then
echo "$string1 $string2"
fi
Click to expand...
Click to collapse
Try these variants and observe the result:
Code:
if [ a=a ]; then echo yes; fi
if [ a=b ]; then echo yes; fi
if [ a ]; then echo yes; fi
if [ ]; then echo yes; fi
(I actually did the same to find out what's going on)
elfaure said:
The one that does NOT have the -f option is the Android one; the default one that gets called from a terminal or my script.
Click to expand...
Click to collapse
This seems to have changed between 10.4.4.25 and 10.6.1.14.4 (below, respectively):
Code:
rm [-rR] <target>
Code:
Usage: rm [-rR] [-f] <target>
Welcome to the world of code portability.
---------- Post added at 07:01 AM ---------- Previous post was at 06:48 AM ----------
elfaure said:
Here is a simple test example with identical structure. I see no difference (besides forgetting the $). Comment?
Code:
#!/bin/sh
string1="blah"
string2="blah"
if [ $string1=$string2 ]; then
echo "$string1 $string2"
fi
Click to expand...
Click to collapse
1. You need a space between the comparison operator and the variable names for this to work like you expect.
2. Get into the habit of always quoting variable names when performing such tests (i.e. if [ "$string1" = "$string2" ]; then). Not doing so may bite you when you're not expecting it.
becomingx said:
1. You need a space between the comparison operator and the variable names for this to work like you expect.
2. Get into the habit of always quoting variable names when performing such tests (i.e. if [ "$string1" = "$string2" ]; then). Not doing so may bite you when you're not expecting it.
Click to expand...
Click to collapse
1. I started out with these spaces and tested the script with and without the spaces and it did not make any difference (output was the same) so I removed them thinking they weren't needed. But I did question this. I observed other examples that had this space and was wondering why they were there. Also the spaces between the [ ] and the arguements are required. I did actually know that [=test was a command (from prior readings).
2. Why is this important for variables with no special characters? I thought that was only a grouping thing for variables like "${OBJ}_Cache"
[Edit] Wiki: The quotation marks around $1 ensure that the test works properly even if the value of $1 is a null string. If the quotation marks are omitted and $1 is the empty string, the test command displays the error message "test: argument expected"
_that said:
Try these variants and observe the result:
Code:
if [ a=a ]; then echo yes; fi
if [ a=b ]; then echo yes; fi
if [ a ]; then echo yes; fi
if [ ]; then echo yes; fi
(I actually did the same to find out what's going on)
Click to expand...
Click to collapse
But you may need the spaces around the "=" and quotes around the variables that @becomingx points out for accurate results. As the variable names become more complex this may fail.
Code:
if [ "a" = "b" ]; then echo yes; fi
elfaure said:
2. Why is this important for variables with no special characters? I thought that was only a grouping thing for variables like "${OBJ}_Cache"
[Edit] Wiki: The quotation marks around $1 ensure that the test works properly even if the value of $1 is a null string. If the quotation marks are omitted and $1 is the empty string, the test command displays the error message "test: argument expected"
Click to expand...
Click to collapse
Not only for that reason, but also for things like spaces.
Code:
THIS="and that"
if [ $THIS == "and that" ]; then
...
fi
== `[: too many arguments'
becomingx said:
Not only for that reason, but also for things like spaces.
Code:
THIS="and that"
if [ $THIS == "and that" ]; then
...
fi
== `[: too many arguments'
Click to expand...
Click to collapse
So I followed @_that's link to the Wiki for [=test, and there is absolutely no discussion at all about using "=" or "==" for testing comparisons between variables, only strings. Why?? These examples and your Firefox code for B2R script use the equal operator for comparison and that is what i am trying to do here but I can't yet make it work.
I have failed to figure this out. Here is my test code citing due dilligence. I will now peek at @_that 's solution.
Code:
#!/system/bin/sh
#This script finds duplicate binaries in /system/bin and /system/xbin and prints them to the screen
BIN="$(ls /system/bin)"
#XBIN="$(ls /system/xbin)"
XBIN="$(find /system/xbin -iname "{$OBJ}")"
for OBJ in $BIN
do
#if [ "${OBJ}" = "${XBIN}" ]; then
#if [ "${OBJ}" ] && [ "${XBIN}" ]; then
if [ "${OBJ}" == "$XBIN" ]; then
echo $OBJ
fi
done
I have failed to figure this out. Here is my test code citing due dilligence. I will now peek at @_that 's solution.
[Edit] Short, sweet, simple, works, brilliant. What cereal do you eat in the morning @_that? I think I need to change mine.
Question: Is there any way to make this work with my original structure??? I need a comprehensive method for test matching a string variable to a list variable AND a list variable to another list variable. I would think the latter could be reduced to the former thru the use of a for-do loop "for OBJ in $LIST_VARIABLE1 do ...something to...$LIST_VARIABLE2".
Code:
#!/system/bin/sh
#This script finds duplicate binaries in /system/bin and /system/xbin and prints them to the screen
BIN="$(ls /system/bin)"
#XBIN="$(ls /system/xbin)"
XBIN="$(find /system/xbin -iname "{$OBJ}")"
for OBJ in $BIN
do
#if [ "${OBJ}" = "${XBIN}" ]; then
#if [ "${OBJ}" ] && [ "${XBIN}" ]; then
if [ "${OBJ}" == "$XBIN" ]; then
echo $OBJ
fi
done

[guide] Hacking the startup sequence to run your own code

I have been trying to customise my MTK phones with a pre-defined user experience, with sepcific settings etc.
Perhaps one way to achieve this is to check if the device has been facory reset, then use a script to insert specific settings once. For this I need to launch a script early in the boot sequence.
This could be achieved by dismantling the boot.img, altering the init.rc, then re-building, which requires significant work and risks bricking the device. So I looked for a way to run a script without significant re-flashing. here goes:
xlog changes the system log level, and is called just a few times at boot-up. Xlog is run early, and as root, with the parameter boot.
This script renames xlog as xlogboot, introduces a script in place of xlog, which runs another script, startup.sh when xlog is called with parameter boot. All the original parameters are passed to the renamed xlog binary, so the system functionality should not be changed.
I pushed the script to the device, then run it as root. I can now edit /system/bin/startup.sh to run whatever initialisation commands I wish. I have so far tested on a ZTE v965 .
Code:
#!/system/bin/sh
#This script creates a hook into the bootup system of Android
#This hook operates when /system/bin/xlog is called with
#the first parameter 'boot'
#Use this script entirely at your own risk. I highly recommend
#you ensure YOU have a backup of YOUR device before going further
#Public Domain Nick Hill 2014
if [ -e /system/bin/xlogboot ] || [ -e /system/bin/startup.sh ]; then
echo "This script may have already been run, exiting.."
exit 1
fi
if [ ! -e /system/bin/xlog ]
then
echo "This script is not running in an expected environment. Exiting.."
exit 2
fi
if [ $USER != "root" ]
then
echo "This script must be run as root. try running su. Exiting.."
exit 3
fi
touch /system/bin/atestfile
if [ ! -e /system/bin/atestfile ]
then
echo "It appears system folder is not mounted read-write. Remounting..."
mount -o remount,rw /system
else
rm /system/bin/atestfile
fi
echo -e '#!/system/bin/sh\n' > /system/bin/startup.sh
chown root:root /system/bin/startup.sh
chmod 755 /system/bin/startup.sh
mv /system/bin/xlog /system/bin/xlogboot
echo -e '#!/system/bin/sh\n/system/bin/xlogboot $*\nif [ "$1" == "boot" ] \nthen\n/system/bin/startup.sh\nfi\n' >/system/bin/xlog
chown root:shell /system/bin/xlog
chmod 755 /system/bin/xlog
Enjoy!
Make your own custom rom
Problem: You have an android device which you want to give/sell in USA or England. The device has come with an array of auto-starting chinese pop-ups, horrible wallpaper, and a Chinese clock applet. You uninstall all those system apps, replace your widgets with nice English ones. The phone when factory reset, starts in Chinese. Returns the user to tacky wallpaper, and you have lost the nice theming and widgets you have painstakingly installed and set up in the system folder.
Solution: This backup script. I have tested it on a v965, it also appears the file system would be OK on an A766 and many other android devices.
Instructions:
Use my previous script on this thread to create a hacked startup sequence. You must already have the /system/bin/startup.sh in place.
Unpack the tarball
Check the script lists the files you intend to back up. You will need to edit the script for that. I have set it to preserve settings for language, launcher, the 3D clock app factory.widgets.ThreeDDigitalWeatherClock-1.apk , which I think is really cool, wallpaper and the ADB mode.
Copy the install.sh and busybox to a writable directory on your android device.
su (go to root)
In a shell, cd to the directory where you uploaded the files.
sh install.sh
This will create a directory /system/perm-config
When you have the device as you would like it,
cd /system/perm-config
./make-backup.sh
This will ceate a directory tree in /system/perm-config/data folder, containing the backups of specific app data.
If all goes well, next time the phone is factory reset, the defaults are reloaded.
You could then re-flash the system partition of devices, perform a factory reset to take the device to your own defaults. You can use the last script (to hack the startup sequence), and this script to make your own custom ROMs. The script should do it's job even after un-rooting a device.
As usual, use at your own risk. I take no responsibility if your phone bricks, explodes, turns to antimatter, suddenly drops into a parallel dimension or starts receiving calls from the future.

Categories

Resources