[DEV][SCRIPT] First-Boot App Install - Epic 4G Android Development

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.

Related

Possible [How To] Moving all caches to SD?

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/.

[CUSTOM RECOVERY] Integrate GoogleApps into ROM's w/o Google Experience/AOSP =)

Soo,
I want to start a project to make a script which includes the Market in a "bare bone" ROM.
The goal is to have cyanogen to make ROM's without Google Experience and let the user run a script to reinclude the Market.
I have an idea how:
The user has to download a file from the HTC Website: The ADP1 Systemimage.
He places it into a folder in which is a script which unyaffs the image, copys the necesarry files and makes an update.zip out of it which can be flashed over the "bare bone-rom".
I don't know if this legal or not, but Google won't attack the end-user, but the one who provides software illegal.
But HTC has a license, so there shouldn't be a problem.
The end-user does something illegal I think, but he won't get into any trouble with google.
The hardest part is to find the necesarry files.
I diffed the folders of a market and non-market ROM and filtered out some unneeded parts.
Here's the list of which files to copy.
# Apps
cp system/app/BugReport.apk gfiles/app/BugReport.apk
cp system/app/checkin.apk gfiles/app/checkin.apk
cp system/app/Gmail.apk gfiles/app/Gmail.apk
cp system/app/GmailProvider.apk gfiles/app/GmailProvider.apk
cp system/app/GoogleApps.apk gfiles/app/GoogleApps.apk
cp system/app/GoogleContactsProvider.apk gfiles/app/GoogleContactsProvider.apk
cp system/app/GooglePartnerSetup.apk gfiles/app/GooglePartnerSetup.apk
cp system/app/GoogleSettingsProvider.apk gfiles/app/GoogleSettingsProvider.apk
cp system/app/GoogleSubscribedFeedsProvider.apk gfiles/app/xx.apk
cp system/app/GoogleSubscribedFeedsProvider.apk gfiles/app/GoogleSubscribedFeedsProvider.apk
cp system/app/gtalkservice.apk gfiles/app/gtalkservice.apk
cp system/app/ImProvider.apk gfiles/app/ImProvider.apk
cp system/app/MediaUploader.apk gfiles/app/MediaUploader.apk
cp system/app/NetworkLocation.apk gfiles/app/NetworkLocation.apk
cp system/app/SetupWizard.apk gfiles/app/SetupWizard.apk
cp system/app/Street.apk gfiles/app/Street.apk
cp system/app/Talk.apk gfiles/app/Talk.apk
cp system/app/Vending.apk gfiles/app/Vending.apk
cp system/app/VoiceDialer.apk gfiles/app/VoiceDialer.apk
cp system/app/VoiceSearch.apk gfiles/app/VoiceSearch.apk
cp system/app/YouTube.apk gfiles/app/YouTube.apk
# Framework
cp system/framework/com.google.android.gtalkservice.jar gfiles/framework/com.google.android.gtalkservice.jar
cp system/framework/com.google.android.maps.jar gfiles/framework/com.google.android.maps.jar
# Permissions
cp system/etc/permissions/com.google.android.gtalkservice.xml gfiles/etc/permissions/com.google.android.gtalkservice.xml
cp system/etc/permissions/com.google.android.maps.xml gfiles/etc/permissions/com.google.android.maps.xml
Click to expand...
Click to collapse
PLEASE ONLY DEV-TALK!
LINUX
The script for linuxusers is ready. It's attached.
Usage:
Go to the folder
chmod +x extract
./extract
You will need your device connected with a ROM without Google Apps, but root, and you'll need the drivers (usb rules) if it doesn't work from the start.
IT WILL TELL YOU TO DOWNLOAD A FILE, YOU HAVE TO GOOGLE FOR IT!
CUSTOM RECOVERY
Usage:
Place "signed-dream_devphone_userdebug-img-150275.zip" on your sdcard.
Boot into this recovery, adb into the device and run:
sh /sbin/gapps
It will do ALL automatically!
I hope I can later include it in the menu =)
Download: http://www.4shared.com/file/135537189/25541756/recoverynewimg.html
It's based on Amom_RA's great recovery!
Improved list for the backup and restore after flash or leave untouched strategies:
GOOGLE AND HTC STUFF (?)
/system/app/BugReport.apk
/system/app/checkin.apk
/system/app/Clicker.apk
/system/app/Gmail.apk
(easy to substitute with other mail client):
pop.gmail.com port 995 with SSL
smtp.gmail.com port 465 with SSL)
/system/app/GmailProvider.apk
/system/app/GoogleApps.apk
android/cupcake/packages/providers/GoogleContactsProvider is open source
/system/app/GoogleContactsProvider.apk
/system/app/GooglePartnerSetup.apk
/system/app/GoogleSettingsProvider.apk
android/cupcake/packages/providers/GoogleSubscribedFeedsProvider is open source
/system/app/GoogleSubscribedFeedsProvider.apk
/system/app/gtalkservice.apk
android/cupcake/packages/providers/ImProvider is open source
/system/app/ImProvider.apk
/system/app/MediaUploader.apk
/system/app/NetworkLocation.apk
/system/app/SetupWizard.apk
android/cupcake/packages/apps/Stk/src/com/android/stk is open source
/system/app/Stk.apk
/system/app/Street.apk
/system/app/Talk.apk
/system/app/TmoImPlugin.apk
/system/app/Vending.apk
android/cupcake/packages/apps/VoiceDialer is open source
/system/app/VoiceDialer.apk
/system/app/VoiceSearch.apk
/system/app/YouTube.apk
/system/etc/permissions/com.google.android.gtalkservice.xml
/system/etc/permissions/com.google.android.maps.xml
/system/framework/com.google.android.gtalkservice.jar
/system/framework/com.google.android.maps.jar
/system/framework/com.htc.framework.jar
/system/framework/com.htc.resources.apk
/system/lib/libcerttool_jni.so
Other closed source(?) files:
/system/bin/akmd
(/system/etc/AudioFilter.csv)
(/system/etc/AudioPara4.csv)
(/system/etc/AudioPreProcess.csv)
/system/etc/firmware/brf6300.bin
(/system/etc/gps.conf)
/system/etc/wifi/Fw1251r1c.bin
(/system/etc/wifi/tiwlan.ini)
/system/lib/libaudioeq.so
/system/lib/libgps.so
/system/lib/libhgl.so
/system/lib/libhtc_acoustic.so
/system/lib/libhtc_ril.so
/system/lib/libjni_pinyinime.so
/system/lib/libmm-adspsvc.so
/system/lib/libOmxCore.so
/system/lib/libOmxH264Dec.so
/system/lib/libOmxMpeg4Dec.so
/system/lib/libOmxVidEnc.so
/system/lib/libopencorehw.so
/system/lib/libpvasf.so
/system/lib/libpvasfreg.so
/system/lib/libqcamera.so
/system/lib/libspeech.so
/system/lib/hw/lights.goldfish.so
/system/lib/hw/lights.msm7k.so
/system/lib/hw/sensors.trout.so
WAREZ (?)
/system/app/HTC_IME.apk
/system/lib/libt9.so
/system/app/ PDFViewer.apk
/system/lib/libpdfreader.so
/data/app/Quickoffice_HTC_1.0.1.apk
/data/app/teeter.apk
also posted here http://forum.xda-developers.com/showthread.php?t=564303&page=6
Were gonna need Stk.apk it's for the sim card without that it's impossible to make calls.
And vending.apk is for Market and without that it is impossible to download the majority of apps.
I would suggest a different strategy that is even easier. Every user has this
files already on his rom, most (all?) of them are 1.5 based. So before
updating the phone with a cooked rom you have only to backup (tar)
the not redistributable files to the sdcard. After having flashed the coocked rom
you just need to untar them to the flash memory.
Z҉A҉L҉G҉O̚̕̚ said:
Were gonna need Stk.apk it's for the sim card without that it's impossible to make calls.
And vending.apk is for Market and without that it is impossible to download the majority of apps.
Click to expand...
Click to collapse
Stk.apk is for the Sim menu. You can make calls even if you delete it from your rom
farmatito said:
I would suggest a different strategy that is even easier. Every user has this
files already on his rom, most (all?) of them are 1.5 based. So before
updating the phone with a cooked rom you have only to backup (tar)
the not redistributable files to the sdcard. After having flashed the coocked rom
you just need to untar them to the flash memory.
Click to expand...
Click to collapse
The problem with that is that the apk's have odexes and resource id's that must match the build number to actually work even Cyanogen said that.
And regarding the keep-proprietary-apps-on-device-for-custom-rom install, with all the odexing and resource id mismatches... Ugh.
Click to expand...
Click to collapse
I'm building the AOSP android-1.5_r3 now and will load it onto my device and will try to push the files to it.
Please wait for the results.
If I have success, I'll start making a script which automates the process.
maxisma said:
I'm building the AOSP android-1.5_r3 now and will load it onto my device and will try to push the files to it.
Please wait for the results.
If I have success, I'll start making a script which automates the process.
Click to expand...
Click to collapse
Good luck and good speed.
Z҉A҉L҉G҉O̚̕̚ said:
The problem with that is that the apk's have odexes and resource id's that must match the build number to actually work even Cyanogen said that.
Click to expand...
Click to collapse
If i recall correctly JF made a tool to convert odex files to dex files which could then be repacked in the apk. Don't know if this could be run on the phone tough.
SUCCESS! I found the needed files, got market working on AOSP!
It's the list above (first post).
I'm writing a script now ;-)
Edit:
Script for Linux users is done, testing it now and looking for bugs, will then make a windows-one.
Ok, script is in the first post.
Couldn't this script run from within a recovery image with little if no changes?
i.e. consider this install procedure for a new ROM
1) push update.zip for new ROM to SD card
2) push signed-dream_devphone_userdebug-img-150275.zip to SD (I suspect most people would just have it milling about their SD card in the end!)
3) wipe
4) apply update.zip
5) run (obviously slightly modded) script in recovery before rebooting and running ROM for first time
There'd need to be some kind of unzip capacity within the recovery image, otherwise, there doesn't seem to be anything you're doing in your script that couldn't be done on the handset itself.
Loccy said:
Couldn't this script run from within a recovery image with little if no changes?
i.e. consider this install procedure for a new ROM
1) push update.zip for new ROM to SD card
2) push signed-dream_devphone_userdebug-img-150275.zip to SD (I suspect most people would just have it milling about their SD card in the end!)
3) wipe
4) apply update.zip
5) run (obviously slightly modded) script in recovery before rebooting and running ROM for first time
There'd need to be some kind of unzip capacity within the recovery image, otherwise, there doesn't seem to be anything you're doing in your script that couldn't be done on the handset itself.
Click to expand...
Click to collapse
Yeah, you're right!
But the unzip process would last much longer on this little, little handset.
But ok i'll make a script
EDIT:
Have written a script, untested.
# Mounting
mount sdcard
mount system
# Chmod the files
chmod +x sbin/unyaffs
# Unzip Image
mkdir /sdcard/system
mv /sdcard/signed-dream_devphone_userdebug-img-150275.zip /sdcard/system/signed-dream_devphone_userdebug-img-150275.zip
unzip /sdcard/system/signed-dream_devphone_userdebug-img-150275.zip
# Remove not needed files, move & unyaffs the system
cd /sdcard/system
rm boot.img
rm recovery.img
rm userdata.img
rm android-info.txt
./sbin/unyaffs /sdcard/system/system.img
rm system.img
# Copy the needed files & create folders
cd /sdcard
mkdir gfiles
mkdir gfiles/app
mkdir gfiles/etc
mkdir gfiles/etc/permissions
mkdir gfiles/framework
# Apps
cp system/app/BugReport.apk gfiles/app/BugReport.apk
cp system/app/checkin.apk gfiles/app/checkin.apk
cp system/app/Gmail.apk gfiles/app/Gmail.apk
cp system/app/GmailProvider.apk gfiles/app/GmailProvider.apk
cp system/app/GoogleApps.apk gfiles/app/GoogleApps.apk
cp system/app/GoogleContactsProvider.apk gfiles/app/GoogleContactsProvider.apk
cp system/app/GooglePartnerSetup.apk gfiles/app/GooglePartnerSetup.apk
cp system/app/GoogleSettingsProvider.apk gfiles/app/GoogleSettingsProvider.apk
cp system/app/GoogleSubscribedFeedsProvider.apk gfiles/app/GoogleSubscribedFeedsProvider.apk
cp system/app/gtalkservice.apk gfiles/app/gtalkservice.apk
cp system/app/ImProvider.apk gfiles/app/ImProvider.apk
cp system/app/MediaUploader.apk gfiles/app/MediaUploader.apk
cp system/app/NetworkLocation.apk gfiles/app/NetworkLocation.apk
cp system/app/SetupWizard.apk gfiles/app/SetupWizard.apk
cp system/app/Street.apk gfiles/app/Street.apk
cp system/app/Talk.apk gfiles/app/Talk.apk
cp system/app/Vending.apk gfiles/app/Vending.apk
cp system/app/VoiceDialer.apk gfiles/app/VoiceDialer.apk
cp system/app/VoiceSearch.apk gfiles/app/VoiceSearch.apk
cp system/app/YouTube.apk gfiles/app/YouTube.apk
# Framework
cp system/framework/com.google.android.gtalkservice.jar gfiles/framework/com.google.android.gtalkservice.jar
cp system/framework/com.google.android.maps.jar gfiles/framework/com.google.android.maps.jar
# Permissions
cp system/etc/permissions/com.google.android.gtalkservice.xml gfiles/etc/permissions/com.google.android.gtalkservice.xml
cp system/etc/permissions/com.google.android.maps.xml gfiles/etc/permissions/com.google.android.maps.xml
# Put back the ADPimg
mv /sdcard/system/signed-dream_devphone_userdebug-img-150275.zip /sdcard/signed-dream_devphone_userdebug-img-150275.zip
#Push the files to the device & reboot it
cp -r /sdcard/system/* /system/
echo "Please reboot!"
Click to expand...
Click to collapse
Code:
cp system/app/GoogleSubscribedFeedsProvider.apk gfiles/app/xx.apk
cp system/app/GoogleSubscribedFeedsProvider.apk gfiles/app/GoogleSubscribedFeedsProvider.apk
Think there is typo error in the first line.
Could be a good thing to set explicitely the permissions and ownership of the files.
I think the last line should be
Code:
cp -r /gfiles/* /system/
rt ?
Yap, there is 1 line too much @farmatito, thanks, will fix that!
@sureshg:
I rewrite the script for the recovery.. thanks!
Another possible way to do this is to make a script that makes an update.zip file from HTC's yaffs file.
It would only consists of the apk's and libraries we need to modify (market, IM, Maps, whatever) which would make flashing it faster on the device. And it would also be flashable with Cyanogen's bootloader after we flash an AOSP build since we can flash any .zip file with it.
However, I would like to be able to back up the new market and all associated libraries before trying it in case I wanna switch back
@ maxisma: Thanks for taking this in a positive direction. I was thinking along the same lines, and just posted the below to another thread before I saw this thread:
It looks to me as though Google is bluffing. Here is copyright law that, IMHO, gives every user the right to make and use a backup: COPYRIGHT LAW Just because Google say something, doesn't mean it is true.
I believe the solution to this whole mess is very simple. Here is the roadmap:
1) Cyanogen makes a list of all the closed source apps that need to be left out of the ROM.
2) Some kind person(s) write an app that the user can run to backup the list of files, signs and zips it so that it can be flashed later. Let's call that app "GoogleBack," and make it freely available here (and on the Market?).
3) Cyanogen produces each new ROM without the proprietary files that are on the backup list.
4) User runs "GoogleBack" one time and resulting googleback.zip is stored on /sdcard (root directory).
5) User installs new CM update.zip from Recovery as usual.
6) User also flashes googleback.zip while still in Recovery.
7) User reboots as usual, and now has a new ROM, complete with Google's precious proprietary apps.
8) Everybody goes home happy.
Alternatively, Cyanogen could add a step to the reboot process (home+back) that runs a script to copy the backup files from the backup file (and maybe also run fix_permissions if necessary). This would make that first reboot a longer process, but it would get the job done.
We need to get busy on a solution. This whole issue is just a speed-bump on the Android highway.
I think you are absolutely on the right track. Keep up the good work. Thanks also to everyone else who is making this happen.
use of deviceinstalled official rom
Hi,
why not use the already installed software on the user device. The update.zip of the custom rom could rely on the vanilla stock firmware and do all the needed patching and homebrew additions on base of the stock rom during first boot. So enduser has to flash an official rom first, unit is in an well known state and the dev update.zip just does the conversion to the custom rom during first boot.
I think the end user may not be allowed to run these modification software but he won't be punished. Don't know if it is legal to redistribute a rom which does the patching but that would be the same problem of redistributing software which does a merge of two roms on the enduser side.
Greetings Lopiuh
stellarman said:
@ maxisma: Thanks for taking this in a positive direction. I was thinking along the same lines, and just posted the below to another thread before I saw this thread:
It looks to me as though Google is bluffing. Here is copyright law that, IMHO, gives every user the right to make and use a backup: COPYRIGHT LAW Just because Google say something, doesn't mean it is true.
I believe the solution to this whole mess is very simple. Here is the roadmap:
1) Cyanogen makes a list of all the closed source apps that need to be left out of the ROM.
2) Some kind person(s) write an app that the user can run to backup the list of files, signs and zips it so that it can be flashed later. Let's call that app "GoogleBack," and make it freely available here (and on the Market?).
3) Cyanogen produces each new ROM without the proprietary files that are on the backup list.
4) User runs "GoogleBack" one time and resulting googleback.zip is stored on /sdcard (root directory).
5) User installs new CM update.zip from Recovery as usual.
6) User also flashes googleback.zip while still in Recovery.
7) User reboots as usual, and now has a new ROM, complete with Google's precious proprietary apps.
8) Everybody goes home happy.
Alternatively, Cyanogen could add a step to the reboot process (home+back) that runs a script to copy the backup files from the backup file (and maybe also run fix_permissions if necessary). This would make that first reboot a longer process, but it would get the job done.
We need to get busy on a solution. This whole issue is just a speed-bump on the Android highway.
I think you are absolutely on the right track. Keep up the good work. Thanks also to everyone else who is making this happen.
Click to expand...
Click to collapse
This is almost exactly what I was talking about (except I was thinking that the "GoogleBack" zip should be made on a computer since it would be faster to make) and that we could use HTC's official provided yaffs image (because they are licensed to distribute it) instead of the ones from an existing phone.

[HOW-TO] ROM-HACKING: init.rc ext2-auto-mount / ROM Signing / ROM Kitchen

AS MENTIONED IN THE INTRODUCTION TEXT THIS HAS ONLY BEEN TESTED ON AMON RA ROM 1.6.2 BUT SHOULD REALLY WORK ON ANY ROM THAT HAS NO EXT2 AUTO-MOUNT. AND YEAH THIS WHOLE PROCESS HAS BEEN DONE ON A 32a BOARD. FOR THOSE THAT TRY THIS ON OTHER ROMS LET ME KNOW HOW IT GOES.
I've searched and shuffled through the entire forum and made inquiries to ROM authors without much light being shed on this issue. I doubt I am the only one who has been looking for a way of doing this so I decided to do a small HOW-TO. Here I will explain step by step as to how you can implement a script to be part of your ROM that will auto mount an ext2 partition on boot up if such partition is present. I have included all the tools I've used in order to pull this off, and as the title suggests this has only been done on Amon Ra's latest 1.6.2 ROM. In order to follow these instructions you are expected to allready have set up an adb enviroment on your linux box and for the signing process to work you must have sun-java present, the gnu java wont work. And of course a microSD card with an ext2 partition
1. Download install.sh to your home directory
Code:
wget http://www.grindhouse.no/androidtools/install.sh
chmod a+x install.sh
2. Now execute the install.sh script which will create a directory to work in and download a tool and script package and unpack it.
Code:
./install.sh
When the install.sh script is done you need to move the mkbootimg preferebly to your tools directory of your SDK.
Code:
mv toolstomove/mkbootimg <path/to/sdk/tools/mkbootimg>
3. Unpack the RA1.6.2 ROM into a directory in your home dir. In this HOW-TO we will use directory name "ra1.6.2" as an example through out the entire process.
4. Copy the boot.img from ra1.6.2 to the ROM-cooker dir
Code:
cp $HOME/ra1.6.2/boot.img $HOME/ROM-cooker/boot.img
cd $HOME/ROM-cooker
5. Use unpack.pl to extract the ramdisk from the boot image. I've modified the script a little so it automates the entire process and decompresses the ramdisk to a directory
Code:
./unpack boot.img
6. Now you can either replace the init.rc file here with the one I've included in this package or you can add these lines by yourself. In wich case do the following
Code:
cd boot.img-ramdisk
pico init.rc
Press CTRL+w and then CTRL+t and input 27. hit enter. This will take you to line 27 of init.rc so you can add a line right before the init process remounts the rootfs in read-only mode. Add following line:
Code:
mkdir /sdext2 0771 system system
Now scroll down to the end of the init.rc file and add the following:
Code:
service mountsdext2 /system/bin/mountsd
user root
group root
oneshot
7. You have now edited (or replaced) your init.rc file and prepared it to execute a script on boot that will detect an ext2 partition and boot it if there is one to be found. Now you have to make the mountsd script a part of the ROM. Do the following:
Code:
cd $HOME/ROM-cooker
mv toolstomove/mountsd $HOME/ra1.6.2/system/bin/mountsd
rm -rf toolstomove
8. Now that the init.rc file is sorted out and mountsd has been placed in /system/bin of the ROM so it is time to re-pack the boot.img:
Code:
cd $HOME/ROM-cooker
./repack boot.img-kernel boot.img-ramdisk boot.img
rm $HOME/ra1.6.2/boot.img
mv boot.img $HOME/ra1.6.2/boot.img
9. Your ROM now has a new boot image with an updated init.rc and the /system/bin dir has the script needed to auto-mount the microsd ext2. Now you must re-zip the ROM and sign it. Do the following:
Code:
cd $HOME/ra1.6.2
zip -r update.zip *
mv update.zip $HOME/ROM-cooker/update.zip
cd $HOME/ROM-cooker
./sign.pl update.zip
10. The ROM is now signed and you now have a file called update-signed.zip. Connect the phone to your computer and execute thus:
Code:
./push update-signed.zip
11. Now you are ready to flash the modified ROM which will auto-mount an ext2 partition on your microSD. There is no need to wipe before flashing. If you have no prior experience with ROM flashing or whatever just backup your current install. If you're using OpenHOME or anything similar, nothing will be changed or damaged but if you're using MontAlbert's themes with the ROM you will have to flash them again after flashing this modified ROM.
Code:
adb reboot recovery
12. Flash from choose zip and of course choose update-signed.zip. Reboot. After the system boots up again you can now check whats what with either one of the commands:
Code:
[email protected]:~$ adb shell mount | grep sdext2
/dev/block/mmcblk0p2 on /sdext2 type ext2 (rw,noatime,nodiratime,errors=continue)
[email protected]:~/boot$ adb shell busybox df -h | grep sdext2
/dev/block/mmcblk0p2 893.7M 13.0K 846.0M 0% /sdext2
13. Voila! Your RA 1.6.2 ROM now detects and mounts your microSD ext2 partition on boot. Woohoo?
I hope the HOW-TO was easy reading and that you have succeeded in hacking up your ROM. I know that certain ROMs have this as a built-in function but Amon Ra's does not. But since alot of people including myself use his ROM because of the high speed and stability I thought I should contribute to his project and add a cool (and missed?) function to it.
Mind you that you can use the ROM-cooker set to further adjust and hack up the ROM as you see fit. Happy learning!
Very nice!
Now the question many people will ask : why would you automount ext2 if you don't use apps2sd ?
I personally have ubuntu on my ext2 And besides this approach can be used for a number of things, people who have had the need, or wanted to experiment with init.rc doing things on boot, the mountsd script can easily be altered to do what ever needed.
For me its been a learning curve finding these things out, so by sharing it I may spare some people breaking their backs over this whole init.rc thing. people may want to modify init.rc for whatever reason, so I'm sure people wont have a problem finding a way of putting this to use, and its a subject that isnt all that covered on the forum .. and hey .. at least they get a rom kitchen out of the whole shabang
Very interesting! Thank you.
I used your unpack-program to unpack a recovery-image. It seems to work fine. What I am trying to do is change the state the recovery-image returns the phone to. Would it be possible to just replace your mountsd-script with, for example, a script that installs apps? Or is there a better way to do what Im trying to achieve?
Cheers,
edit: I noticed that on the emulator it is sufficient to just place an apk-file in "data/app" to get it installed. Could it be possible that this is all I need a script to do? :O or could I hurt my poor phone by doing so you think?
sandis84 said:
edit: I noticed that on the emulator it is sufficient to just place an apk-file in "data/app" to get it installed. Could it be possible that this is all I need a script to do? :O or could I hurt my poor phone by doing so you think?
Click to expand...
Click to collapse
That's indeed all you need to do.
Hi!
So I tried to create a signed update.zip, but it failed. It didnt create a "update-script"-file, so my device refused to install it. I wrote my own "update-script"-file, but then it complained "no digest" for the file. How do I solve this?
post the contents of your script people might see whats up
so is this all on linux?
also where are the script files for your tutorial
thanks for the time to put together
sitimber said:
so is this all on linux?
also where are the script files for your tutorial
thanks for the time to put together
Click to expand...
Click to collapse
Says where its at in the first line : )
Code:
wget http://www.grindhouse.no/androidtools/install.sh
But now that I checked, I have to apologize, I see I have a missed payment with my hosting, I'll fix that within the day. Also sorry I havent been answering the few questions here I've been afk cause of surgery.
sitimber said:
post the contents of your script people might see whats up
Click to expand...
Click to collapse
well, I looked in another "update-script" file and found this:
assert compatible_with("0.2") == "true"
assert getprop("ro.product.device") == "dream" || getprop("ro.build.product") == "dream"
show_progress 0.5 0
write_radio_image PACKAGE:radio.img
show_progress 0.5 10
Click to expand...
Click to collapse
So I figured that nothing was essential other then the line "write_radio_image PACKAGE:radio.img". Also ofcourse I made sure it contained the name of my image-file instead of "radio.img". This gave me the "no digest" message, so now I feel unsure on how to create a working update.zip.
edit:
SOLVED! How silly of me. When you sign the update, a hash of each file is put in manifest.mf. Since I added the update-script after signing the file, ofcourse the digest(hash) was missing. Now everything works alot better and I can proceed... until I get stuck again
Cheers,
edit2:
Just to get a better understanding, what exactly does each line do here? Or where can I read about this?
Code:
service mountsdext2 /system/bin/mountsd
user root
group root
oneshot
edit3:
Ok, so I have experimentet, but I still dont manage to solve those last steps. I tried to edit init.rc and just add "mkdir /testdir 0000 system system" where the other directories were created. I then repacked it, zipped it, signed it, put it on my sdcard, started up a custom recovery, installed the update and rebooted. Everything seems to work fine. But when I start adb and check around, I dont see the "testdir"-directory. Also when I check in init.rc my line is gone. Do you guys have an idea of where I went wrong?
sitimber said:
so is this all on linux?
also where are the script files for your tutorial
thanks for the time to put together
Click to expand...
Click to collapse
it doesnot necesarily have to be linux ...you can also do it in windows using cygwin and dsxda's android rom kitchen

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.

[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