[Android Software/Hacking General [Developers Only]] osm0sis:
Included Functions:

ui_print "<message>" ["<message 2>" ...]
show_progress <amount> <time>
set_progress <amount>
sleep <seconds>

is_substring <substring> <string>
less_than_int <x> <y>
greater_than_int <x> <y>

mount <partition>
unmount <partition>
is_mounted <partition>

write_raw_image <file> <block>

package_extract_file <file> <destination_file>
package_extract_dir <dir> <destination_dir>

rename <file> <destination_file>

delete <file> [<file2> ...]
delete_recursive <dir> [<dir2> ...]

symlink <file/dir> <link> [<link2> ...]

set_metadata <file> <uid|gid|mode|capabilities|selabel> <value> [<uid|gid|mode|capabilities|selabel_2> <value2> ...]
set_metadata_recursive <dir> <uid|gid|dmode|fmode|capabilities|selabel> <value> [<uid|gid|dmode|fmode|capabilities|selabel_2> <value2> ...]

set_perm <owner> <group> <mode> <file> [<file2> ...]
set_perm_recursive <owner> <group> <dir_mode> <file_mode> <dir> [<dir2> ...]

ch_con <context> <file> [<file2> ...]
ch_con_recursive <dir_context> <file_context> <dir> [<dir2> ...]
restore_con <file/dir> [<file2/dir2> ...]

file_getprop <file> <property>
getprop <property>

sha1_check <file> [<sha1_hex> [<sha1_hex2> ...]]

apply_patch <src_file> <tgt_file> <tgt_sha1> <tgt_size> [<src_sha1_1>:<patch1> [<src_sha1_2>:<patch2> ...]]
apply_patch_check <file> [<sha1_hex> [<sha1_hex2> ...]]
apply_patch_space <bytes>

abort [<message>]
assert "<command>" ["<command2>"]

backup_files <file> [<file2> ...]
restore_files <file> [<file2> ...]

* set_metadata/set_metadata_recursive capabilities may require the setcap binary built from AOSP's libcap source if your recovery does not support it.

Other Script Additions/Notes:

Embedded Zips: If your script is possibly going to be embedded in a ROM zip install (ie. from a ROM kitchen), then there is a chunk of script you'll want to include: http://xdaforums.com/showpost.php?p=64929134&postcount=501

User Choice: If your script requires the user to make some simple yes/no decisions, this can be accomplished using the timeout and keycheck utilities, and the second script function from this page (thanks @Zappo): https://xdaforums.com/showpost.php?p=71016567&postcount=98

Systemless Root: If your script needs access to the su.img /su mount filesystem created by a systemless SuperSU installation, the second chunk of script on this page will handle that so you can treat it like a normal filesystem from then on: http://xdaforums.com/showpost.php?p=64929134&postcount=501

Magisk/BINDSBIN SuperSU Systemless Root: If your script needs access to the magisk.img /magisk mount filesystem created by a Magisk installation or /sbin/supersu from BINDSBIN SuperSU (default on Android Oreo), these updated snippets will handle that so you can treat it like a normal filesystem from then on: https://xdaforums.com/showpost.php?p=73542799&postcount=1438

Systemless Mod Expansion: If your script needs a substantial amount of space in the su.img /su mount filesystem created by a systemless SuperSU installation, the script on this page will handle expanding the su.img by 32M over whatever the current size is to accommodate multiple sizable mods installed at the same time: http://xdaforums.com/showpost.php?p=67862346&postcount=750

System-As-Root (SAR): If your script needs to mount /system_root and bind mount over /system and/or give access to working /system binaries on SAR devices while in recovery, the script on this page attempts to make all that happen for you: https://xdaforums.com/t/dev-templat...-signing-script.2934449/page-23#post-84272713

Zip Signing:

Because they're not being unzipped directly by the recovery, shell zips must use busybox unzip to unpack, and this can lead to problems with zip flag errors once signed since the busybox unzip isn't full featured. Thanks to @topjohnwu's exceptional work streamlining all the previous required tools (and the testkeys) into one called "zipsigner" for his Magisk installer, now it's the only requirement, works for shell and EDIFY-based flashable zips, and works on zips of any size on pretty much any hardware without any memory issues! It can be grabbed from the attachments. Thanks @topjohnwu for the compiled zipsigner jar.

zipsigner
---------
https://github.com/topjohnwu/Magisk/tree/v20.4/signing

*zipsigner* Java source is at the above Magisk repo subdirectory,
which compiles to *zipsigner-3.0.jar*

Example Usage
-------------

7za a -tzip -r build.zip .\build\*

java -jar zipsigner-3.0.jar build.zip build-signed.zip

It can be run on device when booted using the dexed version I have also attached and with the following command:

dalvikvm -Djava.io.tmpdir=. -Xnodex2oat -Xnoimage-dex2oat -cp zipsigner-3.0-dexed.jar com.topjohnwu.utils.ZipSigner build.zip build-signed.zip

To run from recovery of course /system will just need to be mounted so dalvikvm can be executed.

I've released a zip installer + Magisk module to add the dexed zipsigner.jar (plus a wrapper to run the above command), zip and zipalign to any device. See my Odds and Ends thread.

TKruzze has also created an excellent utility for Windows to automate this process, and can be triggered from a right-click context menu! See the Zip Builder thread for more info.

The old shell zip procedure and my ZipScriptSign packages are now superseded entirely, but are preserved in the Hide tag below for any interested.

This was cobbled together from Chainfire's OpenDelta README, notes, and my own experimentation with TKruzze on the shell PA GApps 2.0, and circumvents this issue using some handy tools Chainfire created.

zipadjust
---------
https://github.com/omnirom/android_packages_apps_OpenDelta/tree/android-5.0/jni

*zipadjust* can be built by calling:

gcc -o zipadjust zipadjust.c zipadjust_run.c -lz -static

minsignapk
----------
https://github.com/omnirom/android_packages_apps_OpenDelta/tree/android-5.0/server

*minsignapk* Java source is included, as well as a prebuilt
*minsignapk.jar* file that should work on most systems

Example Usage (desired contents in subdirectory "build")
-------------

7za a -tzip -r build-unsigned.zip .\build\*

java -jar signapk.jar test.certificate.x509.pem test.key.pk8 build-unsigned.zip build.zip

zipadjust build.zip build-fixed.zip

java -jar minsignapk.jar test.certificate.x509.pem test.key.pk8 build-fixed.zip build-signed.zip

Attached are Win32 and Linux32 compiles of zipadjust and automation scripts to make the zip script signing process easy. See the instructions for more info.

References:

[TUTORIAL] Making Flashable ZIPs, EDIFY Script, ZIP Signing & Key Creation (and the further linked references)

[TRICK/EDIFY] Output To Recovery UI from Shell Script

[ROOT] SuperSU - Post re: Zip Signing