[Tutorial] Edify Scripts,Making Flashable Zips - Motorola Atrix 2

This is a WIP.
Edify Scripting Commands
I came across the problem of creating flash-able ZIP files and Edify scripting and in the interests of sharing and helping this great community I would like to share what I have found and hopefully learn more through discussion, I certainly am no expert and am always willing to learn.
So I would like to try and put together a guide to Edify scripting commands and what their function is. I hope we can all collaborate to make this a helpful source of information to all budding devs...we all have to start somewhere right!?
***Please, if there are any mistakes in this post or if you can help by adding further info please post below, thanks***
If any of you have ever flashed a zip,ROM you most probably see things written on the recovery screen like wiping data,wiping cache or CM10 by so and so.You ever wonder how these things are written??
Well the answer is in Edify script.So all those of you who wanna learn how to do all that have to learn the commands used in Edify scripting.
Interested???
Ok lets begin...
Print text in the recovery during flashing process:
Code:
ui_print("Your text here");
Code:
ui_print(" ");
This simply prints a line of text in the recovery, it has no actual effect on the flashing process, if you want a blank line just leave a blank space as the second example.
Controlling the progress bar:
I believe I understand this correctly, if not please do post below with further clarification.
Code:
show_progress(0.000000, 0);
or
Code:
set_progress(0.000000);
You have two choices when controlling the progress bar, the first example allows you to define fractions of the progress bar and how long they will take to fill. The second example just allows you to specify that the bar fills to a certain fraction at whatever point during the flashing process.
The command is defined as:
set_progress(progress bar fraction, duration in seconds to fill defined fraction);
Click to expand...
Click to collapse
For example the following code lines interspersed with your other commands would fill a fifth of the progress bar every five seconds:
Code:
show_progress(0.200000, 5);
ui_print(" ");
show_progress(0.200000, 5);
ui_print(" ");
show_progress(0.200000, 5);
ui_print(" ");
show_progress(0.200000, 5);
ui_print(" ");
show_progress(0.200000, 5);
This process will only complete if the script takes long enough to flash, therefore you need to be aware of what you are actually flashing and how long it will take when defining these values.
If you wish to just define a fraction without fill without a time scale you can use the following command:
Code:
set_progress(0.000000);
It is also best practice to include this element in your scripts as it will reassure people that their handset hasn't frozen during a flash.
Mounting/Unmounting a partition:
This has to be dealt with care as without mounting the required partition you can't do any modification.
To mount a partition you need to use the following syntax:
mount("filesystem-type", "partition-type", "device-specific-location", "mount-point");
filesystem-type: "ext3" or "yaffs2" (edison is ext4)
partition-type: "EMMC" or "MTD" (edison is EMMC)
location: Device specific address(eg. system is /dev/block/mmcblk1p21 )
mount-point: the partition you want to mount (eg./system etc)
Click to expand...
Click to collapse
Example command would be:
Code:
mount("ext3", "EMMC", "/dev/block/mmcblk1p21", "/system");
To unmount a partition you need to input the following command:
Code:
unmount("/system");
Obviously replace the mount partition with whatever partition you are working in.
Format a partition:
To format a partition you need to use the following syntax:
format("filesystem-type", "partition-type", "device-specific-location", "0");
Click to expand...
Click to collapse
Example:
format("ext3", "EMMC", "/dev/block/mmcblk1p21", "0");
Some scripts include the "0" and some do not, not sure exactly on the function difference when included or not, again clarification would be great.
Flashing the contents of your ZIP file:
To flash an entire directory i.e. to copy the contents of the entire directory from your zip into the respective folders in ROM:
Code:
package_extract_dir("system", "/system");
To flash a single file:
Code:
package_extract_file("youtube.apk", "/data");
These commands are structured as follows:
Entire directory:
package_extract_dir ("zipfileSource", "destination-partition");
Click to expand...
Click to collapse
Single File:
package_extract_file ("file", "device-specific-mountpoint");
Click to expand...
Click to collapse
Deleting folders & files:
You can delete multiple folders or files using just one command, as follows:
To delete files:
Code:
delete("file-path-1", "file-path-2", "file-path-3);
To delete folders/directories:
Code:
delete_recursive("directory-path-1", "directory-path-2", "directory-path-3");
Setting Permissions
Here are the basics for setting permissions.
If you want to research the reasons behind this, there is some useful information on Linux permissions here: chmod wiki,
Set permissions of a file or set of files:
set_perm(uid, gid, mode, "filepath1", "filepath2")
uid - user id
gid - group id
mode - permission mode
filepath... - file to set permission on
Click to expand...
Click to collapse
Example:
Code:
set_perm(0, 0, 06755, "/system/xbin/su");
Set permissions of a directory or set of directories and all files and folders within them:
set_perm_recursive(uid, gid, dirmode, filemode, "dirpath1", "dirpath2")
uid - user id
gid - group id
dirmode - permission to set to directories contained within the specified directory
filemode - permission to set to files contained within the specified directory
dirpath... - directory to set permission on
Click to expand...
Click to collapse
Example:
Code:
set_perm_recursive(0, 0, 0755, 0644, "/system");
Permissions syntax explained...so I can understand it lol (if I do then anyone can!):
The following are the pre-defined Android UID's & GID's. Taken from the following link: Android UIDs and GIDs
AID_ROOT 0 /* traditional unix root user */
AID_SYSTEM 1000 /* system server */
AID_RADIO 1001 /* telephony subsystem, RIL */
AID_BLUETOOTH 1002 /* bluetooth subsystem */
AID_GRAPHICS 1003 /* graphics devices */
AID_INPUT 1004 /* input devices */
AID_AUDIO 1005 /* audio devices */
AID_CAMERA 1006 /* camera devices */
AID_LOG 1007 /* log devices */
AID_COMPASS 1008 /* compass device */
AID_MOUNT 1009 /* mountd socket */
AID_WIFI 1010 /* wifi subsystem */
AID_ADB 1011 /* android debug bridge (adbd) */
AID_INSTALL 1012 /* group for installing packages */
AID_MEDIA 1013 /* mediaserver process */
AID_DHCP 1014 /* dhcp client */
AID_SHELL 2000 /* adb and debug shell user */
AID_CACHE 2001 /* cache access */
AID_DIAG 2002 /* access to diagnostic resources */
/* The 3000 series are intended for use as supplemental group id's only. */
/* They indicate special Android capabilities that the kernel is aware of. */
AID_NET_BT_ADMIN 3001 /* bluetooth: create any socket */
AID_NET_BT 3002 /* bluetooth: create sco, rfcomm or l2cap sockets */
AID_INET 3003 /* can create AF_INET and AF_INET6 sockets */
AID_NET_RAW 3004 /* can create raw INET sockets */
AID_MISC 9998 /* access to misc storage */
AID_NOBODY 9999
AID_APP 10000 /* first app user */
"root", AID_ROOT
"system", AID_SYSTEM
"radio", AID_RADIO
"bluetooth", AID_BLUETOOTH
"graphics", AID_GRAPHICS
"input", AID_INPUT
"audio", AID_AUDIO
"camera", AID_CAMERA
"log", AID_LOG
"compass", AID_COMPASS
"mount", AID_MOUNT
"wifi", AID_WIFI
"dhcp", AID_DHCP
"adb", AID_ADB
"install", AID_INSTALL
"media", AID_MEDIA
"shell", AID_SHELL
"cache", AID_CACHE
"diag", AID_DIAG
"net_bt_admin", AID_NET_BT_ADMIN
"net_bt", AID_NET_BT
"inet", AID_INET
"net_raw", AID_NET_RAW
"misc", AID_MISC
"nobody", AID_NOBODY
Click to expand...
Click to collapse
You will need to also understand the way file permissions are represented:
Example = drwxrwxrwx
-Use Root Explorer to find the UID, GID, and permissions for a file. Permissions are the string that looks like some variation on 'rwxr-xr--' next to each file. Long press and choose "change owner" to get the UID and GID. You just want the number next to "owner" and "group", respectively.
-If you're replacing a file, look up these settings for the existing copy and use them. If you're adding a file, just find a file that does the same functions and copy what it has (for example, installing an app to /system/app? Just look at these settings for any other app in that directory).
-MODE is technically a 4-bit string, but the first character can be omitted. There doesn't seem to be any android file permissions with the first character set. For good practice, I think it's safe to assume you can always use a leading 0 unless you know otherwise for something specific. Or, just use a 3-digit MODE, which says to leave those settings as they are (disabled by default). (I.e. 0644=644).
The next 9 characters define the file permissions. These permissions are
given in groups of 3 each.
The first 3 characters are the permissions for the owner of the file or directory.
Example = -rwx------
The next 3 are permissions for the group that the file is owned by.
Example = ----rwx---
The final 3 characters define the access permissions for everyone not part of the group.
Example = -------rwx
There are 3 possible attributes that make up file access permissions.
r - Read permission. Whether the file may be read. In the case of a
directory* this would mean the ability to list the contents of the
directory.
w - Write permission. Whether the file may be written to or modified. For
a directory* this defines whether you can make any changes to the contents
of the directory. If write permission is not set then you will not be able
to delete* rename or create a file.
x - Execute permission. Whether the file may be executed. In the case of a
directory* this attribute decides whether you have permission to enter*
run a search through that directory or execute some program from that
directory
You set these permissions using the following binary based numerical system:
Code:
0: --- No Permissions (the user(s) cannot do anything)
1: --x Execute Only (the user(s) can only execute the file)
2: -w- Write Only (the user(s) can only write to the file)
3: -wx Write and Execute Permissions
4: r-- Read Only
5: r-x Read and Execute Permissions
6: rw- Read and Write Permissions
7: rwx Read, Write and Execute Permissions
Click to expand...
Click to collapse
Default Linux permissions:
For Files:
"Read" means to be able to open and view the file
"Write" means to overwrite or modify the file
"eXecute" means to run the file as a binary
For Directories:
"Read" means to be able to view the contents of the directory
"Write" means to be able to create new files/directories within the directory
"eXecute" means to be able to "Change Directory" (cd) into the directory
Most of the time you set "Read" and "eXecute" together on directories (kind of useless when set by themselves)
Interestingly through further research it seems this system is based on the Octal Binary system...I may be wrong...
Further Commands:
In progress...
So, this is by no means an exhaustive list and I would appreciate it that if I have made any mistakes people make me aware in this thread and I can update this tutorial.
I would also like to add further commands and their uses, if people can provide more I will add them too.
I hope this helps people out! Many thanks!
Credits: wilskywalker for his guide from which I got the ideas and the knowledge.

How to create the flashable zip:
You will need the following:
Android SDK, ADB & Fastboot set up for your handset.
Notepad++
7Zip
Setting up your zip directories:
you will need to create the following folder structure (these are case sensitive):
/META-INF/com/google/android
Click to expand...
Click to collapse
All flash-able zips include this file structure, the final folder 'android' will contain two files:
update-binary
updater-script
Click to expand...
Click to collapse
update-binary: I have been unable to find much information on the update-binary file other than they seem to be chip set specific (if anyone can shed further light on these I will include it here). For the sake of compatibility I have attached the update binary from the latest CyanogenMod Nightlies for the Atrix 2 at the bottom of this thread - You can of course download the latest nightly and extract the update-binary file yourself as the attached one will obviously begin to date.
For anybody having problems flashing it is worth ensuring you have an up to date version of the update-binary (obviously the one attached to this thread will gradually become out of date).
updater-script: This we can create ourselves, to ensure it works properly we will use Notepad++.
Open Notepad++ and start a new file, with the following settings:
Format: Unix
Encoding: ANSI
Default Language: Normal Text
Click to expand...
Click to collapse
Save this file as:
File name: updater-script
File type: All types (*.*)
Click to expand...
Click to collapse
You can now begin writing your edify script in this file.
I'm explaining a simple example script for your better understanding.
Code:
assert(getprop("ro.product.board") == "edison");
ui_print(" ");
ui_print("confirming device edison");
ui_print(" ");
ui_print("success");
ui_print(" ");
show_progress(0.200000, 5);
ui_print("Mounting your system...");
mount("ext3", "EMMC", "/dev/block/mmcblk1p21", "/system");
ui_print(" ");
show_progress(0.200000, 5);
ui_print("updating system files");
package_extract_dir("system", "/system");
ui_print(" ");
show_progress(0.200000, 5);
ui_print("unmounting system");
unmount("/system");
ui_print(" ");
show_progress(0.200000, 5);
ui_print("by your name");
show_progress(0.200000, 5);
ui_print(" ");
***EMPTY LINE***
assert(getprop("ro.product.board") == "edison");
Click to expand...
Click to collapse
This is checking you are flashing the correct handset, this is not a requirement, but is best practice. Just insert another device name in the place of "edison" if you so wish, or remove the command all together.
mount("ext3", "EMMC", "/dev/block/mmcblk1p21", "/system");
Click to expand...
Click to collapse
This is the specific mount point for the edison system partition, if you wish to flash a different partition, data for instance you can get the mount points for your device by entering the following code over ADB:
Code:
adb shell "mount > /sdcard/PHONENAME_mountinfo.txt"
This will place a text file on your sdcard with the mount points for your specific device (remember to swap 'PHONENAME' with your device name e.g. 'edison').
Additionaly here are the mount points for data and cache for A2
Cache:
mount("ext3", "EMMC", "/dev/block/mmcblk1p22", "/cache");
Click to expand...
Click to collapse
Data:
mount("ext3", "EMMC", "/dev/block/mmcblk1p25", "/data");
Click to expand...
Click to collapse
package_extract_dir("system", "/system");
Click to expand...
Click to collapse
This command extracts the files you wish to flash from the zip and flashes them to the phone, it is formatted as follows ("package-path", "/destination-path"). So for this example you are telling it to flash everything from the 'system' folder in your zip to the /system partition of your handset. You can obviously change these values for different partitions.
unmount("/system");
Click to expand...
Click to collapse
This simply unmounts whatever partition you previously mounted.
ui_print(" ");
Click to expand...
Click to collapse
Shows text in the recovery whilst the flash is ongoing, you can put whatever you please between the double quotes, you must leave a space if you wish to have a blank line.
show_progress(0.200000, 5);
Click to expand...
Click to collapse
Controls what the progress bar in the background is displaying, it is formatted as follows (fragment, seconds).
***EMPTY LINE***
Click to expand...
Click to collapse
This is not actually text, you simply need to leave a blank line at the end of your script before you save it for it to work.
FYI, this means in fact your script could look like this and still work:
Code:
ui_print(" ");
show_progress(1.000000, 30);
mount("ext3", "EMMC", "/dev/block/mmcblk1p21", "/system");
package_extract_dir("system", "/system");
unmount("/system");
ui_print(" ");
***EMPTY LINE***
But that just isn't that pretty, or as deceptively complicated lol!
Make sure you save your edify script.
Files to flash:
You now need to create a further folder, this needs to be named based on where within the system you are flashing, for the sake of this example we are flashing to the system partition, so create this folder path(of course the structure depends on what are files you need to flash and their location):
/system/app
Click to expand...
Click to collapse
Place whatever files you wish to flash within this file e.g:
/system/app/nameofapp.apk
Click to expand...
Click to collapse
Creating your .zip file:
Select both of your top directories and their contents 'META-INF' and 'system' and package them into a .zip file with 7zip using the following settings:
Archive: name_of_your_file
Archive Format: zip
Compression level: Store
Update mode: Add and replace files
Click to expand...
Click to collapse
And there you have it, your very own flash-able .zip file.
How to sign your update.zip:
You don't actually need to sign your zip file for it to work as most custom recoveries now support unsigned zips, for aspiring developers and the more cautious among us though the how to will be updated later.
For now you can use the META-INF folder from the attached zip as is just modify the updater-script according to your requirments.
How to create your own private signing key & certificate:
You will need the following download:
Open SSL
If you want to create your own private keys for signing, here's what you need to do.
As before extract the OpenSSL files to a folder in the root of your c:\ drive, preferably named 'openssl' for ease of cmd line navigation. Then input the following:
Code:
cd\openssl\
openssl genrsa -out key.pem 1024
openssl req -new -key key.pem -out request.pem
openssl x509 -req -days 9999 -in request.pem -signkey key.pem -out certificate.pem
openssl pkcs8 -topk8 -outform DER -in key.pem -inform PEM -out key.pk8 -nocrypt
You can then replace 'key.pk8' & 'certificate.pem' with your own files.
I have attached an example flashable .zip file that includes a updater-script and the update-binary.Use that as a base or example to set your zip up.
I really hope this has helped folks out, if so please consider hitting the 'Thanks' button!
Happy flashing!
May the -Mass times Acceleration-be with you...

Thanks a TON!! You must've read my mind because I planned on trying to figure this out this weekend.lol BTW, what program are you using to write these scripts?
Brought to you by time and relative dimensions in space.

1BadWolf said:
Thanks a TON!! You must've read my mind because I planned on trying to figure this out this weekend.lol BTW, what program are you using to write these scripts?
Brought to you by time and relative dimensions in space.
Click to expand...
Click to collapse
Lol.
Notepad++ is the unanimous choice.
Also always leave one blank line at the bottom or the script won't work.
May the -Mass times Acceleration-be with you...

deveshmanish said:
Notepad++ is the unanimous choice.
Also always leave one blank line at the bottom or the script won't work.
May the -Mass times Acceleration-be with you...
Click to expand...
Click to collapse
I thought so but wanted to be sure. Thanks again.
Brought to you by time and relative dimensions in space.

Thanks for putting this together..
At first it seems a little complex for an aspiring modder, but still a great reference for the novice as well as the experienced modders..
Maybe offer some example scripts..? Feel free to use some from any of my zips.. Also, that goes for people trying to make their own - look at what others have done as examples.
Also might be worth noting the default permissions for system are 0644 - meaning if you are only installing things that need those perms (like an .apk, .jar or .so, etc), then you don't need to specify permissions in the updater-script.
EDIT: another text editor worth trying is Sublime Text 2 (thanks to cogeary for the tip) - need to eventually pay for the license (or find another way around it) or you will get pop-ups.
It's for both Windows and Linux (I use it in Ubuntu constantly, and mostly Notepad++ in Windows).
Sent from my MB865 using xda app-developers app

alteredlikeness said:
Thanks for putting this together..
At first it seems a little complex for an aspiring modder, but still a great reference for the novice as well as the experienced modders..
Maybe offer some example scripts..? Feel free to use some from any of my zips.. Also, that goes for people trying to make their own - look at what others have done as examples.
Also might be worth noting the default permissions for system are 0644 - meaning if you are only installing things that need those perms (like an .apk, .jar or .so, etc), then you don't need to specify permissions in the updater-script.
Sent from my MB865 using xda app-developers app
Click to expand...
Click to collapse
I'm definitely going to try and make this simpler.BTW great idea of putting sample zips together for reference.Thanks.
And yeah some stuff needs to be added even the path for data and cache partitions.And also I'm thinking of adding a slight explanation of busybox.The folder structure of a zip and what files it contains those are also on the to-do list.
Will get back to this once I'm done playing with MIUIv5.Enjoying it so far.
May the -Mass times Acceleration- be with You...

OP updated with guide to create the flashable zip.

Nice Tut Sir Its Very Helpful...

Yeah... I love this thread and use it often too excellent job op!

Interesting tutorial. What got me interested in this thread is. I want to convert a recovery.img to a flashable recovery zip so I can easily switch recoveries without odin. I have seen apps that can create flash zip automatically, but none of them support of adding recovery.img. Thanks.

Related

[Script] Simple tar backup and restore for devs [FINISHED!]

To all of the ROM makers here, please stop using those bonsai data-backup/data-restore scripts, as they don't work. I'm assuming they used to work since everyone here seems to be using them, but something has changed (maybe something in CWM 5.x?) and now all those data-backup and data-restore scripts do is make phones not work.
I've taking those scripts and rewritten them using the tar command. busybox's tar doesn't have many options, but it does preserve file permissions and ownership, so it makes for an adequate backup tool. HUGE thanks to SenseiSimple for the ideas and improvements. See SenseiSimple's post, here.
EDIT: Here is the final version!
updater-script BACKUP EXAMPLE
Code:
ui_print("************************************************");
ui_print(" TAR BACK UP / RESTORE EXAMPLE");
ui_print("************************************************");
show_progress(1.000, 0);
set_progress (0.100);
#EXTRACT BACKUP SCRIPT
ui_print("Preparing tools...");
package_extract_file("tools/busybox", "/tmp/busybox");
package_extract_file("tools/tar-backup", "/tmp/tar-backup");
set_perm(0, 0, 0755, "/tmp/tar-backup");
set_perm(0, 0, 0755, "/tmp/busybox");
#CREATE BACKUP
set_progress (0.350);
ui_print("Backing up - this may take a while...");
run_program("/sbin/mount","/sdcard");
run_program("/sbin/mount","/data");
run_program("/tmp/tar-backup","backup");
unmount("/data");
#RECOVER BACKUP
set_progress (0.600);
ui_print("Recovering backed up data...");
run_program("/sbin/mount","/data");
run_program("/tmp/tar-backup","recover");
# run_program("/tmp/tar-backup","recover","delete");
# run_program("/tmp/tar-backup","recover","archive");
unmount("/data");
set_progress(1.000);
show_progress(1.000, 0);
tar-backup script
edit the value of ROMName=YourROMName (you should only have to edit this file once for all your ROM versions, it's not version-dependent), that's it.
Code:
#!/tmp/busybox sh
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU Library General Public License as published
# by the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# License GPLv2+: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>
#
# toadlife, SenseiSimple, XDA Community, Bonsai
# invoke with
# run_program("/tmp/tar-backup","backup");
# run_program("/tmp/tar-backup","recover" [,"delete"|"archive"]);
# - "delete" option deletes the backup file
# - "archive" option renames the backup file for archiving (otherwise, it is left alone and replaced on next backup/flash)
ROMName=MyAwesomeROM
platbuild=EI22
PATH=/tmp:/sbin:$PATH
datadir=/data
backdir=/sdcard/ROMBackup-$platbuild
backfile=$backdir/$ROMName.tgz
TEST="busybox test"; TAR="busybox tar"; MKDIR="busybox mkdir"
if [ "$1" = "backup" ]; then
rm /data/dalvik-cache/*
rm /data/lost+found/*
rm $backfile
if $TEST -d $datadir ; then
$TEST ! -d $backdir && $MKDIR $backdir
$TAR pczf $backfile $datadir
if $TEST $? -ne 0 ; then
echo "Backup failed!"; exit 1
else
echo "Backup completed"; exit 0
fi
fi
elif [ "$1" = "recover" ]; then
if $TEST -f $backfile; then
$TAR pxzf $backfile
if [ "$2" = "delete" ]; then
rm $backfile;
elif [ "$2" = "archive" ]; then
archdate=`date +%Y%m%d-%I%M`
archfile=$backdir/$ROMName-$archdate.tgz
mv $backfile $archfile
fi
echo "Restore Completed!"; exit 0
else
echo "Restore failed!"; exit 1
fi
else
echo "Backup - Invalid argument"; exit 1
fi
Example CWM package (unsigned) that uses the script.
BTW, I have tested this script several times with test builds of my ROM and also tested it going from SleeperROM 1.x to my ROM. In sleeper ROM I started with blank slate, installed a few apps, configured my email and set a wallpaper. I then installed a test build of my ROM CleanGB with this backup restore script and I had no problems after flashing; all of my data and settings, including the apps in /data from sleeper ROM came over.
Thank you for this. I proposed this to ERA for Legendary and also to the Bonsai crew.
Sent from my SPH-D700 using XDA App
UNIFIED BACKUP SCRIPT - INSTRUCTIONS/DIFFERENCES
SUMMARY The motivation is threefold, as Toadlife initiated with the purpose of modernizing the backup scripts to better protect the data file attributes in backup by using Tar rather than streaming to Cpio, it's possible with adding this improvement to add new functionality and prevent cluttering up users' sdcards with various ROM folders/editions. They will now all be located by ROM name (i.e. SleeperROM, CleanGB, StarskyROM, RandomROM, LegendaryROM *.tgz) in the /sdcard/ROMBackup-EI22/*.tgz directory.
In your ROM package
1. REPLACE /tools/data-backup and /tools/data-restore
2. WITH /tools/tar-backup (script below)
3. UPDATE ROMName=CleanGB with your rom name
in your updater-script, replace
Code:
package_extract_file("tools/data-backup", "/tmp/data-backup");
package_extract_file("tools/data-restore", "/tmp/data-restore");
set_perm(0, 0, 0755, "/tmp/data-backup");
set_perm(0, 0, 0755, "/tmp/data-restore");
with
Code:
package_extract_file("tools/tar-backup", "/tmp/tar-backup");
set_perm(0, 0, 0755, "/tmp/tar-backup");
updater-script USAGE:
1. REPLACE: run_program("/tmp/data-backup");
2. WITH run_program("/tmp/tar-backup", "backup");
3. REPLACE: run_program("/tmp/data-restore");
4a. WITH run_program("/tmp/tar-backup", "recover"); - Leave the backup in place, will be overwritten in the future
4b. OR run_program("/tmp/tar-backup", "recover","delete"); To delete the backup file when complete
4c. OR run_program("/tmp/tar-backup", "recover","archive"); To archive (with date) the backup file when complete
MINIMAL updater-script BACKUP EXAMPLE
Code:
ui_print("************************************************");
ui_print(" TAR BACK UP / RESTORE EXAMPLE");
ui_print("************************************************");
show_progress(1.000, 0);
set_progress (0.100);
#EXTRACT BACKUP SCRIPT
ui_print("Preparing tools...");
package_extract_file("tools/busybox", "/tmp/busybox");
[B]package_extract_file("tools/tar-backup", "/tmp/tar-backup");[/B]
[B]set_perm(0, 0, 0755, "/tmp/tar-backup");[/B]
set_perm(0, 0, 0755, "/tmp/busybox");
#CREATE BACKUP
set_progress (0.350);
ui_print("Backing up - this may take a while...");
run_program("/sbin/mount","/sdcard");
run_program("/sbin/mount","/data");
[B]run_program("/tmp/tar-backup","backup");[/B]
unmount("/data");
#RECOVER BACKUP
set_progress (0.600);
ui_print("Recovering backed up data...");
run_program("/sbin/mount","/data");
[B]run_program("/tmp/tar-backup","recover");
# run_program("/tmp/tar-backup","recover","delete");
# run_program("/tmp/tar-backup","recover","archive");[/B]
unmount("/data");
set_progress(1.000);
show_progress(1.000, 0);
FILE: /tools/tar-backup
edit the value of ROMName=YOURROMNAME (you should only have to edit this file once for all your ROM versions, it's not version-dependent), that's it.
Code:
#!/tmp/busybox sh
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU Library General Public License as published
# by the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# License GPLv2+: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>
#
# toadlife, SenseiSimple, XDA Community, Bonsai
# invoke with
# run_program("/tmp/tar-backup","backup");
# run_program("/tmp/tar-backup","recover" [,"delete"|"archive"]);
# - "delete" option deletes the backup file
# - "archive" option renames the backup file for archiving (otherwise, it is left alone and replaced on next backup/flash)
[B]ROMName=CleanGB[/B]
platbuild=EI22
PATH=/tmp:/sbin:$PATH
datadir=/data
backdir=/sdcard/ROMBackup-$platbuild
backfile=$backdir/$ROMName.tgz
TEST="busybox test"; TAR="busybox tar"; MKDIR="busybox mkdir"
if [ "$1" = "backup" ]; then
rm /data/dalvik-cache/*
rm /data/lost+found/*
rm $backfile
if $TEST -d $datadir ; then
$TEST ! -d $backdir && $MKDIR $backdir
$TAR pczf $backfile $datadir
if $TEST $? -ne 0 ; then
echo "Backup failed!"; exit 1
else
echo "Backup completed"; exit 0
fi
fi
elif [ "$1" = "recover" ]; then
if $TEST -f $backfile; then
$TAR pxzf $backfile
if [ "$2" = "delete" ]; then
rm $backfile;
elif [ "$2" = "archive" ]; then
archdate=`date +%Y%m%d-%I%M`
archfile=$backdir/$ROMName-$archdate.tgz
mv $backfile $archfile
fi
echo "Restore Completed!"; exit 0
else
echo "Restore failed!"; exit 1
fi
else
echo "Backup - Invalid argument"; exit 1
fi
Example CWM package (unsigned) to augment these instructions - pay attention to your version of Busybox vs the one included.
SenseiSimple said:
Thanks, i'll be giving it a spin for the next release!
I'm wondering, should we perhaps standardize the directory the backups go into and name the actual backup file accordingly?
I for one hate my sd card filling up with a bunch of random folders, backups included. (i know this is trivial, but since you've provided a good change to the backup method...)
will put the backup into /sdcard/EI22_ROM_Backup/CleanGB.tgz
since we don't automatically delete the backup, i assume for precautionary reasons, best for them to pile up in one place, no?
Click to expand...
Click to collapse
Couldn't agree more. Seems like I'm constantly cleaning backup files off my sdcard.
Why not delete the backup file after the restore? Otherwise a flashaholic will have a whole bunch of these files on their card as well as their nandroids, titanium backups, ROMs, pics etc. Just add a delete to the script.
kennyglass123 said:
Why not delete the backup file after the restore? Otherwise a flashaholic will have a whole bunch of these files on their card as well as their nandroids, titanium backups, ROMs, pics etc. Just add a delete to the script.
Click to expand...
Click to collapse
That's my mentality on it. But in case something goes wrong with the restore, maybe, you have the whole backup file to dissect? that was the only reason i could think of to keep all the cruft in which case, at least have them all consolidated.
I will definitely include this in my rom. Thanks
Sent from my SPH-D700 using XDA App
SenseiSimple said:
That's my mentality on it. But in case something goes wrong with the restore, maybe, you have the whole backup file to dissect? that was the only reason i could think of to keep all the cruft in which case, at least have them all consolidated.
Click to expand...
Click to collapse
Everyone should already be making a nandroid before flashing anything and then can always use advanced restore data. My issue is until you start looking at your sd card, you don't know ROMs have left backups behind. Nuke em...lol.
SenseiSimple said:
Thanks, i'll be giving it a spin for the next release!
I'm wondering, should we perhaps standardize the directory the backups go into and name the actual backup file accordingly?
I for one hate my sd card filling up with a bunch of random folders, backups included. (i know this is trivial, but since you've provided a good change to the backup method...)
(my edits in bold)
Click to expand...
Click to collapse
Sounds good to me. Putting them both in one script would be easier too. I'll use the second revision. You could allways pass another varible to the script to tell it weather or not to delete the backup.
SenseiSimple said:
That's my mentality on it. But in case something goes wrong with the restore, maybe, you have the whole backup file to dissect? that was the only reason i could think of to keep all the cruft in which case, at least have them all consolidated.
Click to expand...
Click to collapse
Ten years sysadminning had led me to be extremely wary of deleting data, so I'm always inclined to keep backups.
Ten years sysadminning had led me to be extremely wary of deleting data, so I'm always inclined to keep backups.
Click to expand...
Click to collapse
I know that personally if something messed up with the re-install phase of the flashing, i'd want the backup file to still be available... it would be nice to have a unified backup dir, and maybe even an option in CWM to delete backups left by roms - it becomes somewhat of a redundancy of CWM's backup at that point, but it's not as if we can invoke the CWM backup routine from script anyway...
toadlife said:
Sounds good to me. Putting them both in one script would be easier too. I'll use the second revision. You could allways pass another varible to the script to tell it weather or not to delete the backup.
Click to expand...
Click to collapse
i deleted my script from the post, on testing, i just can't get it to run - in theory it's a great idea - the single script file is sound but running it from the updater_script with run_program("/tmp/data_save","backup"); for example, just doesn't run it... i've tried variations using
run_program("/sbin/sh","/tmp/data_save","backup");
run_program("/tmp/busybox","sh","/tmp/data_save","backup");
each are no-go...
individually, the scripts work... is there a limitation that the only way run_program can pass arguments is to a binary and not a shell script? that's all i can think of
EDIT:
I GOT IT, will post up the revision in a moment
SenseiSimple said:
EDIT:
I GOT IT, will post up the revision in a moment
Click to expand...
Click to collapse
Crud. I just posted updated version at the top that contains a variable to control deletion of the backup file.
Can you update the script to take a variable that controls whether or not the backup file gets deleted?
It may be worthwhile to add the current date to the filename - it keeps the current backup and restore for a flash fresh, but allows archival copies to be trivially stored ala Nandroid.
k0nane said:
It may be worthwhile to add the current date to the filename - it keeps the current backup and restore for a flash fresh, but allows archival copies to be trivially stored ala Nandroid.
Click to expand...
Click to collapse
This could be done right after the restore finishes...if the file is not set to be deleted...
Code:
date=`date +.%m.%d.%Y.%I:%M`;
newromname={$romname}{$date}
newbackfile=/sdcard/${build}_ROM_Backup/$newromname.tgz
mv $backfile $newbackfile
SenseiSimple said:
EDIT:
I GOT IT, will post up the revision in a moment
Click to expand...
Click to collapse
Sorry, I got impatient and rolled them into one script myself. It tags the files with the date if the delete option is not set. The script is in the first post.
toadlife said:
To all of the ROM makers here, please stop using those bonsai data-backup/data-restore scripts, as they don't work. I'm assuming they used to work since everyone here seems to be using them, but something has changed (maybe something in CWM 5.x?) and now all those data-backup and data-restore scripts do is make phones not work.
I've taking those scripts and rewritten them using the tar command. busybox's tar doesn't have many options, but it does preserve file permissions and ownership, so it makes for an adequate backup tool.
EDIT: I've rewritten the scripts so that both backup and restore functionality are in one script. Thanks SenseiSimple for the idea!
tar-backup
Code:
#!/tmp/busybox sh
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU Library General Public License as published
# by the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# License GPLv2+: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>
#
#
# tar data backup and restore
# based on bonsai data backup/restore scripts
# by toadlife , SenseiSimple and the Epic 4G XDA community
#
# Call from your updater script like so...
#
# Backup: run_program("/tmp/tar-backup", "backup");
# Restore: run_program("/tmp/tar-backup", "restore"[, "delete"]);
#
# optional "delete" switch will cause the backup file to be deleted after
# restore
#
#
romname=CleanGB
build=EI22
datadir=/data
PATH=/tmp:/sbin:$PATH
BB=/tmp/busybox
backfile=/sdcard/${build}_ROM_Backup/$romname.tgz
if [ "$1" = "backup" ]; then
$BB rm /data/dalvik-cache/*
$BB rm /data/lost+found/*
$BB rm $backfile
if $BB test -d $datadir; then
$BB test ! -d /sdcard/${build}_ROM_Backup && $BB mkdir /sdcard/${build}_ROM_Backup
$BB tar pczf $backfile $datadir
if $BB test $? -ne 0; then
echo "Backup failed!"
exit 1
else
echo "Backup completed"
exit 0
fi
fi
fi
if [ "$1" = "restore" ]; then
if $BB test -f $backfile; then
$BB tar pxzf $backfile
echo Restore Completed!
if [ "$2" = "delete" ]; then
rm $backfile
else
DATE=`date +%Y.%m.%d.%I%M`;
newromname=$romname.$DATE
newbackfile=/sdcard/${build}_ROM_Backup/$newromname.tgz
mv $backfile $newbackfile
fi
exit 0
else
echo Restore failed!
exit 1
fi
fi
Here is an example package that uses the script.
Click to expand...
Click to collapse
From looking at it, it doesn't look like there should be issues... Nice work!
and with the improved handling of tarballs through CWM, this thing should be nice and fast! =)
Your version still didn't work for me, same issue i was facing with mine.
I updated post #4 with an updated version based on a combination of yours and the one i was late providing, i've tested it several times with the three options.
What are you thoughts? Try it out and if it works update your code detail with it, my mini-tutorial can be linked complementary to it
EDIT I just remembered/experienced that CWM (5.0.2.7 afaik) has a bug in which it doesn't provide the right datetime. So the archive feature may be broken until that is fixed. http://forum.xda-developers.com/showthread.php?p=19689193#post19689193 - mine shows several years off "jan 01, 2005 01:00" and the archives overwrite themselves... perhaps we need to serialize/number rather than date
SenseiSimple said:
Your version still didn't work for me, same issue i was facing with mine.
Click to expand...
Click to collapse
What issue? It worked great for me.
SenseiSimple said:
EDIT I just remembered/experienced that CWM (5.0.2.7 afaik) has a bug in which it doesn't provide the right datetime. So the archive feature may be broken until that is fixed. http://forum.xda-developers.com/showthread.php?p=19689193#post19689193 - mine shows several years off "jan 01, 2005 01:00" and the archives overwrite themselves... perhaps we need to serialize/number rather than date
Click to expand...
Click to collapse
IIRC, Jan 1 2005 is the date you get when you pull the battery. Apparently it resets the internal clock on the device. When doing a normal reboot or power down the current date is retained.
Anyhow, yours looks fine. I'll test it out later today and will edit my top post with your revision.
toadlife said:
What issue? It worked great for me.
IIRC, Jan 1 2005 is the date you get when you pull the battery. Apparently it resets the internal clock on the device. When doing a normal reboot or power down the current date is retained.
Anyhow, yours looks fine. I'll test it out later today and will edit my top post with your revision.
Click to expand...
Click to collapse
Cool thanks, sorry for the delay. about the time, i had indeed recently pulled the battery without booting in between.
The issue i had with my original script and yours was something to do with busybox applets/builtins between /tmp/busybox and /sbin/busybox... i'm not sure what version of busybox i had included with my rom, but i substituted mine with yours (mine was 1.9MB which i've noticed in a few different roms, yours and the one in ICS releases are 2MB), and for good measure combined our two scripts, everything magically came together, oddly enough with the combined script, both busybox versions work.

[Q] set_perm_recursive to set_perm question

I've been searching for a guide to help me understand the syntax set_perm and set_perm_recursive, but can not find anything from googling these terms and explanations of how to use them and what values to use for a particular permission...
What I'm trying to do is create a flashable zip with apks ( some stored in the /system/app & some in the /data/app ), and with the updater-script file I've cut it down to the necessity syntaxs but having problems with the above syntax... I see that I can set permissions to all files within the /system/app folder ( using set_perm_recursive(0, 0, 0755, 0644, "/system/app"); syntax ), however I don't want/need to set all the file permissions in /system/app folder that have already been set from the initial rom flash, so using set_perm(x, x, x, "/path"); syntax instead I want to set each file I flash into the /system/app folder ( from the flashable zip ) individually to the exact same permissions as set_perm_recursive I pasted above... So, can I just remove the _recursive & 0644, parts of the syntax so that it looks like this set_perm(0, 0, 0755, "/system/app/xxx.apk"); for each individual file permission?
Much appreciate the response and hope you all understand what I'm trying to achieve, cuz I was kinda confused a little when writing this!
Cheers all
trueno2k said:
I've been searching for a guide to help me understand the syntax set_perm and set_perm_recursive, but can not find anything from googling these terms and explanations of how to use them and what values to use for a particular permission...
What I'm trying to do is create a flashable zip with apks ( some stored in the /system/app & some in the /data/app ), and with the updater-script file I've cut it down to the necessity syntaxs but having problems with the above syntax... I see that I can set permissions to all files within the /system/app folder ( using set_perm_recursive(0, 0, 0755, 0644, "/system/app"); syntax ), however I don't want/need to set all the file permissions in /system/app folder that have already been set from the initial rom flash, so using set_perm(x, x, x, "/path"); syntax instead I want to set each file I flash into the /system/app folder ( from the flashable zip ) individually to the exact same permissions as set_perm_recursive I pasted above... So, can I just remove the _recursive & 0644, parts of the syntax so that it looks like this set_perm(0, 0, 0755, "/system/app/xxx.apk"); for each individual file permission?
Much appreciate the response and hope you all understand what I'm trying to achieve, cuz I was kinda confused a little when writing this!
Cheers all
Click to expand...
Click to collapse
Don't know if you're still requiring this, but you can take a look at this:
Function Name: set_perm
Function Syntax: set_perm(uid, gid, mode, file1, file2, ..., fileN)
Parameter Details:
uid = user id
gid = group id
mode = permission mode
fileX = file to set permission on
These 4 attributes are necessary, hope it helps!
more insight
Function Name: set_perm_recursive
Function Syntax: set_perm_recursive(uid, gid, dirmode, filemode, dir1, dir2, ...dirN)
Parameter Details:
uid = user id
gid = group id
dirmode = permission to set to directories contained within the specified directory
filemode = permission to set to files contained within the specified directory
dirX = directory to set permission on
Action: Set permissions of a directory or set of directories and all files and folders within them. At least one directory must be specified (The first 5 parameters are required)
hope it helps and know that sure as hell it did help me, cheers

[TUT] Create your own updater-script!

To create updater-script or to edit updater-script you need Notepad++ (don’t use notepad). Download it from here and install in your pc
updater-script is located in Meta-inf/com/google/android/updater-script
To create your own updater-script
Open notepad++ and from file menu select new and create the commands and create your own updater-script with this tutorial
After typing the commands save it as all types(*.*) and name it as updater-script and click save and put it in folder Meta-inf/com/google/android/updater-script
In this tutorial i will explain you all commands used in updater-script so that you can edit or create updater-script
ui_print – This command prints the prints the word inside the quotations
Example – ui_print(“galaxy s advance”); prints galaxy s advance in your cwm recovery
mount – This command mounts the partition, if you want to add files to system partition you have to mount system partition, data for data partition
To mount system - mount(“ext4″, “EMMC”, “/dev/block/mmcblk0p3″, “/system”);
Here mmcblk0p3 is the name of system partition for galaxy s advance(this name varies from device to device)
format - This command formats the partition specified
It is highly recommended to include this command to format system and data if you are making updater-script for ROM
To Format system - format(“ext4″, “EMMC”, “/dev/block/mmcblk0p3″, “0″);(partition name varies from device to device)
package_extract_dir(” “, “/”) – This command extracts all the files from the folder mentioned inside first quotation to the partition or directory inside second quotation
For system - package_extract_dir(“system”, “/system”);
(this copies all files from system folder in zip to system partition in phone)
For data - package_extract_dir(“data”, “/data”);
package_extract_file(” “,”/”) - This command extract the single file inside between first quotation from zip to the partition or directory inside second quotation
symlink – This command creates links to its executable files
Here is an example
for super su binaries - symlink(“/system/xbin/su”, “/system/bin/su”);
set_perm_recursive - This command sets permission for folders
here android uses unix permission system
in unix
4 – read
2 – write
1 – execute
so
rwx is 4+2+1 = 7
rw is 4+2 = 6
rx is 4+1 = 5
Example - set_perm_recursive(0, 0, 0755, 0644, “/system”);
In this 0 is a user id for owner that refers to root. It means that permission owner for system folder. and 0 is root user means it unrestricted access to system. it is given in order to run programs to run properly
second 0 also refers to root. but here it refers to group id 0
we are only seeing about folders because “set_perm_recursive” is a command that sets permission to folders
next 0755 it means rwxr-xr-x permission has been given to system folder and rw-r-r is set for all folders inside system folder
set_perm – This command sets permission for a specific file
Example - set_perm(1000, 1000, 0640, “/system/etc/bluetooth/auto_pairing.conf”);
here the 1000 refers to user id system and 0640 is rw-r—–
and this command sets the permission rw-r—– for the file auto_pairing.conf
unmount – This command unmounts the partition
Example - unmount(“/system”); – unmounts system
General rule in updater-script – all commands should end with semi colon ; otherwise it will show error and if cwm or twrp shows status 7 error the error is in updater-script
try fixing it by going through this thread
Great!!!!! I was looking for something like this, thanks
Enviado desde mi GT-I9070 mediante Tapatalk
Thanks. it took lot of time for me to understand this, after looking through suid, Unix and going through Linux permissions I understood
So I made a tut for in simple way that everyone could understand
Sent from my GT-I9070 using xda app-developers app
Thanx A lot
@PradeepMurugan Usefull Post for all. Keep it up bro.
abhinav2hd said:
@PradeepMurugan Usefull Post for all. Keep it up bro.
Click to expand...
Click to collapse
Thanks I will update this thread by adding information how to create updater-script for flashable zips soon and make thread some what beautiful soon
Sent from my GT-I9070 using Tapatalk
Thanks mate
keep up the good work

[Guide] Making Mod Pack for a ROM

its about making patch modpack for my rom and
making update script full...
So,Let's start...
________________________________________
________________________________________
How to make modpack or patch...
Frist make sure that what you want to add on your
rom..like i want to add my modded
systemui,framwork_res,some importent app,some
brinery like su,mkbootimg,some wallpaper,new
ringtone,boot logo,boot animation and some app
with data...
ok now i explain you somethings which are very
very important...
frist in a modpack this folders are added..like>>>
1.Meta_inf
2.data
3.sdcard
4.system...etc etc...
you will also see more folder or file but now i will
tell you about this folders ^^^...
1.Meta_inf...
i think everybody know this folder...i give a short
example...
in this folder you will found update script and
update brinary...
[Q]what is update script?
[Ans.] updater-script - it is just a text file which
contains all the commands which tells the
clockworkmod what to do with the given
zip file. the updater-script is written in the edify
scripting language.
[Q]what is update brinary?
[ans] update-binary - it is a binary which is
requiered by the clockworkmod to translate the
human readable format of the updater-
script to machine readable format for execution
of the updater-script in our device.
now i think you would understand what is update
script and brinary...
ok now 2.Data folder...in data folder you can add
some app with data...fir this what you need?!!
Frist install your app on your mobile and mod
it...like i want to add Xposed installer with
frimwere updated in my modpack...so frist i
installed the app and open it..then click on install/
update...then reboot my device...now my modding
was complete...now its time to add it with data...
.
so i made a folder on sdcard like (modpack for my
rom) then open it and made another folder name
(data) then in data folder i made two folders like
(app) and (data)
then i opened root explorer and went to root
derectory...then go to data...then go to app folder
and choosed my app thats mean xposed...then
copied it to sdcard/modpack/data/app and again
go to root derectory/data...this time i go to data
folder and find my apps data.then copy it to
sdcard/modpack/data/data...thats all...
This is an example...now you can add you app
with data like i had added...but i recommend you
that dont add more then 4 apps with data...
ok now 3.sdcard...
by this folder you can add anythings to your
sdcard...like i want to add some themes of mi
home luncher and all kernel,profile of viper 4
fx...frist made (sdcard)folder on your sdcard/
modpack...now copy all things from your sdcard
which you want to add..like i copied viper4fx
folder from my sdcard and paste it to sdcard/
modpack/sdcard...you can add themes in this way
too...just copied the themes with the whole
derctory in your sdcard/modpack/sdcard
folder...like i copied miui folder to my sdcard/
modpack/sdcard folder...beacuse all themes of
miui are in miui folder...
now comes 4.System folder.. so make a folder
(system) on your sdcard/modpack...then open
system folder and made some folder like
app,etc,lib,bin,xbin etc if you want to add
somethings on your roms system folder..i think
every body know this folder...if you want to add
your modded app,just sing it and drop it to...
Now full completed...you can see some extra
folders and files...if you want to add these to then
comment here i will told you how add these
folder...or you can pm me too
________________________________________
now its time to make update script for your
modpack..
...........
frist copy a meta_inf to your sdcard/modpack and
open update script...delect all things...
you can edit this line as your wish>>>
ui_print(“xolo – next level”);
now see what is ui print?
ui_print – This command prints the prints the
word inside the quotations
Example – ui_print(“xolo – next level”); prints
xolo next level in your cwm recovery
______________________
then you need to mount system partition...and
also another pertition like data,etc (if you want
to add anythings to this folderd)...but no need to
mount sdcard...For mount system-
mount(“ext4″, “EMMC”, “/
dev/block/mmcblk0p5″, “/system”);
if you want to mount data folder then write data
insted of system like-
mount(“ext4″, “EMMC”, “/
dev/block/mmcblk0p5″, “/data”);
okey...done mounting...
Now see what is mount?
mount – This command mounts the partition, if
you want to add files to system partition you
have to mount system partition, data for data
partition
To mount system - mount(“ext4″, “EMMC”, “/
dev/block/mmcblk0p5″, “/system”);
Here mmcblk0p5 is the name of system
partition for mtk 6589 chipsets (this name
varies from device to device)
To mount data - mount(“ext4″, “EMMC”, “/dev/
block/mmcblk0p7″, “/data”); (partition name
varies from device to device)
_____________________
Now formating...what is format>
format - This command formats the partition
specified
It is highly recommended to include this
command to format system and data if you are
making updater-script for ROM
To Format system - format(“ext4″, “EMMC”, “/
dev/block/mmcblk0p5″, “0″);(partition name
varies from device to device)
To Format data - format(“ext4″, “EMMC”, “/
dev/block/mmcblk0p7″, “0″);(partition name
varies from device to device)
NB.dont use it in your modpacks script its for
custom rom....
_______________________
Now you done mounting and its time to install all
things in all folder thats mean extracting...like
sustem folder will extract in your system
pertition...data folder will be in data pertition
and sdcard folder in your sdcard...for extract
system files use this command>>>
package_extract_file(”system“,”/system”)
for data>>> just delect system and add data like.
package_extract_file(”data“,”/data”)
for sdcard do same...
Now what is this>>>
package_extract_dir(” “, “/”) – This command
extracts all the files from the folder mentioned
inside first quotation to the partition or
directory
inside second quotation
For system - package_extract_dir(“system”, “/
system”);
(this copies all files from system folder in zip to
system partition in phone)
For data - package_extract_dir(“data”, “/
data”);
____________________
Ok now symlink...
symlink("mksh", "/system/bin/sh");
the above command creates a symlink.
okay, now let's see about symlinks,
symlink is nothing but shortcuts, for example if
a file is requiered in two different places instead
of copy pasting the file
in two different locations, the file is copied to
one of the two locations and in the other
location a shortcut to the file(symlink)
is created. the source and the symlink can have
different names (actually this is the prime use
of symlinks).
to explain in a noob friendly manner,
take the above symlink, it creates a shortcut
(symlink) for the command "mksh" and places
it in the path of the operating system.
the shortcut(symlink) directs to the file "/
system/bin/sh" , so whenever the os gets a
request to execute the "mksh" command, the
actual
binary that gets excuted will be "/system/bin/
sh" .
creating symlinks saves a lot of space because
instead of copying the whole file and placing it
in requiered places we are just
creating shortcuts which directs to the source
file which can be placed anywhere in the file
system (generally placed in the path of the os)
i think you understood...if you not then dont
use...its just use then when you want to add
somethings on system/bin folder and its for
advance user..
______________________
ok now seting permission..its not need if you
wont want anything in system/bin...but if add
then you must need add permission for this gile
and seting petmission are really too much easy
and so funny just see what is it and how to
set>>>
set_perm_recursive - This command sets
permission for folders
here android uses unix permission system
in unix
4 – read
2 – write
1 – execute
so
rwx is 4+2+1 = 7
rw is 4+2 = 6
rx is 4+1 = 5
Example - set_perm_recursive(0, 0, 0755,
0644, “/system”);
In this 0 is a user id for owner that refers to
root. It means that permission owner for
system folder. and 0 is root user means it
unrestricted access to system. it is given in
order to run programs to run properly
second 0 also refers to root. but here it refers
to group id 0
we are only seeing about folders because
“set_perm_recursive” is a command that sets
permission to folders
next 0755 it means rwxr-xr-x permission has
been given to system folder and rw-r-r is set
for all folders inside system folder
hope you understan...
___________________
Now another things...and its use in seting
permissions to but its defferent just see>>>
set_perm – This command sets permission for
a specific file
Example - set_perm(1000, 1000, 0640, “/
system/etc/bluetooth/auto_pairing.conf”);
here the 1000 refers to user id system and
0640 is rw-r—–
and this command sets the permission rw-r—–
for the file auto_pairing.conf
this is use for one files auto_praing.conf
__________________
Now you need to unmount these folder which you
mounted...see it>>>
unmount – This command unmounts the
partition
Example - unmount(“/system”); – unmounts
system...you need to unmount another folder
too..like for unmount data>>>
unmount(“/data”);
___________________
ok guys all done...i hope you understood all that i
have told...if you not then ignore it...and now try
to make a script for your modpack...
____________________
now give you a short example of my modpack and
update script...
...................
in my modpack i have these folders>>>
1.meta_inf,
2.data,
3.sdcard,
4.system,
.....now have a look in my script >>>
ui_print("====================
===============");
ui_print("Installing cayno x v2 modpack for all
cayno x users");
ui_print(" ");
ui_print(" By: MD.Shafikul main dev of cayno x ");
ui_print("====================
===============");
ui_print("");
ui_print("mounting system");
show_progress(0.500000, 0);
mount("ext4", "EMMC", "/dev/block/mmcblk0p5", "/
system");
ui_print("mounting data");
mount("ext4", "EMMC", "/dev/block/mmcblk0p5", "/
data");
show_progress(0.200000, 0);
ui_print("[ ] Installing all files");
package_extract_dir("system", "/system");
show_progress(0.200000, 0);
package_extract_dir("data", "/data");
ui_print("installing themes ");
package_extract_dir("sdcard", "/sdcard");
set_perm(0, 1000, 0755, "/system/xbin/busybox");
symlink("/system/xbin/busybox", "/system/bin/
busybox");
ui_print("letast busybox installed");
run_program("/system/xbin/busybox", "--install", "-
s", "/system/xbin");
ui_print("installing abrouted!");
show_progress(0.500000, 0);
set_perm(0, 0, 06755, "/system/xbin/su");
symlink("/system/xbin/su", "/system/bin/su");
set_perm_recursive(0, 0, 0777, 0777, "/system/etc/
init.d");
ui_print("init.d activated!");
ui_print("jocking man... ");
show_progress(0.200000, 0);
unmount("/system");
ui_print("[*] unmount system succeced! ");
unmount("/data");
ui_print("[*] unmount dataoo succeced! ");
unmount("/sdcard");
ui_print("");
ui_print(" Thanks for downloading cayno x ");
ui_print(" Auto rebooting ");
sleep(2);
ui_print(" Please wait... ");
sleep(2);
run_program("/sbin/sleep", "5");
run_program("/sbin/reboot");
^^^^^thats all that i wrote
_______________________________________
NB.(must read)>>>1.General rule in updater-script
– all commands
should end with semi colon ; otherwise it
will show error and if cwm or twrp shows status
7 error the error is in updater-script
2.if you dont understand then ignore beacuse its
can bootlooped...
3.if felt in installing zip then pm me pr comment
here or give me your script i will try my best to
correct it...
4.if the post help you,then give me some
respect...please..
5.dont forget to click on like botton its can
inspared me to write more post...
6.if you copy these post then give me credit,if
you not then i will understood that you are a
busted...
7.and never stop customization
Credit goes to my friend Md. Shafiqul for writting this..
HIT A THANKS IF I HAVE HELPED YOU

permission backup system - TWRP

Hello,
I have a script in TWRP
I trying to take backup of the android system all in: "/system"
into a sdcard "/external_sd/backupOSUmidigiPower"
Code:
ui_print("Start");
run_program("/sbin/busybox", "mount", "/dev/block/mmcblk0p31", "/system");
run_program("/sbin/busybox", "mkdir", "-p", "/external_sd/backupOSUmidigiPower");
run_program("/sbin/busybox", "cp", "-rp", "/system", "/external_sd/backupOSUmidigiPower/");
ui_print("Finish");
That Works very fine and take backup into sd card
But then i trying to take restore backup back to "/system"
but my question is:
1. "Why is my permission gone, see photo"
2. How can i copy all files/folder with permissions
linux cp commands:
Code:
cp
copy with recursion (-r) and (-p) preserve mode,ownership,timestamps
sudo cp -rp <sourceDir> <destDir>
And still got chmod 777 permission on all files/folders
I got bootloop before i think file permission is chmod 777
Can you help me out
Thanks for your time
I experienced that cp command always changes ownership of copied files / directories to root:root regardless of their initial ownership.
jwoegerbauer said:
I experienced that cp command always changes ownership of copied files / directories to root:root regardless of their initial ownership.
Click to expand...
Click to collapse
How can i move files and keep permission?
Moving and Copying are different things.
Don't confuse file's / directory's permissions and file's / directory's ownership: these are different things.

Categories

Resources