[Android General] jostrus:
Regular Expression Macro for Notepad++ to Convert updater-script to shell script

This is a list of the Regular Expressions I used for quick conversion of an updater script inside the OTA zip. The basic idea is to extract the system folder from the OTA zip and place in a formatted partition or image file. Then you run the script and it sets the appropriate permissions and creates symlinks as the updater script would. The conversion makes one major assumption. Symlink commands either have 1 or 2 parameters (except for toolbox). For the case of toolbox the regex matches and does some qwerky magic to handle the crazy long list of links. This could be done for all symlink lines however I designed this to be used with Notepad++ to be setup in a macro. I have included the said macro as well.

This will probably work on any region script but I only tested on the US version.

If you want to just use my pre-made macro View attachment Notepad++_shortcuts.zip download the zip and extract the shortcuts.xml. Place it in your Notepad++ configuration folder. On Windows 7/8 that is %APPDATA%\Notepad++. If you do not have any existing macros or program launching shortcuts you can just overwrite an existing file. If you have some you'll need to manually edit and merge the macro. Instructions for such are beyond the scope of this post.

The macro does the following:

For the replace lines with <nothing> that means blank.

The next 2 join split lines. I've underlined the next line to note the spaces in
the search text. This is not underscore characters. For those that care it is
eight (8) spaces.
Search: [U]\n [/U]
Replace: <nothing>

Search: \n"
Replace: "

This next one deletes all *unsupported* command lines.
Search: ^(?:(?!symlink|set_perm|set_perm_recursive).)*$\r?\n?
Replace: <nothing>

Create and single symlinks
Search: ^symlink\(("[^"]+"), ?("[^"]+")\);
Replace: ln -s \1 \2

Create and 2 file symlinks
Search: ^symlink\(("[^"]+"), ?("[^"]+"), ?("[^"]+")\);
Replace: ln -s \1 \2\nln -s \1 \3

Set recursive permissions
Search: ^set_perm_recursive\((\d+), ?(\d+), ?(\d+), ?(\d+), ?("[^"]+")\);
Replace: chown -R \1\:\2 \5\nchmod -R \4 \5\nfind \5 -type d -exec chmod -R \3 '{}' \\;

Set single target permissions
Search: ^set_perm\((\d+), ?(\d+), ?(\d+), ?("[^"]+")\);
Replace: chown -R \1\:\2 \4\nchmod -R \3 \4

The rest is all to generate the symlinks for toolbox. It's a slightly round about
way of handling the variable length parameters.
Search: ^symlink\("toolbox", ?([^)]+)\);
Replace: |\1

Search to select: ^\|"(.*)"$

Search in Selection: ", ?"
Replace in selection: "\n|"

Search in Selection: ^\|"(.*)"$
Replace in selection: ln -s "toolbox" "\1"

This does not (deliberately) add the hash bang (#!) to enable making the script executable. I feel deliberately requiring one to run sh/csh/bash <script name> is a safer way to protect the less knowledgable.

This does assume that the folder your extracted system data will be in is at /system. You would need to do another search and replace if you wanted to use a different location and still use the script.

Edit: Fixed replacement match index on single target which was referencing invalid parameter resulting in no filename being produced. Updated attachment as well.