Jump to content


Photo

ClockWorkMod recovery version 3 or higher Scripting Tutorial

- - - - -

  • Please log in to reply
10 replies to this topic

#1
Phoenix Silver

Phoenix Silver

    Hardcore

  • MoDaCo Silver
  • PipPipPipPipPipPip
  • 1,839 posts
  • Gender:Female
  • Location:Strasbourg.
  • Devices:ZTE Blade Orange France
  • Twitter:@phoenixbjp
This guide is a reference of the commands used in Clockworkmod.
For Edify and not Amend (Cwm 3 or higher).


Structure


First thing you need to download this file : clockworkmod_skeleton.zip

Download it here :

http://ftpb.free.fr/...oads/photom.php

The structure is :

META-INF
    |______com
            |______google
                      |______android
                                 |______updater-script
                                 |______update-binary
system (optional)
data (optional)

It's updater-script you modify to run your scripts in clockworkmod





Commands reference :


Assert

Assert("function");



Mount

mount(fs_type, partition_type, location, mount_point);

2 choices of fs_type

fs_type="yaffs2" partition_type="MTD" location=partition
fs_type="ext4" partition_type="EMMC" location=device

For an ex to mount the system partition to install programs insert this line in the script

mount("yaffs2", "MTD", "system", "/system");



Unmount

unmount("partition");

unmount the partitions you have mounted with mount

To follow the ex earlier :

unmount("/system");

you need to unmount partitions in the inverse order of the mount.



Is_mounted

is_mounted(mount_point);



Format

format(fs_type, partition_type, location);


2 choices of fs_type

fs_type="yaffs2" partition_type="MTD" location=partition
fs_type="ext4" partition_type="EMMC" location=device

For an ex format the data partition

format("yaffs2", "MTD", "userdata");



Ui_print

ui_print("text");

Print text in screen.

ex :

ui_print("Installing boot.img");



Package_extract_dir

package_extract_dir(package_path, destination_path);

Extract a directory for an ex :

package_extract_dir("system", "/system");



Package_extract_file

package_extract_file(package_path, destination_path);

Extract a single file for an ex :

package_extract_file("boot.img", "/tmp/boot.img");



Symlink

symlink target src1 src2 ...
unlinks any previously existing src1, src2, etc before creating symlinks.



File_getprop

file_getprop(file, key);

interprets 'file' as a getprop-style file (key=value pairs, one per line, # comment lines and blank lines okay), and returns the value
for 'key' (or "" if it isn't defined).



Write_raw_image

write_raw_image(file, partition);

Flash img file in its partition

For an ex to flash a kernel just use

write_raw_image("/tmp/boot.img", "boot");



Apply_patch_space

apply_patch_space(bytes);



Apply_patch

apply_patch(srcfile, tgtfile, tgtsha1, tgtsize, sha1_1, patch_1, ...);



Apply_patch_check

apply_patch_check(file, [sha1_1, ...]);



Sha1_check

sha1_check(data);

to return the sha1 of the data (given in the format returned by read_file).



Delete

delete("File");

Delete a file

For an ex :

delete("/tmp/boot.img");



Delete_recursive

delete_recursive("directory");

Delete a directory

For an exe :

delete_recursive("/system/lib/modules");
delete the directory modules in system/lib



Show_progress

show_progress(param1,param2);



Set_perm

set_perm(param1,param2,param3,"file");

Set the permissions of a file. For an ex :

set_perm(0,0,755,"/tmp/checksys.sh");



Run_program

run a program for an ex :

run_program("/tmp/checksys.sh");



IF...THEN...ELSE...ENDIF

If condition do action else do another action endif;

for an ex :

if file_getprop("/tmp/nfo.prop","ramconsole") == "9"
then 
      #Gen1
      ui_print("Extracting Gen1 kernel");
      package_extract_file("gen1.img","/tmp/boot.img");
else
      #Gen2
      ui_print("Extracting Gen2 kernel");
      package_extract_file("gen2.img","/tmp/boot.img");
endif;



==

Compare 2 values.

For an ex :

If value1 == value2 then ......



#

To write a comment in the script.

#This is a comment.

Edited by Phoenix Silver, 01 September 2011 - 07:40 PM.

  • 3
Si le corps est mortel, l’âme elle est éternelle.

#2
Phoenix Silver

Phoenix Silver

    Hardcore

  • MoDaCo Silver
  • PipPipPipPipPipPip
  • 1,839 posts
  • Gender:Female
  • Location:Strasbourg.
  • Devices:ZTE Blade Orange France
  • Twitter:@phoenixbjp
Reserved

Guide under construction. Some commands are uncompleted. So if you know what it means or have exs feel free to indicate it and i'll update the guide.
Ty.

  • 1
Si le corps est mortel, l’âme elle est éternelle.

#3
t0mm13b

t0mm13b

    Hardcore

  • MoDaCo Silver
  • PipPipPipPipPipPip
  • 1,784 posts
  • Gender:Male
  • Location:Ireland
  • Devices:GT-S8500,Zte Blade,SE ST15i
  • Twitter:@t0mm13b
Nice job darling :)

  • 0
try{ not_laugh; }catch{ FAIL; }finally{ laugh; }

#4
Sebastian404

Sebastian404

    Hardcore

  • Developer Team
  • PipPipPipPipPipPip
  • 2,104 posts
  • Gender:Male
  • Location:Somwhere Near Mountain View, California
  • Devices:lots of them
  • Twitter:@sebastian404
its about time someone wrote one, but you might want to mention this is for Edify and not Amend...

  • 0

#5
Phoenix Silver

Phoenix Silver

    Hardcore

  • MoDaCo Silver
  • PipPipPipPipPipPip
  • 1,839 posts
  • Gender:Female
  • Location:Strasbourg.
  • Devices:ZTE Blade Orange France
  • Twitter:@phoenixbjp

its about time someone wrote one, but you might want to mention this is for Edify and not Amend...

Yes you are right it's for Cwm version 3 or higher.

  • 0
Si le corps est mortel, l’âme elle est éternelle.

#6
KonstaT

KonstaT

    Hardcore

  • Developer Team
  • PipPipPipPipPipPip
  • 2,328 posts
  • Gender:Male
  • Location:Finland
  • Devices:Moto G, ZTE Blade III
Good job. Where was this when I started learning this. ;)

