update-script syntax - A guide for ROM devs, modders, and themers

Search This thread

sirocyl

Senior Member
Introduction ___________________________________
Android, as it is on HTC devices, has quite an advanced system for installing the OS and updates thereof, not unlike install systems for PC's, like the Windows installer system and NullSoft Install System (NSIS).
"ROM"s for Android aren't necessarily ROMs, but packages. containing files. Technically, a Nandroid backup of a clean install could be considered a ROM.

The update-script file, found in /META-INF/com/google/android/update-script (relative to the package), is necessary for any ROM, no matter how simplistic, to be flashed through the recovery.
icon3.gif
(Nandroid-style, or ROM Flash-images, found in a collection with [system|data|cache|boot|recovery|radio|bootloader|splash|etc.].img files, can usually be flashed using fastboot, or adb/terminal via flash_image, but that is out of the scope of this guide.
They can, however, be flashed through an update.zip file, which will be discussed in detail below.
Goldcards, .nbh files and flashing from the bootloader is not covered; see an unbrick/root guide for details.)

Examples! __________________________
Now that we got that out of the way, let's take a look at an update-script file, from KiNgxKxKlair-Hero-Eclair-v1.3_signed (since I have this readily at hand.) Code abridged somewhat (thousands of symlink commands trimmed off).

Highlight syntax:
Commands bold, black
Functions light-blue
Strings red
Integers/numbers and booleans orange
Variables dark-blue
ROOT: green, bold, path/path green
Equal signs, etc pink
Parentheses light-purple

Code:
[B]assert[/B] [COLOR=DeepSkyBlue]compatible_with[/COLOR][COLOR=Plum]([/COLOR][COLOR=Red]"0.2"[/COLOR][COLOR=Plum])[/COLOR] [COLOR=Magenta]==[/COLOR] [COLOR=Red]"true"[/COLOR]
[B]show_progress[/B] [COLOR=DarkOrange]0.1 0[/COLOR]


[B]format[/B] [B][COLOR=YellowGreen]SYSTEM:[/COLOR][/B]
[B]copy_dir[/B] [B][COLOR=YellowGreen]PACKAGE:[/COLOR][/B][COLOR=YellowGreen]system[/COLOR] [B][COLOR=YellowGreen]SYSTEM:[/COLOR][/B]

[B]symlink[/B][COLOR=YellowGreen] dumpstate [B]SYSTEM:[/B]bin/dumpcrash[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] toolbox [B]SYSTEM:[/B]bin/newfs_msdos[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] toolbox [B]SYSTEM:[/B]bin/renice[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] toolbox[B] SYSTEM:[/B]bin/notify[/COLOR]
[COLOR=Silver][I][----------snip----------][/I][/COLOR]

