[ASUS ZenFone 8] bnsmb:
Note:

The instructions below work in my environment - they should work for others after adjusting the configuration. But of course I can't guarantee that.

After creating all the other scripts to install and configure the Android OS without user intervention I finally wrote a script to do all the steps necessary to install and configure the Android OS using these scripts.

For this purpose I used another script that I wrote some time ago and use also for a lot of other things: execute_tasks.sh.

execute_tasks.sh reads a list of defined tasks from one or more include files and executes one or more of these tasks one after the other. One or more parameter for the tasks are supported. It's also possible to define task groups with one or more tasks that can be used like single tasks.

The usage for execute_tasks.sh is :

Spoiler content hidden.

To get a more detailed usage description either download the script and execute it with the parameter -H or use this link .

The include file with the tasks to install and configure the Android OS, prepare_phone.include, can be downloaded here.

To use that file either use

./execute_tasks.sh -i prepare_phone.include [task1 ... task#]

or create the symbolic link prepare_phone.sh for execute_tasks.sh :

ln -s ./execute_tasks.sh ./prepare_phone.sh

and use it like this

./prepare_phone.sh [task1 ... task#]

Note:

./prepare_phone.sh and prepare_phone.include must be in the same directory. In the rest of this post I use this method.

To list all defined tasks in the include file prepare_phone.include use the parameter --list, e.g:

Spoiler content hidden.

The tasks in the include files use the other scripts I wrote to install and configure the Android OS. Therefor you should first download the current version of these scripts either manual (see below) or using the task download_scripts:

./prepare_phone.sh download_scripts

The task download_scripts will download all necessary scripts from https://bnsmb.de/files/public/Android to the current directory; to download the scripts to another directory add the target directory as task parameter, e.g. to download the scripts into the directory /var/tmp/scripts use:

./prepare_phone.sh download_scripts:/var/tmp/scripts

Next either edit the default values for the various variables in the file prepare_phone.include or, better, create the config file prepare_phone.conf with the necessary config entries like this:

Spoiler content hidden.

It's also possible to define other variables used by the various scripts executed by the tasks in prepare_phone.include in this file, an example for the file prepare_phone.conf can be downloaded here.

The config file "prepare_phone.conf" is searched in the current directory, the home directory "${HOME}" and in the directory /etc (in this order),

When done use the task check_config to check the configuration, e.g.

./prepare_phone.sh check_config

The task check_config will check that all required variables are set and, if possible, that the values of these variables are valid. It also checks that all scripts used by the tasks in the include file exist.

The include file defines a task group called all that can be used to install and configure a phone attached via USB from scratch.

To list the tasks that will be done if the parameter all is used use the parameter --list-default-tasks, e.g.

Spoiler content hidden.

Hopefully the task names are self-explanatory ...

In principle the tasks executed if the parameter all is used will

do a factory reset

install the OS using TWRP

install the TWRP recovery into the boot partition

install Magisk into the boot partition

enable access via adb using Magisk

install Magisk v25

enable root access for the shell via Magisk

install Magisk v26

copy all scripts from the local directory ${ESSENTIAL_SCRIPTS_DIR} to the directory ${SCRIPT_DIR_ON_THE_PHONE} on the phone

install all apk files found in the local directory ${ESSENTIAL_APPS_DIR}

install all Magisk Modules found in the local directory ${ESSENTIAL_MAGISK_MODULES_DIR}

enable root access for the applications listed in the variable ${APPS_FOR_ROOT_ACCESS}

copy the script post_install.sh to the phone and execute it there (only if it exists)

To install and configure a phone attached via USB use the command:

./prepare_phone.sh all

Sample output of an installation and configuration done using the script with the parameter all can be found here.

Other task groups defined are:

Task group install_magisk

The tasks in this task group will

install the Magisk app

install Magisk into the boot partition

enable root access for the shell.

install the essential Magisk Modules found in the local directory ${ESSENTIAL_MAGISK_MODULES_DIR}

Task group update_os

The tasks in this task group will

install the OS into the passive boot slot

install TWRP into the boot partition for the passive boot slot

install Magisk into the boot partition of the passive boot slot

change the active slot and reboot the phone

The task group update_os can be used together with the task set_os_image_to_install to update an existing OS, e.g:

./prepare_phone.sh set_os_image_to_install:/data/develop/android/OmniROM_13.0/out/target/product/zenfone8/omni-13-20230121-zenfone8-MICROG.zip update_os

Sample output of an OS update using these tasks can be found here.

To install and configure the phone manually using my other scripts use these commands:

Spoiler content hidden.

To update the OS manual using the scripts use these commands (assuming Magisk is already installed):

Spoiler content hidden.

Note:

Reinstalling an ASUS Zenfone 8 with OmniROM from scratch including a factory reset takes about 12 minutes with these scripts, and updating the operating system in the passive slot takes about 5 minutes.

Please note that while writing the global script I updated and corrected some of the other scripts. Therefor it's recommended to download the current versions of the scripts.

Some hints for trouble shooting

Each task is a function in the include file with the name task_<taskname>, e.g. the function used to implement the task enable_adb is task_enable_adb.

Task parameter must be added to the taskname using the colon ":" as delimiter, example: install_magisk_in_boot_partition_only:noreboot:next

To execute the tasks in verbose mode use the parameter --info; to execute the complete script in verbose mode use the parameter --verbose.

To execute the tasks with "set -x" use the parameter --trace.

To execute the tasks in single step mode use the parameter --single-step.

The global initialisation of the script is done in the function init_tasks; all script parameter after "--" are parameter for the function init_tasks. To execute the function init_tasks with "set -x" use the parameter "-- trace"; to view the known parameter for the function init_tasks use the parameter "-- help".

To execute the tasks in dry-run mode use the init_tasks parameter " -- dryrun"

In the default configuration execute_tasks.sh will stop executing the remaining tasks if one of the tasks ends with an error. To disable this functionality for one task use the task parameter ignorerc; to disable this functionality global use the the task enable_disable_abort_on_error:disable and to enable it again use the task enable_disable_abort_on_error:enable.

Use the parameter "-h -v" to get the detailed usage help

Notes

The scripts used by this script can be downloaded manually from these URLs:

https://bnsmb.de/files/public/Android/boot_phone_from_twrp.sh

https://bnsmb.de/files/public/Android/enable_access_via_adb.sh

https://bnsmb.de/files/public/Android/enable_adb_using_magisk.sh

https://bnsmb.de/files/public/Android/enable_root_access_via_magisk.sh

https://bnsmb.de/files/public/Android/init_magisk_db.sh

https://bnsmb.de/files/public/Android/install_apk.sh

https://bnsmb.de/files/public/Android/install_magisk_via_twrp.sh

https://bnsmb.de/files/public/Android/install_os_via_twrp.sh

https://bnsmb.de/files/public/Android/install_twrp_from_within_twrp.sh

https://bnsmb.de/files/public/Android/install_twrp.sh

The documentation for these scripts can be found on my home page https://bnsmb.de/My_HowTos_for_Android.html or in the various HowTos in the XDA Forum that I wrote.

Update 02.02.2023

See here for how to configure WiFi in Android via script

Update 18.04.2023/bs

see How to install Magisk v26.0 or newer via script for how to install Magisk v26 via script

Update 12.01.2024 /bs

In TWRP version 3.7.0_12-1 for the ASUS Zenfone 8 (necessary for Android 14 based ROMs) the bootctl binary is not included anymore. Therefor the installation and configuration described in this post will only partially work.

To work around this, you need to create a new TWRP image based on TWRP 3.7.0_12-1 but with the bootctl binary (see here for how to do that)

Update 19.01.2024 /bs

Updated the list of tasks available in the script to install and configure the Android OS