I think that the topic tittle could be changed to ClockWorkMod Edify Scripting Tutorial or something like that. Didn't understand what it was about until I looked in.

There's nothing much to add besides set_perm_recursive(param1,param2,param3,"directory"). Unmount should also be unmount(), not umount like elsewhere. I also read somewhere that if you mount more than one partition, you should unmount them in reverse order. I don't know if makes any difference though...


  • 0

#7
t0mm13b

t0mm13b

    Hardcore

  • MoDaCo Silver
  • PipPipPipPipPipPip
  • 1,784 posts
  • Gender:Male
  • Location:Ireland
  • Devices:GT-S8500,Zte Blade,SE ST15i
  • Twitter:@t0mm13b

Good job. Where was this when I started learning this. ;)

I think that the topic tittle could be changed to ClockWorkMod Edify Scripting Tutorial or something like that. Didn't understand what it was about until I looked in.

There's nothing much to add besides set_perm_recursive(param1,param2,param3,"directory"). Unmount should also be unmount(), not umount like elsewhere. I also read somewhere that if you mount more than one partition, you should unmount them in reverse order. I don't know if makes any difference though...


Yes in that regard to the mount order - that is true... its a LIFO (Last In, First Out) type of order for example:
mount("yaffs2", "MTD", "system", "/system");
mount("yaffs2", "MTD", "data", "/data");
....
umount("/data");
umount("/system");

Notice the ordering, if it was in the reverse as in

umount("/system");
umount("/data");

From what I recall, this can cause problems with the script....

  • 0
try{ not_laugh; }catch{ FAIL; }finally{ laugh; }

#8
Phoenix Silver

Phoenix Silver

    Hardcore

  • MoDaCo Silver
  • PipPipPipPipPipPip
  • 1,839 posts
  • Gender:Female
  • Location:Strasbourg.
  • Devices:ZTE Blade Orange France
  • Twitter:@phoenixbjp

Good job. Where was this when I started learning this. ;)

I think that the topic tittle could be changed to ClockWorkMod Edify Scripting Tutorial or something like that. Didn't understand what it was about until I looked in.

There's nothing much to add besides set_perm_recursive(param1,param2,param3,"directory"). Unmount should also be unmount(), not umount like elsewhere. I also read somewhere that if you mount more than one partition, you should unmount them in reverse order. I don't know if makes any difference though...

Oki ty for your feedback :)
Updated

Edited by Phoenix Silver, 01 September 2011 - 07:41 PM.

  • 0
Si le corps est mortel, l’âme elle est éternelle.

#9
vNa5h

vNa5h

    Addict

  • Members
  • PipPipPipPipPip
  • 774 posts
  • Gender:Male
  • Location:India
  • Devices:Dell XCD35 (ZTE Blade)

Oki ty for your feedback :)
Updated



what about mount with 3 args

  • 0

Dell XCD35 a.k.a ZTE Blade a.k.a Orange San Fransisco

Powered by

CM10.1 KonstaKANG, Soundmagic PL11 earphones, Samsung class 6 16GB



Apps installed

TV Shows / Movies .....I have watched....


#10
the_crevis

the_crevis

    Enthusiast

  • Members
  • PipPipPip
  • 286 posts
  • Gender:Male
  • Devices:LG Nexus 4, ZTE Crescent
  • Twitter:@the_crevis
Just don't put the yaffs2/ext4 part

  • 0
LG Nexus 4 (daily driver) - CM10.2
ZTE Crescent (backup) - CM9
ZTE Blade - Deceased
If I helped you at all then remember to hit that green up arrow! Posted Image

#11
Adilson

Adilson

    Regular

  • Members
  • PipPip
  • 62 posts
  • Devices:Dell Steak, Motorola Milestone
This sqaved my day, thanks!
I have a question tough. Is there a way to automate the script, I.E. making clockworkmod start it without any manual intervention? My problem is, I want to automate a rescue procedure that will clena the user's data and install some aditional software.

  • 0




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users