[B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/zcip[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/zcat[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/yes[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/xargs[/COLOR]
[COLOR=Silver][I][----------snip----------][/I][/COLOR]

[B]set_perm_recursive[/B][COLOR=DarkOrange] 0 0 0755 0644[/COLOR] [B][COLOR=YellowGreen]SYSTEM:[/COLOR][/B]
[B]set_perm_recursive[/B][COLOR=DarkOrange] 0 2000 0755 0755 [/COLOR][COLOR=YellowGreen][B]SYSTEM[/B]:bin[/COLOR]
[B]set_perm_recursive[/B][COLOR=DarkOrange] 0 2000 0755 0755[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]xbin[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 0 3004 02755[/COLOR][COLOR=YellowGreen][B] SYSTEM:[/B]bin/ping[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 0 0 04755[/COLOR][COLOR=YellowGreen][B] SYSTEM:[/B]bin/su[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 0 0 04755 [/COLOR][COLOR=YellowGreen][B]SYSTEM:[/B]xbin/busybox[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 0 0 04755[/COLOR][COLOR=YellowGreen] [B]SYSTEM:[/B]xbin/iptables[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 0 0 04755[/COLOR][COLOR=YellowGreen][B] SYSTEM:[/B]xbin/dnsmasq[/COLOR]

[B]set_perm_recursive[/B][COLOR=DarkOrange] 1002 1002 0755 0440[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/bluez[/COLOR][B]
set_perm[/B][COLOR=DarkOrange] 0 0 0755[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/bluez[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 1002 1002 0440[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/dbus.conf[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 1014 2000 0550[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/dhcpcd/dhcpcd-run-hooks[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 0 2000 0550 [/COLOR][COLOR=YellowGreen][B]SYSTEM:[/B]etc/init.goldfish.sh[/COLOR]
[B]set_perm_recursive[/B][COLOR=DarkOrange] 0 0 0755 0555[/COLOR][COLOR=YellowGreen][B] SYSTEM:[/B]etc/ppp
[/COLOR] 
[B]format[COLOR=YellowGreen] DATA:[/COLOR][/B]
[B]copy_dir[/B][COLOR=YellowGreen][B] PACKAGE:[/B]data [B]DATA:[/B][/COLOR]
[B]symlink[/B][COLOR=YellowGreen] /data/app_s[B] SYSTEM:[/B]app[/COLOR]
[B]symlink[/B] [COLOR=YellowGreen]/data/system-framework[B] SYSTEM:[/B]framework[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 1000 1000 0771[/COLOR][COLOR=YellowGreen][B] DATA:[/B]app
[/COLOR] 
[B]show_progress[/B][COLOR=DarkOrange] 0.2 0[/COLOR]
[B]format[COLOR=YellowGreen] BOOT:[/COLOR][/B]
[B]write_raw_image[COLOR=YellowGreen] PACKAGE:[/COLOR][/B][COLOR=YellowGreen]boot.img [/COLOR][B][COLOR=YellowGreen]BOOT:[/COLOR][/B]
[B]show_progress[/B][COLOR=DarkOrange] 0.2 10[/COLOR]
[B]format[COLOR=YellowGreen] CACHE:[/COLOR][/B]
Whoa :eek:. Lotsa weird numbers and long commands. But it installs a functioning, rooted Eclair Hero, with busybox, on the G1 with all the right permissions, with no hiccups.

Let's pull it apart. :D

How It Works ________________________
The update-script seems greatly over-complicated, but a lot of it is simple (and some can just be copy-pasted as-is to make up the skeleton of the script.

Code:
[B]assert[/B] [COLOR=DeepSkyBlue]compatible_with[/COLOR][COLOR=Plum]([/COLOR][COLOR=Red]"0.2"[/COLOR][COLOR=Plum])[/COLOR]  [COLOR=Magenta]==[/COLOR] [COLOR=Red]"true"[/COLOR]
[B]show_progress[/B] [COLOR=DarkOrange]0.1 0[/COLOR]
The first line here is an "assert", a boolean condition.
If the argument following the assert (a function, command, or "variable" condition) is true, the script continues, otherwise it halts.
icon4.gif
If you are writing an update-script for a recovery that's compatible with specification v0.2 (which I cover here, and is on most modded post-Cupcake recovery systems to date), you MUST include this first line.
The compatible_with() is a function, which itself returns true if "0.2" OR "0.1" is passed to it, in a v0.2-spec recovery (post-Cupcake).

The second line changes the progress-bar fill. It takes two arguments, a fraction and a duration. Half of the progress bar is taken by verification before this point, so the remaining fraction is relative to the second half (1.0 is half, 0.5 is a quarter, and so forth.)
The fraction is relative to 1.0, which is the post-verification progress.
The duration is in seconds, and specifies how slowly the fraction fills.

Code:
[B]format[/B] [B][COLOR=YellowGreen]SYSTEM:[/COLOR][/B]
[B]copy_dir[/B] [B][COLOR=YellowGreen]PACKAGE:[/COLOR][/B][COLOR=YellowGreen]system[/COLOR] [B][COLOR=YellowGreen]SYSTEM:[/COLOR][/B]
This looks easy. Because it is. :p

The format command takes a "root", a.k.a partition name, as its only argument, and does exactly what it says on the tin - formats a "root" clean.
icon4.gif
FORMATTING ERASES DATA IRREVERSIBLY. Just wanted to make that clear, in case it wasn't already.
The available roots are listed in the appendix.

The copy_dir command is also fairly simple. It copies the contents of a folder from one place, to another, making the folder if it doesn't exist.
In this case, it copies from the update package's system folder to /system/.

Code:
[B]symlink[/B][COLOR=YellowGreen] dumpstate [B]SYSTEM:[/B]bin/dumpcrash[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] toolbox [B]SYSTEM:[/B]bin/newfs_msdos[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] toolbox [B]SYSTEM:[/B]bin/renice[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] toolbox[B] SYSTEM:[/B]bin/notify[/COLOR]
[COLOR=Silver][I][----------snip----------][/I][/COLOR]

[B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/zcip[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/zcat[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/yes[/COLOR]
[B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/xargs[/COLOR]
[COLOR=Silver][I][----------snip----------][/I][/COLOR]
These are important, too, especially for a rooted/modded rom. The symlink command takes two arguments. Not quite like your Linux/Unix/POSIX "ln -s" command, since it accepts a ROOT: path syntax. The first argument is taken as-is, though, and can be either of:
- A linux executable that's in the $PATH environment (such as SYSTEM:/bin, :/sbin, :/xbin
- A file somewhere.

The command, in the source code, does the following:
- Counts arguments. Exactly two taken, or fail with error.
- Translates the ROOT: path notation into something POSIX compatible, or fails with an error
- Double-checks that ROOT: is mounted, and mounts, otherwise throws an error and stops
- symlink(argv[0], path) - standard C. Takes the first argument, and the translated ROOT: path, and links the path to the first argument. Or fails with an error.

The first argument is the target, i.e., what to link to.
The second argument is the link itself.

Code:
[B]set_perm_recursive[/B][COLOR=DarkOrange] 1002 1002 0755 0440[/COLOR]  [COLOR=YellowGreen][B]SYSTEM:[/B]etc/bluez[/COLOR][B]
set_perm[/B][COLOR=DarkOrange] 0 0 0755[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/bluez[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 1002 1002 0440[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/dbus.conf[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 1014 2000 0550[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/dhcpcd/dhcpcd-run-hooks[/COLOR]
[B]set_perm[/B][COLOR=DarkOrange] 0 2000 0550 [/COLOR][COLOR=YellowGreen][B]SYSTEM:[/B]etc/init.goldfish.sh[/COLOR]
[B]set_perm_recursive[/B][COLOR=DarkOrange] 0 0 0755 0555[/COLOR][COLOR=YellowGreen][B] SYSTEM:[/B]etc/ppp
[/COLOR]
Permissions. Ugggh. Probably one of the more confusing things here, since if they're set wrong, some parts of, if not the entire Android system, will fail hard.

You have two commands, set_perm and set_perm_recursive. They both set the ownership and UNIX permissions on files; one on a single file, or a folder (not its contents), and the other acts on everything within the folder.

______________________________________________________

Changelog:
v0.1: Initial version, explanation of recovery system and parts of the update-script from King's eclair hero
v0.2: Incomplete still, added more tear-apart of the King update-script. And... SYNTAX HIGLIGHTING!

Will continue on explaining set_perm/_recursive in v0.3, expected later tonight.
 
Last edited:

sirocyl

Senior Member
Appendix A: Roots and Partitions ________
This is a list of all the available roots in the Android recovery, as scoped from roots.c in the source code, and df and mount on the device.

Code:
  ROOT:     (Linux block device) /mountpoint/ fs, size
    Description.

  BOOT:     (/dev/mtdblock[?]) / (RAM)  Raw
    Kernel, ramdisk and  boot config.
  DATA:     (/dev/mtdblock5)   /data/   yaffs2, 91904kb
    User, system config,  app config, and apps (without  a2sd)
  CACHE:    (/dev/mtdblock4)   /cache/  yaffs2, 30720kb
    OTA cache,  Recovery/update config and temp
  MISC:     (/dev/mtdblock[?]) N/A     Raw
    [TODO: Get info on MISC:]
  PACKAGE:  (Relative to package file) N/A
    Pseudo-filesystem for update  package.
  RECOVERY: (/dev/mtdblock[?]) / (RAM) Raw,     [?]kb
    The recovery  and update environment's kernel and ramdisk.
    Similar to BOOT:.
  SDCARD:   (/dev/[B]mmcblk[/B]0(p1)) /sdcard/ fat32,  32MB-32GB
    The microSD card. Update zip is usually here.
  SYSTEM:   (/dev/mtdblock3)   /system/ yaffs2, 92160kb
    The OS partition,    static and read-only.
  TMP:                         /tmp/    in RAM
    Standard Linux temporary directory.
    Cleared on poweroff/reboot.
[TODO: Find mtd partition for BOOT:, RECOVERY:, MISC:]
 
Last edited:

RichieDaze

Senior Member
Jan 18, 2009
486
130
New York City
This is a great topic!

I know most of these commands, but always wanted to perfect my understanding towards it's use in general for different tasks.

Great tut!
 

sirocyl

Senior Member
This is a great topic!

I know most of these commands, but always wanted to perfect my understanding towards it's use in general for different tasks.

Great tut!


Thanks! I knew it would be useful. But I haven't even finished it yet, mainly 'cause I had to dash off to school at the last minute.

I'm going to add to it now that I'm back home. :)
 
Last edited:

adlx.xda

Inactive Recognized Developer
Feb 4, 2010
1,541
1,752
Madrid
Command to remove/delete file/dirs

Great post.

You could also add:

write_radio_image PACKAGE:radio.img

(working for Motorola MB200 Cliq/Dext at least)

I was wondering is there is there any command that can be used in update-script to remove files and/or directories?

Any further reference about this?

Thanks in advance
 

JAguirre1231

Senior Member
Great post.

You could also add:

write_radio_image PACKAGE:radio.img

(working for Motorola MB200 Cliq/Dext at least)

I was wondering is there is there any command that can be used in update-script to remove files and/or directories?

Any further reference about this?

Thanks in advance


Pretty sure to delete it would be

delete SYSTEM:app/Mms.apk


This would remove the stock messaging app for example
 

adlx.xda

Inactive Recognized Developer
Feb 4, 2010
1,541
1,752
Madrid
run sh script from update-script

You can also run a custom #!/sbin/sh script from update-script:

run_program PACKAGE:script.sh

cool!
 

domenukk

Senior Member
Jan 11, 2010
823
31
Agreed. sticky this.
It took me weeks to figure all this out.
This thread is a few months too late :p
Thanks a lot anyway. ;)
 

hadesz

Senior Member
Nov 22, 2007
63
8
Budapest
hello

Can i copy some app to data/app, if data/app is a simlink to /system/sd/app?
Or can I test if the folder SYSTEM:sd/app exists?
And skip or overwrite existing files?
Thanks

OK, I see system/sd is not mounted, then I can't copy apps from update.zip?
 
Last edited:

luca_v3r

Member
Jun 16, 2009
48
2
If I wanted to copy these files for FMRadio (extracted from the ROM Cliq) to my milestone without root, can I run this script through the update. zip?
Is correct?

Thanks!:)


mount("MTD", "system", "/system");
ui_print("Copying in your phone...");

package_extract_file("system/bin/fmradio", "/system/bin/fmradio");
package_extract_file("system/bin/fmradioserver", "/system/bin/fmradioserver");
package_extract_file("system/lib/libFMRadio.so", "/system/lib/libFMRadio.so");
package_extract_file("system/lib/libfmradio_jni.so", "/system/lib/libfmradio_jni.so");
package_extract_file("system/lib/libfmradioplayer.so", "/system/lib/libfmradioplayer.so");
package_extract_file("system/app/FMRadio.apk", "/system/app/FMRadio.apk");

set_perm(0, 0, 04755, "/system/bin/fmradio");
set_perm(0, 0, 04755, "/system/bin/fmradioserver");
set_perm(0, 0, 04755, "/system/bin/libFMRadio.so");
set_perm(0, 0, 04755, "/system/bin/libfmradio_jni.so");
set_perm(0, 0, 04755, "/system/bin/libfmradioplayer.so");
set_perm(0, 0, 0644, "/system/app/FMRadio.apk");

unmount("/system");
 

sirocyl

Senior Member
Simply awesome.....sticky!
This should be a sticky.
Agreed. sticky this.


Sticky? It's not even finished yet! :D
And on that note, I'm sorry I haven't kept up with it. Been busy with non-android junk, school, and my website and projects.
I'll hopefully update later tonight. No promises, but I have this thread on e-mail alert so every post in here is almost like a reminder to me lol

Also, through tearing apart some update-zips I've seen some very useful commands that I haven't covered yet. (Cyanogen is like, an update-script wizard)

It took me weeks to figure all this out.
This thread is a few months too late :p
Thanks a lot anyway. ;)
Great write up.. thank you for putting the time into this!
You're all welcome! Always happy to serve the fellow devs.

You can also run a custom #!/sbin/sh script from update-script:

run_program PACKAGE:script.sh

cool!

I can't believe that I didn't cover that. Will be in next version.

great resource. What language is are these zip files written? There has to be a syntax guide out there.
The update-script is a custom format, implemented by the Android recovery environment. It's actually parsed by (I think) recovery.c using rules in commands.c (not sure, haven't seen that source since I first wrote this up)

If I wanted to copy these files for FMRadio (extracted from the ROM Cliq) to my milestone without root, can I run this script through the update. zip?
Is correct?

Thanks!
I don't have any experience with the Motorola devices, so I wouldn't be certain. It looks alright though.

I might be redoing the write-up for CyanogenMod 5, as it's got better examples of commands and it's way more up-to-date.
Also, I see that a lot of the script structure has changed since I last touched on this subject, from a BASIC-like language to something almost resembling C. I'll be covering that, too.
 

Serris

Senior Member
Feb 10, 2010
530
73
Test chamber No.4
Any help apriciated since I am still new in this stuff, here is the thing I have problem with booting once I flash an update I created. If I flash my update.zip right after I flashed rom, the phone freezes in boot screen, but if I first boot the phone without my update, and then flash update it works normally. Any ideas?

And one more problem if I add "copy_dir PACKAGE:data DATA:" to update-script I always get E:syntax error

Reagards
 

Firerat

Senior Member
Feb 24, 2009
3,848
185
Any help apriciated since I am still new in this stuff, here is the thing I have problem with booting once I flash an update I created. If I flash my update.zip right after I flashed rom, the phone freezes in boot screen, but if I first boot the phone without my update, and then flash update it works normally. Any ideas?

And one more problem if I add "copy_dir PACKAGE:data DATA:" to update-script I always get E:syntax error

Reagards

try a reboot, sometimes it gets 'stuck' and throws that syntax error even if you 'fixed' it
 

animefans

Senior Member
Any help apriciated since I am still new in this stuff, here is the thing I have problem with booting once I flash an update I created. If I flash my update.zip right after I flashed rom, the phone freezes in boot screen, but if I first boot the phone without my update, and then flash update it works normally. Any ideas?

And one more problem if I add "copy_dir PACKAGE:data DATA:" to update-script I always get E:syntax error

Reagards

I have different experience. I have this line, there's no error/warning whatsoever. At the same time, files are not copied over

If it matters, I am using AmonRa Recovery 1.32
and I am packaging in data/local/bin/busybox.bin

I also tried
mount("MTD","data","/data")
package_extract_dir("data","/data")

Still not copy.

However, I do see /data/local/bin/busybox.bin when I go into recovery terminal!. I wonder if my problem is because the real data partition is not mounted in recovery
 

Top Liked Posts

  • There are no posts matching your filters.
  • 26
    Introduction ___________________________________
    Android, as it is on HTC devices, has quite an advanced system for installing the OS and updates thereof, not unlike install systems for PC's, like the Windows installer system and NullSoft Install System (NSIS).
    "ROM"s for Android aren't necessarily ROMs, but packages. containing files. Technically, a Nandroid backup of a clean install could be considered a ROM.

    The update-script file, found in /META-INF/com/google/android/update-script (relative to the package), is necessary for any ROM, no matter how simplistic, to be flashed through the recovery.
    icon3.gif
    (Nandroid-style, or ROM Flash-images, found in a collection with [system|data|cache|boot|recovery|radio|bootloader|splash|etc.].img files, can usually be flashed using fastboot, or adb/terminal via flash_image, but that is out of the scope of this guide.
    They can, however, be flashed through an update.zip file, which will be discussed in detail below.
    Goldcards, .nbh files and flashing from the bootloader is not covered; see an unbrick/root guide for details.)

    Examples! __________________________
    Now that we got that out of the way, let's take a look at an update-script file, from KiNgxKxKlair-Hero-Eclair-v1.3_signed (since I have this readily at hand.) Code abridged somewhat (thousands of symlink commands trimmed off).

    Highlight syntax:
    Commands bold, black
    Functions light-blue
    Strings red
    Integers/numbers and booleans orange
    Variables dark-blue
    ROOT: green, bold, path/path green
    Equal signs, etc pink
    Parentheses light-purple

    Code:
    [B]assert[/B] [COLOR=DeepSkyBlue]compatible_with[/COLOR][COLOR=Plum]([/COLOR][COLOR=Red]"0.2"[/COLOR][COLOR=Plum])[/COLOR] [COLOR=Magenta]==[/COLOR] [COLOR=Red]"true"[/COLOR]
    [B]show_progress[/B] [COLOR=DarkOrange]0.1 0[/COLOR]
    
    
    [B]format[/B] [B][COLOR=YellowGreen]SYSTEM:[/COLOR][/B]
    [B]copy_dir[/B] [B][COLOR=YellowGreen]PACKAGE:[/COLOR][/B][COLOR=YellowGreen]system[/COLOR] [B][COLOR=YellowGreen]SYSTEM:[/COLOR][/B]
    
    [B]symlink[/B][COLOR=YellowGreen] dumpstate [B]SYSTEM:[/B]bin/dumpcrash[/COLOR]
    [B]symlink[/B][COLOR=YellowGreen] toolbox [B]SYSTEM:[/B]bin/newfs_msdos[/COLOR]
    [B]symlink[/B][COLOR=YellowGreen] toolbox [B]SYSTEM:[/B]bin/renice[/COLOR]
    [B]symlink[/B][COLOR=YellowGreen] toolbox[B] SYSTEM:[/B]bin/notify[/COLOR]
    [COLOR=Silver][I][----------snip----------][/I][/COLOR]
    
    [B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/zcip[/COLOR]
    [B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/zcat[/COLOR]
    [B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/yes[/COLOR]
    [B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/xargs[/COLOR]
    [COLOR=Silver][I][----------snip----------][/I][/COLOR]
    
    [B]set_perm_recursive[/B][COLOR=DarkOrange] 0 0 0755 0644[/COLOR] [B][COLOR=YellowGreen]SYSTEM:[/COLOR][/B]
    [B]set_perm_recursive[/B][COLOR=DarkOrange] 0 2000 0755 0755 [/COLOR][COLOR=YellowGreen][B]SYSTEM[/B]:bin[/COLOR]
    [B]set_perm_recursive[/B][COLOR=DarkOrange] 0 2000 0755 0755[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]xbin[/COLOR]
    [B]set_perm[/B][COLOR=DarkOrange] 0 3004 02755[/COLOR][COLOR=YellowGreen][B] SYSTEM:[/B]bin/ping[/COLOR]
    [B]set_perm[/B][COLOR=DarkOrange] 0 0 04755[/COLOR][COLOR=YellowGreen][B] SYSTEM:[/B]bin/su[/COLOR]
    [B]set_perm[/B][COLOR=DarkOrange] 0 0 04755 [/COLOR][COLOR=YellowGreen][B]SYSTEM:[/B]xbin/busybox[/COLOR]
    [B]set_perm[/B][COLOR=DarkOrange] 0 0 04755[/COLOR][COLOR=YellowGreen] [B]SYSTEM:[/B]xbin/iptables[/COLOR]
    [B]set_perm[/B][COLOR=DarkOrange] 0 0 04755[/COLOR][COLOR=YellowGreen][B] SYSTEM:[/B]xbin/dnsmasq[/COLOR]
    
    [B]set_perm_recursive[/B][COLOR=DarkOrange] 1002 1002 0755 0440[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/bluez[/COLOR][B]
    set_perm[/B][COLOR=DarkOrange] 0 0 0755[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/bluez[/COLOR]
    [B]set_perm[/B][COLOR=DarkOrange] 1002 1002 0440[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/dbus.conf[/COLOR]
    [B]set_perm[/B][COLOR=DarkOrange] 1014 2000 0550[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/dhcpcd/dhcpcd-run-hooks[/COLOR]
    [B]set_perm[/B][COLOR=DarkOrange] 0 2000 0550 [/COLOR][COLOR=YellowGreen][B]SYSTEM:[/B]etc/init.goldfish.sh[/COLOR]
    [B]set_perm_recursive[/B][COLOR=DarkOrange] 0 0 0755 0555[/COLOR][COLOR=YellowGreen][B] SYSTEM:[/B]etc/ppp
    [/COLOR] 
    [B]format[COLOR=YellowGreen] DATA:[/COLOR][/B]
    [B]copy_dir[/B][COLOR=YellowGreen][B] PACKAGE:[/B]data [B]DATA:[/B][/COLOR]
    [B]symlink[/B][COLOR=YellowGreen] /data/app_s[B] SYSTEM:[/B]app[/COLOR]
    [B]symlink[/B] [COLOR=YellowGreen]/data/system-framework[B] SYSTEM:[/B]framework[/COLOR]
    [B]set_perm[/B][COLOR=DarkOrange] 1000 1000 0771[/COLOR][COLOR=YellowGreen][B] DATA:[/B]app
    [/COLOR] 
    [B]show_progress[/B][COLOR=DarkOrange] 0.2 0[/COLOR]
    [B]format[COLOR=YellowGreen] BOOT:[/COLOR][/B]
    [B]write_raw_image[COLOR=YellowGreen] PACKAGE:[/COLOR][/B][COLOR=YellowGreen]boot.img [/COLOR][B][COLOR=YellowGreen]BOOT:[/COLOR][/B]
    [B]show_progress[/B][COLOR=DarkOrange] 0.2 10[/COLOR]
    [B]format[COLOR=YellowGreen] CACHE:[/COLOR][/B]
    Whoa :eek:. Lotsa weird numbers and long commands. But it installs a functioning, rooted Eclair Hero, with busybox, on the G1 with all the right permissions, with no hiccups.

    Let's pull it apart. :D

    How It Works ________________________
    The update-script seems greatly over-complicated, but a lot of it is simple (and some can just be copy-pasted as-is to make up the skeleton of the script.

    Code:
    [B]assert[/B] [COLOR=DeepSkyBlue]compatible_with[/COLOR][COLOR=Plum]([/COLOR][COLOR=Red]"0.2"[/COLOR][COLOR=Plum])[/COLOR]  [COLOR=Magenta]==[/COLOR] [COLOR=Red]"true"[/COLOR]
    [B]show_progress[/B] [COLOR=DarkOrange]0.1 0[/COLOR]
    The first line here is an "assert", a boolean condition.
    If the argument following the assert (a function, command, or "variable" condition) is true, the script continues, otherwise it halts.
    icon4.gif
    If you are writing an update-script for a recovery that's compatible with specification v0.2 (which I cover here, and is on most modded post-Cupcake recovery systems to date), you MUST include this first line.
    The compatible_with() is a function, which itself returns true if "0.2" OR "0.1" is passed to it, in a v0.2-spec recovery (post-Cupcake).

    The second line changes the progress-bar fill. It takes two arguments, a fraction and a duration. Half of the progress bar is taken by verification before this point, so the remaining fraction is relative to the second half (1.0 is half, 0.5 is a quarter, and so forth.)
    The fraction is relative to 1.0, which is the post-verification progress.
    The duration is in seconds, and specifies how slowly the fraction fills.

    Code:
    [B]format[/B] [B][COLOR=YellowGreen]SYSTEM:[/COLOR][/B]
    [B]copy_dir[/B] [B][COLOR=YellowGreen]PACKAGE:[/COLOR][/B][COLOR=YellowGreen]system[/COLOR] [B][COLOR=YellowGreen]SYSTEM:[/COLOR][/B]
    This looks easy. Because it is. :p

    The format command takes a "root", a.k.a partition name, as its only argument, and does exactly what it says on the tin - formats a "root" clean.
    icon4.gif
    FORMATTING ERASES DATA IRREVERSIBLY. Just wanted to make that clear, in case it wasn't already.
    The available roots are listed in the appendix.

    The copy_dir command is also fairly simple. It copies the contents of a folder from one place, to another, making the folder if it doesn't exist.
    In this case, it copies from the update package's system folder to /system/.

    Code:
    [B]symlink[/B][COLOR=YellowGreen] dumpstate [B]SYSTEM:[/B]bin/dumpcrash[/COLOR]
    [B]symlink[/B][COLOR=YellowGreen] toolbox [B]SYSTEM:[/B]bin/newfs_msdos[/COLOR]
    [B]symlink[/B][COLOR=YellowGreen] toolbox [B]SYSTEM:[/B]bin/renice[/COLOR]
    [B]symlink[/B][COLOR=YellowGreen] toolbox[B] SYSTEM:[/B]bin/notify[/COLOR]
    [COLOR=Silver][I][----------snip----------][/I][/COLOR]
    
    [B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/zcip[/COLOR]
    [B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/zcat[/COLOR]
    [B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/yes[/COLOR]
    [B]symlink[/B][COLOR=YellowGreen] busybox[B] SYSTEM:[/B]xbin/xargs[/COLOR]
    [COLOR=Silver][I][----------snip----------][/I][/COLOR]
    These are important, too, especially for a rooted/modded rom. The symlink command takes two arguments. Not quite like your Linux/Unix/POSIX "ln -s" command, since it accepts a ROOT: path syntax. The first argument is taken as-is, though, and can be either of:
    - A linux executable that's in the $PATH environment (such as SYSTEM:/bin, :/sbin, :/xbin
    - A file somewhere.

    The command, in the source code, does the following:
    - Counts arguments. Exactly two taken, or fail with error.
    - Translates the ROOT: path notation into something POSIX compatible, or fails with an error
    - Double-checks that ROOT: is mounted, and mounts, otherwise throws an error and stops
    - symlink(argv[0], path) - standard C. Takes the first argument, and the translated ROOT: path, and links the path to the first argument. Or fails with an error.

    The first argument is the target, i.e., what to link to.
    The second argument is the link itself.

    Code:
    [B]set_perm_recursive[/B][COLOR=DarkOrange] 1002 1002 0755 0440[/COLOR]  [COLOR=YellowGreen][B]SYSTEM:[/B]etc/bluez[/COLOR][B]
    set_perm[/B][COLOR=DarkOrange] 0 0 0755[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/bluez[/COLOR]
    [B]set_perm[/B][COLOR=DarkOrange] 1002 1002 0440[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/dbus.conf[/COLOR]
    [B]set_perm[/B][COLOR=DarkOrange] 1014 2000 0550[/COLOR] [COLOR=YellowGreen][B]SYSTEM:[/B]etc/dhcpcd/dhcpcd-run-hooks[/COLOR]
    [B]set_perm[/B][COLOR=DarkOrange] 0 2000 0550 [/COLOR][COLOR=YellowGreen][B]SYSTEM:[/B]etc/init.goldfish.sh[/COLOR]
    [B]set_perm_recursive[/B][COLOR=DarkOrange] 0 0 0755 0555[/COLOR][COLOR=YellowGreen][B] SYSTEM:[/B]etc/ppp
    [/COLOR]
    Permissions. Ugggh. Probably one of the more confusing things here, since if they're set wrong, some parts of, if not the entire Android system, will fail hard.

    You have two commands, set_perm and set_perm_recursive. They both set the ownership and UNIX permissions on files; one on a single file, or a folder (not its contents), and the other acts on everything within the folder.

    ______________________________________________________

    Changelog:
    v0.1: Initial version, explanation of recovery system and parts of the update-script from King's eclair hero
    v0.2: Incomplete still, added more tear-apart of the King update-script. And... SYNTAX HIGLIGHTING!

    Will continue on explaining set_perm/_recursive in v0.3, expected later tonight.
    3
    Yes you can! both ways are possible.


    This is also possible.


    If and then statements are supported.

    Code:
    if assert(getprop("ro.product.device") == "trout");
    then 
    # Boot
      ui_print("-Writing boot.img");
        assert(package_extract_file("boot.img", "/tmp/boot.img"),
    	  write_raw_image("/tmp/boot.img", "boot"),
    	  delete("/tmp/boot.img"));
    endif

    Code:
    assert(package_extract_file("trout.img", "/tmp/boot.img")
    better demonstrates how it can be used

    have another if statement and sub droid for trout

    perfect example here
    ( but in python, as it is part of a source build )

    https://github.com/ezterry/GB-devic...mmit/30ae9e66cb0408f649139651a7a6237e54dd7775

    lots of stuff in that, but you can hopefully see whats going on
    2
    Appendix A: Roots and Partitions ________
    This is a list of all the available roots in the Android recovery, as scoped from roots.c in the source code, and df and mount on the device.

    Code:
      ROOT:     (Linux block device) /mountpoint/ fs, size
        Description.
    
      BOOT:     (/dev/mtdblock[?]) / (RAM)  Raw
        Kernel, ramdisk and  boot config.
      DATA:     (/dev/mtdblock5)   /data/   yaffs2, 91904kb
        User, system config,  app config, and apps (without  a2sd)
      CACHE:    (/dev/mtdblock4)   /cache/  yaffs2, 30720kb
        OTA cache,  Recovery/update config and temp
      MISC:     (/dev/mtdblock[?]) N/A     Raw
        [TODO: Get info on MISC:]
      PACKAGE:  (Relative to package file) N/A
        Pseudo-filesystem for update  package.
      RECOVERY: (/dev/mtdblock[?]) / (RAM) Raw,     [?]kb
        The recovery  and update environment's kernel and ramdisk.
        Similar to BOOT:.
      SDCARD:   (/dev/[B]mmcblk[/B]0(p1)) /sdcard/ fat32,  32MB-32GB
        The microSD card. Update zip is usually here.
      SYSTEM:   (/dev/mtdblock3)   /system/ yaffs2, 92160kb
        The OS partition,    static and read-only.
      TMP:                         /tmp/    in RAM
        Standard Linux temporary directory.
        Cleared on poweroff/reboot.
    [TODO: Find mtd partition for BOOT:, RECOVERY:, MISC:]
    2
    Can either the updater-script and/or a shell script determine what type of phone is being used?
    Yes you can! both ways are possible.

    I am trying to see if there is a way to have the script check what type of phone it is running on, and then perform commands according to that type of phone;
    This is also possible.

    maybe with an if and only if statement?
    If and then statements are supported.

    Code:
    if assert(getprop("ro.product.device") == "trout");
    then 
    # Boot
      ui_print("-Writing boot.img");
        assert(package_extract_file("boot.img", "/tmp/boot.img"),
    	  write_raw_image("/tmp/boot.img", "boot"),
    	  delete("/tmp/boot.img"));
    endif
    2
    A little more explanation on permissions would be nice. :)

    Code:
    set_perm_recursive 1002 1002 0755 0440  SYSTEM:etc/bluez
    Code:
    set_perm_recursive <owner> <group> <dir permission> <permission of files/dir below dir> <file/dir to operate on>

    Code:
    set_perm 0 0 0755 SYSTEM:etc/bluez
    Code:
    set_perm <owner> <group> <permission of files/dir below dir> <file/dir to operate on>