### APatch customize.sh Utility Functions Source: https://apatch.dev/zh_CN/apm-guide This details the utility functions available within the `customize.sh` script for APatch module installations. It includes functions for printing messages to the console (`ui_print`, `print`), aborting the installation with an error message (`abort`), and setting file permissions and SELinux contexts recursively (`set_perm`, `set_perm_recursive`). ```txt ui_print print to console Avoid using 'echo' as it will not display in custom recovery's console abort print error message to console and terminate the installation Avoid using 'exit' as it will skip the termination cleanup steps set_perm [context] if [context] is not set, the default is "u:object_r:system_file:s0" this function is a shorthand for the following commands: chown owner.group target chmod permission target chcon context target set_perm_recursive [context] if [context] is not set, the default is "u:object_r:system_file:s0" for all files in , it will call: set_perm file owner group filepermission context for all directories in (including itself), it will call: set_perm dir owner group dirpermission context ``` -------------------------------- ### APatch: 模块脚本执行 Source: https://apatch.dev/zh_CN/apm-guide 模块脚本(如 `post-fs-data.sh`, `post-mount.sh`, `service.sh`, `boot-completed`)放置在模块自身目录中,仅当模块启用时执行。它们根据文件名自动匹配不同的启动模式。 ```shell # 示例:模块内的 service.sh 将以 late_start 服务模式运行 # 模块路径/service.sh ``` -------------------------------- ### APatch Module Structure Source: https://apatch.dev/zh_CN/apm-guide This illustrates the basic file structure of an APatch module zip package. It highlights the optional `customize.sh` script, which is essential for controlling the installation process, and indicates where other module files would reside. ```txt module.zip │ ├── customize.sh <--- (Optional, more details later) │ This script will be sourced by update-binary ├── ... ├── ... /* 其他模块文件 */ │ ``` -------------------------------- ### APatch: 通用脚本执行权限 Source: https://apatch.dev/zh_CN/apm-guide 通用脚本(放置在 `/data/adb/` 下的 `.d` 目录中)需要被设置为可执行权限才能运行。使用 `chmod +x script.sh` 命令可以赋予脚本执行权限。 ```shell chmod +x /data/adb/post-fs-data.d/your_script.sh chmod +x /data/adb/service.d/your_script.sh ``` -------------------------------- ### APatch Module Structure Source: https://apatch.dev/zh_CN/apm-guide Defines the directory structure for an APatch module, including configuration files, system modifications, marker files, and optional execution scripts. The system folder is typically mounted to the system partition. ```text /data/adb/modules ├── . ├── . | ├── $MODID <--- 模块的文件夹名称与模块 ID 相同 │ │ │ │ *** 模块配置文件 *** │ │ │ ├── module.prop <--- 此文件保存模块相关的一些配置,如模块 ID、版本等 │ │ │ │ *** 模块内容 *** │ │ │ ├── system <--- 这个文件夹通常会被挂载到系统 │ │ ├── ... │ │ ├── ... │ │ └── ... │ │ │ │ *** 标记文件 *** │ │ │ ├── skip_mount <--- 如果这个文件存在,那么模块的 `/system` 将不会被挂载 │ ├── disable <--- 如果这个文件存在,那么模块会被禁用 │ ├── remove <--- 如果这个文件存在,下次重启的时候模块会被移除 │ │ │ │ *** 可选文件 *** │ │ │ ├── post-fs-data.sh <--- 这个脚本将会在 post-fs-data 模式下运行 │ ├── post-mount.sh <--- 这个脚本将会在 post-mount 模式下运行 │ ├── service.sh <--- 这个脚本将会在 late_start 服务模式下运行 │ ├── boot-completed.sh <--- 这个脚本将会在 Android 系统启动完毕后以服务模式运行 | ├── uninstall.sh <--- 这个脚本将会在模块被卸载时运行 | ├── action.sh <--- 这个脚本将会在管理器模块中点击 Action 时运行 | ├── system.prop <--- 这个文件中指定的属性将会在系统启动时通过 resetprop 更改 | ├── sepolicy.rule <--- 这个文件中的 SELinux 策略将会在系统启动时加载 │ │ │ │ *** 自动生成的目录,不要手动创建或者修改! *** │ │ │ ├── vendor <--- A symlink to $MODID/system/vendor │ ├── product <--- A symlink to $MODID/system/product │ ├── system_ext <--- A symlink to $MODID/system/system_ext │ │ │ │ *** Any additional files / folders are allowed *** │ │ │ ├── ... │ └── ... | ├── another_module │ ├── . │ └── . ├── . ├── . ``` -------------------------------- ### Getting Module Directory in Scripts Source: https://apatch.dev/zh_CN/apm-guide Demonstrates the recommended way to obtain the base directory path of the current module within any of its associated shell scripts. Using `MODDIR=${0%/*}` prevents hardcoding paths and ensures portability. ```shell MODDIR=${0%/*} # Example: Accessing a file within the module echo "Module files are located in: $MODDIR" ``` -------------------------------- ### APatch module.prop Configuration Source: https://apatch.dev/zh_CN/apm-guide Specifies the format and required fields for the `module.prop` configuration file. This file is essential for APatch to recognize a directory as a valid module, containing metadata like ID, name, version, and author. ```properties id= name= version= versionCode= author= description= ``` -------------------------------- ### APatch: 使用 resetprop 替代 setprop Source: https://apatch.dev/zh_CN/apm-guide 在 APatch 的 post-fs-data 模式下,直接使用 `setprop` 命令会导致启动过程死锁。推荐使用 `resetprop -n ` 来替代,以安全地设置系统属性。 ```shell # 错误示例:可能导致死锁 # setprop # 正确示例:安全地设置属性 resetprop -n ``` -------------------------------- ### APatch BusyBox Standalone Shell Mode Source: https://apatch.dev/zh_CN/apm-guide Demonstrates how to run commands within APatch's BusyBox in a predictable, isolated environment. This ensures scripts consistently use BusyBox's built-in utilities, unaffected by the system's PATH variable. ```shell # Using environment variable: export ASH_STANDALONE=1 /data/adb/ap/bin/busybox sh