[question] task to set values in terminal after boot - Tasker Tips & Tricks

Hi, I'm new on Tasker and want to create an task.
After boot it should set SeLinux to permissive in terminal emulator...
Is it possible to create such an rule?

Create a profile that triggers on device boot :
+ -> event -> system -> device boot
Then add a task that does a shell action with "setenforce 0" and use root checked.
Profile: SELinux Permissive (85)
Event: Device Boot
Enter: Set SELinux (73)
A1: Run Shell [ Command:setenforce 0 Timeout (Seconds):0 Use Root: On Store Output In: Store Errors In: Store Result In: Continue Task After Error: On ]

Thanks a lot...
A lot of questions I have...
First: how do I create an task with an shell action?

look here

ktmom said:
Create a profile that triggers on device boot :
+ -> event -> system -> device boot
Then add a task that does a shell action with "setenforce 0" and use root checked.
Profile: SELinux Permissive (85)
Event: Device Boot
Enter: Set SELinux (73)
A1: Run Shell [ Command:setenforce 0 Timeout (Seconds):0 Use Root: On Store Output In: Store Errors In: Store Result In: Continue Task After Error: On ]
Click to expand...
Click to collapse
Thanks my friend... Your second hint did it.
Best regards.

Related

samsung ultra power save mode

Can I use gasket to enable upsm at 5% ? I'm complete noob so will need talking through thanks
ROOT + shell
echo "0" > /sys/devices/virtual/mdnie/mdnie/accessibility
echo "1" > /sys/devices/virtual/mdnie/mdnie/accessibility
echo "2" > /sys/devices/virtual/mdnie/mdnie/accessibility
echo "3" > /sys/devices/virtual/mdnie/mdnie/accessibility
0 : Normal Screen
1 : Inverted Colors
2 : Ultra Power Save Mode
3 : Screen off but not locked and touchscreen is still working
Thanks for reply but that means nothing to me?
No one with a basic guide
Do you have ROOT?
If not, you can"t auto turn on UPSM.
Yes I have root
@bandit250
you are still interested?
Yes please
First, Make a test.
Task:
1. Run shell [mark ROOT]
Command:
echo "2" > /sys/devices/virtual/mdnie/mdnie/accessibility
Push play
upsm should turn on.
Hi I get this error
17.49.16/E Run Shell: ->
17.49.16/E Run Shell: ->
17.49.16/E Run Shell: ->
17.49.16/Shell runBackground echo "2" > /sys/devices/virtual/mdnie/mdnie/accessibility root: true timeout: -1
17.49.16/Shell start process-thread ID 4097
17.49.16/E add wait type Shell1 time 2147483647
17.49.16/E add wait type Shell1 done
17.49.16/E add wait task
17.49.16/E Error: 1

creating my 1st module: but service.sh never run

Magisk v19.3 on lineageos 16.0 for wt86047
trying to create my first module, no files to replace, just one task: run a remove.sh script
I put following two lines in ./common/service.sh , but there's no file created after boot , seems the service.sh itself never be run at all.
echo -e "\n------------${MODPATH}----------------------------" >> /sdcard/s.txt >&1
sh ./remove.sh
LATESTARTSERVICE=true in ./install.sh --YES
./META-INF/com/google/android/update-binary updated --YES
./module.prop edited --YES
the module installed with no error --YES
manual run remove.sh successfully in terminal after reboot --YES
called from service.sh --NO
need help, THANK YOU!
attached remove.sh
Code:
#!/system/bin/sh
DIRFILE="/sdcard/dir"
if [ -f "$USRFILE" ];then
while IFS= read -r LINE
do
if [ -n "${LINE}" ];then
...
...
fi
I haven't looked at what might be your issue, but you don't need a module for that... Just place your remove.sh script in /data/adb/service.d and give it execution permission.
Didgeridoohan said:
I haven't looked at what might be your issue, but you don't need a module for that... Just place your remove.sh script in /data/adb/service.d and give it execution permission.
Click to expand...
Click to collapse
thanks. but it doesn't work either.
When I manually run the script from terminal, it prompt 'Permission denied.'
But it works after execute 'su' first.
Is this the reason? But how could I authorise root right to the script since it doesn't pop dialogbox at all.
Again, I haven't looked at your script at all, but...
Any scripts run by Magisk at boot will run with superuser permission. That's not your issue...
Might be that the script has to run after boot is completed (if it works while booted but not during boot). You can look for the sys.boot_completed and when it's changed to 1 you can let the script execute.
I use this code in my modules, if it can help
Code:
_SLEEPBOOT=60
# ...
RETRY_INTERVAL=${_SLEEPBOOT} #in seconds
MAX_RETRY=30
retry=${MAX_RETRY}
while (("$retry" > "0")) && [ "$(getprop sys.boot_completed)" != "1" ]; do
sleep ${RETRY_INTERVAL}
((retry--))
done
Didgeridoohan said:
Again, I haven't looked at your script at all, but...
Any scripts run by Magisk at boot will run with superuser permission. That's not your issue...
Might be that the script has to run after boot is completed (if it works while booted but not during boot). You can look for the sys.boot_completed and when it's changed to 1 you can let the script execute.
Click to expand...
Click to collapse
Code:
# Wait for boot to complete
until [ "$(getprop sys.boot_completed)" ]
do
sleep 2
done
insert this code to script but still not work...
after all, found the solution:
don't use '/sdcard/, use '/storage/emulated/0/' instead, don't know why
funnypc said:
Code:
# Wait for boot to complete
until [ "$(getprop sys.boot_completed)" ]
do
sleep 2
done
insert this code to script but still not work...
after all, found the solution:
don't use '/sdcard/, use '/storage/emulated/0/' instead, don't know why
Click to expand...
Click to collapse
Might have worked if you had checked for sys.boot_completed = 1.
But yeah, /sdcard isn't available during boot. To be even more sure it'll work you could use /data/media/0 instead. That's always available (as long as /data is accessible).
Didgeridoohan said:
Might have worked if you had checked for sys.boot_completed = 1.
But yeah, /sdcard isn't available during boot. To be even more sure it'll work you could use /data/media/0 instead. That's always available (as long as /data is accessible).
Click to expand...
Click to collapse
though the script can work alone , I still want make it a module so that could install/disable easier with magisk gui than terminal.
currently I'm add a 'bypass' mode while script load, if volume key pressed repeatly. (like xposed does) but the code can only work after unlock, it seems the getevent can't work after system reboot, before keyguard unlocked. any workaround? thx!
Code:
#!/system/bin/sh
KEYSTRING="KEY_VOLUME"
KEYREPEAT=1
KEYCOUNTS=0
until [ "$(getprop sys.boot_completed)" ]
do
sleep 2
done
setenforce Permissive
echo 300 > /sys/class/timed_output/vibrator/enable
sleep 0.3
for i in `seq 1 4`;
do
EVENT=$(timeout 1 getevent -l -q -c 1)
RESULT=`echo $EVENT | grep -c $KEYSTRING`
input keyevent mouse
if [ "$RESULT" -gt 0 ] ;then
KEYCOUNTS=`expr $KEYCOUNTS + $RESULT`
echo 100 > /sys/class/timed_output/vibrator/enable
fi
done
if [ "$KEYCOUNTS" -gt "$KEYREPEAT" ] ;then
echo 1000 > /sys/class/timed_output/vibrator/enable
fi
Simple, just put your code in the service.sh file of the module instead of a separate script file...
Didgeridoohan said:
Simple, just put your code in the service.sh file of the module instead of a separate script file...
Click to expand...
Click to collapse
can't work. so I put the keypress detection part in a standalone script for debug. just script in service.d folder, not pack to module yet.
if I run the script manually in terminal after keyguard unlocked, everything works as I want
but not when keyguard locked status just after reboot.
funnypc said:
can't work. so I put the keypress detection part in a standalone script for debug. just script in service.d folder, not pack to module yet.
if I run the script manually in terminal after keyguard unlocked, everything works as I want
but not when keyguard locked status just after reboot.
Click to expand...
Click to collapse
I mean the code from your remove.sh file, not the key detecting stuff... That way you can disable the module from the Manager and also from TWRP (or other custom recovery) by placing a disable file in the module directory or enabling Magisk Core Only Mode by placing a .disable_magisk file in /cache.

How To Guide How to enable access via adb on a new installed OS

For automatic installation and configuration of a phone running the Android OS the access via adb is required. "Unfortunately" the access via adb is disabled in most Android distributions (in reality it is of course good that the access via adb is disabled in the default setting! See also the notes regarding the LineageOS at the end of this post))
There are (at least) two ways to enable access via adb:
Manually via the GUI of Android on the phone or via the Android command settings executed by the user root in a shell ,e.g.:
Bash:
settings put global development_settings_enabled 1
settings put global adb_enabled 1
The latter can also be done in a script in an adb shell -- but of course we need a working adb connection ....
One way around this problem is to use Magisk:
In principle this could be done using an init script for Magisk:
Magisk allows to run scripts while booting the phone (see How to run a script at every boot using Magisk); this feature could be used to enable adb via script.
Unfortunately, this method no longer works in the latest Android versions (Androd 12 and Android 13; Android 11 not tested):
Android now uses encryption for most of the files in the subdirectories in /data and to initiate the encryption keys for the files in these directories, the phone must boot once from the installed OS.
To use a Magisk init script to enable the access via adb, we need to create files in the directories /data/adb and /data/misc/adb. If you create these files while booting into TWRP recovery without a configured Android operating system, these files will be created unencrypted, making it impossible to boot the installed Android operating system:
If the Android operating system finds unencrpyted files in these directories at the first reboot, it boots into the installed recovery with the famous error message "Cannot load Android system. Your data may be corrupt" (see How to fix the error "Cannot load Android system. Your data may be corrupt" for details)
Fortunately, the Android operating system does not encrypt files in the directory /data/recovery (and therefore continues booting if there are already files in that directory) and the part of Magisk in the boot partition does not need the Magisk files /data/adb.
So to enable the access via adb using Magisk, we can create a script in the directory /data/recovery and a new Init .rc file for the Android operating system to execute that script while the Android OS is booting - for details about how to do that see How to trigger an action when a property is changed.
The working method to enable adb via Magisk is as follows:
- Boot the phone from a recovery (like TWRP)
- Install the new OS image but do not reboot the phone (see How to install an OS image using the TWRP binary twrp for how to install the OS via the cli commands from TWRP)
- Install Magisk into the boot partition of the phone and delete all files in /data/adb afterwards (see How to install Magisk into the boot partition using a script for how to install Magisk via script)
- copy a script to the directory /data/recovery on the phone that will enable access via adb using the Android command settings and copy the public ssl keys for the access via adb to the directory /data/misc/adb on the phone
- install a new init .rc file via Magisk which executes the script in the direcory /data/recovery to enable the access via adb - this script will be executed while doing the 1st reboot of the new installed Android OS.
(see How to trigger an action when a property is changed for how to add a new init .rc file using Magisk)
- reboot the phone
I wrote two scripts to enable adb using this method:
enable_adb_using_magisk.sh
The script enable_adb_using_magisk.sh must run in an adb session in TWRP after the new OS was installed and after Magisk has been installed into the boot partition but before the first reboot of the new installed operating system.
The script enable_adb_using_magisk.sh
- creates the script /data/recover/enable_adb_via_service.sh on the phone to enable adb and install the public ssl key for access via adb
- creates a new init *rc file using Magisk that will run the script /data/recover/enable_adb_via_service.sh on the phone while doing the 1st reboot (after the file encryption for the files /data is initalized by the Android OS)
To use the script enable_adb_using_magisk.sh manually after installing the new OS and Magisk do while the phone is booted into TWRP:
Bash:
#
# copy the script enable_adb_using_magisk.sh to the directory /tmp on the phone
#
adb push enable_adb_using_magisk.sh /tmp/enable_adb_using_magisk.sh
# copy the public ssl key for access via adb to the directory /tmp on the phone
#
adb push $HOME/.android/adbkey.pub /tmp/adbkey.pub
# execute the script /tmp/enable_adb_using_magisk.sh on the phone
#
adb shell sh /tmp/enable_adb_using_magisk.sh
# reboot the phone into the new installed OS
#
adb reboot
Notes:
The script enable_adb_using_magisk.sh installs the init *rc file into the boot partition from the slot for the next reboot: In this scenario this is the slot with the new installed OS.
To specify the boot partition to use add the boot partition as parameter, e.g.
Bash:
adb shell sh /tmp/enable_adb_using_magisk.sh _a
The init *rc service used is:
Spoiler: init *rc service to enable adb
Code:
#
# additional RC service to enable the access via adb after the 1st boot into the new installed Android OS
#
service bnsmb_enable_adb /system/bin/sh /data/recovery/enable_adb_via_service.sh
user root
group root
seclabel u:r:magisk:s0
disabled
oneshot
on zygote-start
setprop sys.bnsmb_enable_adb_done 0
start bnsmb_enable_adb
#
# Note: the following entries are for testing only!
#
on zygote-start
write /data/recovery/semfile Here_I_am
setprop sys.bnsmb.test.okay 0
The script enable_adb_using_magisk.sh creates the files adb_keys and adb_temp_keys.xml in the directory /data/misc/adb if the public ssl key /tmp/adbkey.pub exists on the phone.
Note that the file /data/misc/adb/db_temp_keys.xml is an Android Binary XML fIle (see How to change files in Android XML Binary format for details about Android Binary XML files)
To avoid the manual steps listed above I wrote another script:
enable_access_via_adb.sh
The script enable_access_via_adb.sh does all the steps listed above; the usage for enable_access_via_adb.sh is
Code:
[ OmniRom 13 Dev - [email protected] /data/develop/android/scripts_on_linux ] $ ./enable_access_via_adb.sh -h
enable_access_via_adb.sh version - v1.0.0.0 - shell script to enable adb access via an init .rc file configured via Magisk
enable_access_via_adb.sh [-h|help|-H] [--reboot|--noreboot] [--nopubkey|--pubkey]
[ OmniRom 13 Dev - [email protected] /data/develop/android/scripts_on_linux ] $
Spoiler: Detailed Usage
Code:
[ OmniRom 13 Dev - [email protected] /data/develop/android/scripts_on_linux ] $ ./enable_access_via_adb.sh -H
enable_access_via_adb.sh version - v1.0.0.0 - shell script to enable adb access via an init .rc file configured via Magisk
Usage
enable_access_via_adb.sh [-h|help|-H] [--reboot|--noreboot] [--nopubkey|--pubkey]
All parameter are optional. The parameter can be used in any order.
Use the parameter "help" or "-H" to print the detailed usage help; use the parameter "-h" to print only the short usage help
If the parameter "--reboot" is used the script will reboot the phone after installing Init .rc file; to disable the automatic reboot use the parameter "--noreboot".
Default is to ask the user for confirmation to reboot the phone.
Use the parameter "--nopubkey" to disable configuring the public key of the current user on the PC for the access via adb; use the parameter "--pubkey" to configure
the public key; default is to configure the public key.
The default public ssl key used is the key in the file "${HOME}/.android/adbkey.pub".
To change some of the values used by the script these environment variables can be set before starting the script:
Set the environment variable PUBLIC_KEY_ON_PC to the file with the public ssl key to use for the access via adb if another public key should be used
Set the environment variable REBOOT to "yes" before starting the script to automatically reboot the phone after enabling the root access
Set the environment variable REBOOT to "no" before starting the script to disable the automatic reboot after enabling the root access
See also the source code of the script
boot_phone_from_twrp.sh
for environment variables supported by this script
Prerequisites
- the phone must be connected via USB
- Magisk must be already installed in the boot partition of the phone
- the phone must be either booted into the fastbootd or bootloader with a working fastboot connection
or already booted into a recovery image with working adb connnection
The scripts boot_phone_from_twrp.sh and enable_adb_using_magisk.sh are required by this script -- see the source code of the script
[ OmniRom 13 Dev - [email protected] /data/develop/android/scripts_on_linux ] $
So installing a new OS and enabling access via adb in a script without user intervention can be done using these commands:
Bash:
#
# do a factory reset and install the OS image using the TRWP binary twrp
#
REBOOT=no ./install_os_via_twrp.sh factory_reset /data/backup/ASUS_ZENFONE8/omnirom_local/omni-13/omni-13-20221211-zenfone8-MICROG.zip
# install Magisk into the boot sector of the partition with the new OS and delete all files in /data/adb afterwards
#
# The parameter delete_adb_dir for the script "install_magisk_via_twrp.sh" is only available in version 2.2.0.0 or newer of the script.
#
REBOOT=no ./install_magisk_via_twrp.sh next copy_apk delete_adb_dir
# enable adb and copy the public keys for adb via new init *rc file using Magisk in the boot partition
#
REBOOT=no ./enable_access_via_adb.sh
# reboot the phone
#
adb reboot
# wait until the new OS is booted and adb is enabled
#
adb wait-for-device
# install the Magisk App
#
./install_apk.sh /data/backup/Android/EssentialApps/Magisk-v25.2.apk
# install the Magisk directories and binaries in /data/adb
#
REBOOT=no ./install_magisk_via_twrp.sh adb_only
# (optional) enable root access for the adb shell
#
REBOOT=yes ./init_magisk_db.sh
Notes:
The script enable_access_via_adb.sh needs the helper script boot_phone_from_twrp.sh.sh and the script enable_adb_using_magisk.sh .
The scripts can be downloaded from my homepage:
enable_access_via_adb.sh
enable_adb_using_magisk.sh
boot_phone_from_twrp.sh
The other scripts mentioned in ths post can also be downloaded from my home page:
install_os_via_twrp.sh (see How to install an OS image using the TWRP binary twrp for a descripton of this script)
install_magisk_via_twrp.sh (see How to install Magisk into the boot partition using a script for a description for this script)
install_apk.sh (see How to install packages (apk files) for Android via script for a description for this script)
init_magisk_db.sh (see How to enable root access using Magisk in a script for a description for this script)
Disabling the service to enable access via adb
To only run once, the script enable_adb_using_magisk.sh creates the file /data/recovery/adb_initialized exists on the phone. If that file already exists when enable_adb_using_magisk.sh starts, the script will do nothing and end immediately.
Therefor, it's not necessary to delete the new init *rc service.
It might even be useful to leave the service installed, since it can be used for other purposes later by modifying the script
However, if necessary, you can either delete the script used by the init *rc service enable_adb_using_magisk.sh or reinstall the original boot partition to get rid of the new service completely:
Bash:
#
# while the phone is booted into the Android OS with enabled root access or while the phone is booted into TWRP
#
# use the parameter "yes" for the script to run without requesting user input
#
adb shell su - -c /data/recovery/work/restore_boot_partition.sh
Directories and files used
Name
Type
Content
Comment
/tmp/adbkey.pubfilessl public key that should be configured/tmp is on a ramdisk so this file is lost after booting the phone/data/recovery/workDirectorytemporary files used for enabling adb/data/recovery/work/enable_adb_via_service.rcfileinit *rc file added to the boot partition via Magiks/data/recovery/work/boot_a.imgfileimage of the original boot partition/data/recovery/work/original_boot_partition.imgSymLinklink to the image with the original boot partition/data/recovery/work/restore_boot_partition.shfileScript to restore the boot partition using the image of the original boot partition/data/recovery/work/header
/data/recovery/work/kernel
/data/recovery/work/ramdisk.cpiofilescontents of the boot partition/data/recovery/adbkey.pubfilepublic ssl key to be configured for access via adb/data/recovery/adb_temp_keys.xml.humanfileXML file with the configuration for the access via adb
(will be converted to an XML file in Android binary XML format in /data/misc/adb)/data/recovery/enable_adb_via_service.shfilescript to enable the access via adb and installl the public ssl key for the access via adb
The script is configured in the init*rc file /data/recovery/work/enable_adb_via_service.rc/data/recovery/enable_adb_via_service.logfilelog file created by the script /data/recovery/enable_adb_via_service.sh/data/recovery/adb_initializedfilesemphor file for the script /data/recovery/enable_adb_via_service.sh - if this file exists the script will do nothing/data/recovery/semfilefiletest file created by the new init *rc service/data/recovery/log.gz
/data/recovery/last_log.gz
/data/recovery/recovery.fstab
/data/recovery/storage.fstabfileFiles created by TWRPonly for information
Enabling access via adb in the LineageOS (Update 11.01.2023)
In the LineageOS 19 for the ASUS Zenfone 8 access via adb is enabled in the default configuration.
Therefor these instructions are not necessary. The only configuration that must be done on a phone running the LineageOS is to copy the public ssl keys to /data/misc/adb to enable the access via adb.
Unfortunately the method used for this described in this post seems not to work in the LineageOS.
In addition, root access via adb can be enabled in the developer settings in the LineageOS. Until now I did not find out how to enable the plain root access from the LineageOS from within a script.
userdebug builds
In userdebug builds of Android the access via adb (without authentification) is enabled in the default.
Trouble Shooting
The script enable_adb_using_magisk.sh uses the log file /data/recovery/enable_adb_via_service.log if executed via init *rc service.
To check if the init *rc file was configured successfully check the properties
sys.bnsmb_enable_adb_done
sys.bnsmb.test.okay
in the running Android OS. Both properties should be defined with the value 0:
Code:
ASUS_I006D:/ # getprop sys.bnsmb_enable_adb_done
0
ASUS_I006D:/ #
ASUS_I006D:/ # getprop sys.bnsmb.test.okay
0
ASUS_I006D:/ #
In addition, if everything worked there should exist the file /data/recovery/semfile.
Code:
130|ASUS_I006D:/ # ls -l /data/recovery/semfile
-rw------- 1 root root 9 2022-12-29 11:44 /data/recovery/semfile
ASUS_I006D:/ #
Use the Android command start to check if the service exists and can be started, e.g.
Spoiler: start bnsmb_enable_adb
Code:
ASUS_I006D:/ # start bnsmb_enable_adb ; dmesg | tail -10
[ 3069.861365] [ 3069.861365] (CPU:2-pid:1:init) [12:35:31.711593934] init: Service 'exec 613 (/system/bin/flags_health_check UPDATABLE_CRASHING)' (pid 5734) exited with status 0 waiting took 0.024000 seconds
[ 3069.861402] [ 3069.861402] (CPU:2-pid:1:init) [12:35:31.711630236] init: Sending signal 9 to service 'exec 613 (/system/bin/flags_health_check UPDATABLE_CRASHING)' (pid 5734) process group...
[ 3069.861618] [ 3069.861618] (CPU:2-pid:1:init) [12:35:31.711846069] libprocessgroup: Successfully killed process cgroup uid 1000 pid 5734 in 0ms
[ 3071.202534] [ 3071.202486] (CPU:2-pid:5077:wk:0xffffffe40) [12:35:33.052716433] [BAT][CHG]asus_jeita_cc_worker set BATTMAN_OEM_WORK_EVENT : WORK_JEITA_CC
[ 3071.220807] [ 3071.220807] (CPU:0-pid:350:wk:0xffffffe40) [12:35:33.071038100] [BAT][CHG]handle_message set property:16 successfully
[ 3071.570753] [ 3071.570753] (CPU:2-pid:1:init) [12:35:33.420982631] init: starting service 'bnsmb_enable_adb'...
[ 3071.575971] [ 3071.575971] (CPU:3-pid:1:init) [12:35:33.426199819] init: Control message: Processed ctl.start for 'bnsmb_enable_adb' from pid: 5735 (start bnsmb_enable_adb)
[ 3071.614570] [ 3071.614570] (CPU:3-pid:1:init) [12:35:33.464799298] init: Service 'bnsmb_enable_adb' (pid 5736) exited with status 0 oneshot service took 0.040000 seconds in background
[ 3071.614609] [ 3071.614609] (CPU:3-pid:1:init) [12:35:33.464837267] init: Sending signal 9 to service 'bnsmb_enable_adb' (pid 5736) process group...
[ 3071.614788] [ 3071.614788] (CPU:3-pid:1:init) [12:35:33.465016277] libprocessgroup: Successfully killed process cgroup uid 0 pid 5736 in 0ms
ASUS_I006D:/ #
If something does not work execute the script manually in an adb session to check :
Spoiler: /data/recovery/enable_adb_via_service.sh
Code:
ASUS_I006D:/ # rm -f /data/recovery/adb_initialized
ASUS_I006D:/ #
ASUS_I006D:/ #
ASUS_I006D:/ # sh -x /data/recovery/enable_adb_via_service.sh
+ tty -s
+ '[' 0 -ne 0 ']'
+ PATH=/system/bin:/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/system_ext/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin
+ export PATH
+ '[' ! -r /data/recovery/adb_initialized ']'
+ echo 'Sleeping 30 seconds now ...'
Sleeping 30 seconds now ...
+ sleep 30
+ touch /data/recovery/adb_initialized
+ settings put global development_settings_enabled 1
+ settings put global adb_enabled 1
+ '[' ! -d /data/misc/adb ']'
+ '[' ! -r /data/misc/adb/adb_keys ']'
+ '[' -r /data/recovery/adbkey.pub ']'
+ >>/data/misc/adb/adb_keys
+ cat /data/recovery/adbkey.pub
+ '[' -r /data/recovery/adb_temp_keys.xml.human ']'
+ xml2abx /data/recovery/adb_temp_keys.xml.human /data/misc/adb/adb_temp_keys.xml
+ chmod 0600 /data/misc/adb/adb_temp_keys.xml
+ chown system:shell /data/misc/adb/adb_temp_keys.xml
+ chcon -v u:object_r:adb_keys_file:s0 /data/misc/adb/adb_temp_keys.xml
chcon '/data/misc/adb/adb_temp_keys.xml' to u:object_r:adb_keys_file:s0
ASUS_I006D:/ #
Thank you for your explanation, I leave my footprint, I need this sometimes.

How To Guide How to install and configure the Android OS 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
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: ./execute_tasks.sh -h
Code:
[ OmniRom 13 Dev - [email protected] /data/develop/scripts ] $ ./execute_tasks.sh -h
[17.01.2023 18:42 ] ### execute_tasks.sh started at 17.01.2023 18:42:44 (The PID of this process is 655162)
[17.01.2023 18:42 ] ### Processing the parameter ...
[17.01.2023 18:42 ] Tasks to execute are: ""
[17.01.2023 18:42 ] Parameter for the function init_tasks are: ""
Usage: execute_tasks.sh [-v|--verbose] [-q|--quiet] [-f|--force] [-o|--overwrite] [-y|--yes] [-n|--no] [-l|--logfile filename]
[-d{:dryrun_prefix}|--dryrun{:dryrun_prefix}] [-D|--debugshell] [-t fn|--tracefunc fn] [-L]
[-T|--tee] [-V|--version] [--var name=value] [--appendlog] [--nologrotate] [--noSTDOUTlog] [--disable_tty_check] [--nobackups]
[--print_task_template [filename]] [--create_include_file_template [filename]] [--list [taskmask]] [--list_tasks [taskmask]]
[--list_task_groups [groupmask]] [--list_default_tasks] [--abort_on_error] [--abort_on_task_not_found] [--abort_on_duplicates]
[--checkonly] [--check] [--singlestep] [--unique] [--trace] [--info] [--print_includefile_help] [-i|--includefile [?]filename]
[--no_init_tasks[ [--no_finish_tasks] [--only_list_tasks] [--disabled_tasks task1[...,task#]] [--list_disabled_tasks] [--enable_all_tasks]
[task1] [... task#] [-- parameter_for_init_tasks]
Current environment: ksh version: 93 | change function code supported: yes | tracing feature using $0 supported: yes
[17.01.2023 18:42 ] ### The logfile used was /var/tmp/execute_tasks.sh.log
[17.01.2023 18:42 ] ### The start time was 17.01.2023 18:42:44, the script runtime is (day:hour:minute:seconds) 0:00:00:00 (= 0 seconds)
[17.01.2023 18:42 ] ### execute_tasks.sh ended at 17.01.2023 18:42:44 (The PID of this process is 655162; the RC is 0)
[ OmniRom 13 Dev - [email protected] /data/develop/scripts ] $
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
Code:
./execute_tasks.sh -i prepare_phone.include [task1 ... task#]
or create the symbolic link prepare_phone.sh for execute_tasks.sh :
Bash:
ln -s ./execute_tasks.sh ./prepare_phone.sh
and use it like this
Code:
./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: ./prepare_phone.sh --list -v
Code:
[ OmniRom 13 Dev - [email protected] /data/develop/android ] $ ./scripts_on_linux/prepare_phone.sh --list -v
[27.01.2023 12:25 ] ### prepare_phone.sh started at 27.01.2023 12:25:09 (The PID of this process is 1024201)
[27.01.2023 12:25 ] ### Processing the parameter ...
[27.01.2023 12:25 ] Tasks to execute are: ""
[27.01.2023 12:25 ] Parameter for the function init_tasks are: ""
[27.01.2023 12:25 ] ### The logfile used is /var/tmp/prepare_phone.sh.log
[27.01.2023 12:25 ] INFO: Searching the default include file "prepare_phone.include" ...
[27.01.2023 12:25 ] INFO: "/data/develop/android/scripts_on_linux/prepare_phone.include" found.
[27.01.2023 12:25 ] INFO: Checking and reading the include file(s) "/data/develop/android/scripts_on_linux/prepare_phone.include " now ...
[27.01.2023 12:25 ] Checking the include file "/data/develop/android/scripts_on_linux/prepare_phone.include" ...
[27.01.2023 12:25 ] INFO: The version of the include file "/data/develop/android/scripts_on_linux/prepare_phone.include", "1.0.0.0", is okay.
[27.01.2023 12:25 ] INFO: Function "init_tasks" found in the include file "/data/develop/android/scripts_on_linux/prepare_phone.include"
[27.01.2023 12:25 ] INFO: Function "finish_tasks" found in the include file "/data/develop/android/scripts_on_linux/prepare_phone.include"
[27.01.2023 12:25 ] Reading the include file "/data/develop/android/scripts_on_linux/prepare_phone.include" ...
[27.01.2023 12:25 ] INFO: Found this list of tasks to be excluded from "all" in the include file "/data/develop/android/scripts_on_linux/prepare_phone.include" :
[27.01.2023 12:25 ] INFO: Found this list of tasks for "all" in the include file "/data/develop/android/scripts_on_linux/prepare_phone.include" :
[27.01.2023 12:25 ] INFO: enable_disable_abort_on_error:enable
[27.01.2023 12:25 ] INFO: boot_phone_from_twrp_image
[27.01.2023 12:25 ] INFO: install_os:noreboot:factory_reset
[27.01.2023 12:25 ] INFO: install_twrp:noreboot:next
[27.01.2023 12:25 ] INFO: install_magisk_in_boot_partition_only:noreboot:next
[27.01.2023 12:25 ] INFO: enable_adb:reboot
[27.01.2023 12:25 ] INFO: #
[27.01.2023 12:25 ] INFO: install_magisk_in_data_adb_only:noreboot:copy_apk
[27.01.2023 12:25 ] INFO: enable_root_access_for_the_shell:reboot
[27.01.2023 12:25 ] INFO: wait_for_access_via_adb:60:kill
[27.01.2023 12:25 ] INFO: install_the_magisk_app
[27.01.2023 12:25 ] INFO: enable_disable_abort_on_error:disable
[27.01.2023 12:25 ] INFO: install_essential_scripts
[27.01.2023 12:25 ] INFO: install_essential_apps
[27.01.2023 12:25 ] INFO: install_essential_magisk_modules
[27.01.2023 12:25 ] INFO: enable_root_access_for_apps:reboot
[27.01.2023 12:25 ] INFO: execute_script_on_the_phone:ignorerc
Include files used are:
/data/develop/android/scripts_on_linux/prepare_phone.include
Tasks defined are:
Task: boot_phone_from_twrp_image Usage: boot_phone_from_twrp_image [ignorerc] [twrp_image] parameter_for_the_script]
Task: boot_phone_into_android Usage: boot_phone_into_android [ignorerc] [force]
Task: boot_phone_into_bootloader Usage: boot_phone_into_bootloader [ignorerc]
Task: boot_phone_into_fastboot Usage: boot_phone_into_fastboot [ignorerc]
Task: boot_phone_into_recovery Usage: boot_phone_into_recovery [ignorerc]
Task: boot_phone_into_safemode Usage: boot_phone_into_safemode [ignorerc] [timeout=timeout_in_seconds] # Default: 30 seconds; Note: The phone must be booted into the AndroidOS for this task
Task: check_config Usage: check_config
Task: download_scripts Usage: download_scripts [target_dir|default|pwd] [backup|nobackup] [ignorerc] # default: download the scripts to the current directory
Task: enable_adb Usage: enable_adb [reboot|noreboot|reboot=no|reboot=yes] [ignorerc] [parameter_for_the_script] # default is: no reboot
Task: enable_disable_abort_on_error Usage: enable_disable_abort_on_error [yes|no] # default is yes
Task: enable_root_access_for_apps Usage: enable_root_access_for_apps [reboot|noreboot|reboot=no|reboot=yes] [ignorerc] [parameter_for_the_script] # default is: no reboot
Task: enable_root_access_for_the_shell Usage: enable_root_access_for_the_shell [reboot|noreboot|reboot=no|reboot=yes] [ignorerc] [parameter_for_the_script] # default is: no reboot
Task: execute_script_on_the_phone Usage: execute_script_on_the_phone [ignorerc] [script_to_execute] # default: post_install.sh in the current directory
Task: factory_reset_via_twrp Usage: factory_reset_via_twrp [reboot|noreboot|reboot=no|reboot=yes] [twrp_imagefile] [ignorerc] [force|noforce]
Task: install_apps Usage: install_apps [reboot|noreboot|reboot=no|reboot=yes] [ignorerc] [apkfile1 ... apkfile#] # default is: no reboot
Task: install_essential_apps Usage: install_essential_apps [reboot|noreboot|reboot=no|reboot=yes] [ignorerc] [dir_with_the_apk_files_to_install] # default is: no reboot
Task: install_essential_magisk_modules Usage: install_essential_magisk_modules [reboot|noreboot|reboot=no|reboot=yes] [ignorerc] [dir_with_the_magisk_modules_to_install] # default is: no reboot
Task: install_essential_scripts Usage: install_essential_scripts [reboot|noreboot|reboot=no|reboot=yes] [ignorerc] [dir_with_the_scripts_to_install] # default is: no reboot
Task: install_magisk_in_boot_partition Usage: install_magisk_in_boot_partition [slot] [reboot|noreboot|reboot=no|reboot=yes] [ignorerc] [magisk_apkfile] [parameter_for_the_script] # default is: reboot
Task: install_magisk_in_boot_partition_only Usage: install_magisk_in_boot_partition_only [slot] [reboot|noreboot|reboot=no|reboot=yes] [ignorerc] [magisk_apkfile] [parameter_for_the_script] # default is: no reboot
Task: install_magisk_in_data_adb_only Usage: install_magisk_in_data_adb_only [reboot|noreboot|reboot=no|reboot=yes] [ignorerc] [magisk_apkfile] [parameter_for_the_script] # default is: no reboot
Task: install_magisk_modules Usage: install_magisk_modules [reboot|noreboot|reboot=no|reboot=yes] [ignorerc] [magisk_module1 ... magisk_module#] # default is: no reboot
Task: install_os Usage: install_os [slot] [reboot|noreboot|reboot=no|reboot=yes] [ignorerc] [reset] [imagefile] [parameter_for_the_script] # default is: no reboot
Task: install_the_magisk_app Usage: install_the_magisk_app [reboot|noreboot|reboot=no|reboot=yes] [ignorerc] [magisk_apk_file] # default is: no reboot
Task: install_twrp Usage: install_twrp [slot] [reboot|noreboot|reboot=no|reboot=yes] [ignorerc] [twrp_imagefile] [parameter_for_the_script] # default is: no reboot
Task: kill_adb_daemon Usage: kill_adb_daemon [reboot|noreboot|reboot=no|reboot=yes] [ignorerc]
Task: restore_titanium_backup Usage: restore_titanium_backup [license=license_file] [zip=zipfile] [app=titanium_app] [ignorerc]
Task: set_os_image_to_install Usage: set_os_image_to_install [os_image] # there is no default value
Task: update_include_file Usage: update_include_file [target_dir|target_file] [ignorerc] [keep|nokeep] # default: nokeep (= delete temporary files)
Task: wait_for_access_via_adb Usage: wait_for_access_via_adb [ignorerc] [kill] [[timeout=]timeout_in_seconds] # default: 30 seconds
Task: wait_for_phone_state Usage: wait_for_phone_state [ignorerc] [state|state=#] [timeout=timeout_in_seconds] # default: 3 30 ; use 0 for infinite; set TIMEOUT_VALUE to define the timeout value via env variable
Task: wait_n_seconds Usage: wait_n_seconds [wait_time] [step_count] # default for wait_time is 60 and default for step count is 5
Task: wipe_dalvik_and_cache_via_twrp Usage: wipe_dalvik_and_cache_via_twrp [reboot|noreboot|reboot=no|reboot=yes] [twrp_imagefile] [ignorerc] [force|noforce]
33 task(s) defined.
Defined Task groups are:
abort_on_error :
task_enable_disable_abort_on_error:enable
install_magisk :
install_the_magisk_app
install_magisk_in_boot_partition:current
wait_for_access_via_adb:60:kill
enable_root_access_for_the_shell:reboot
wait_for_access_via_adb:60:kill
check_root_access
install_essential_magisk_modules:reboot
no_abort_on_error :
task_enable_disable_abort_on_error:disable
refresh :
task_update_include_file
refresh_all :
download_scripts:default
task_update_include_file
update_os :
enable_disable_abort_on_error:enable
boot_phone_from_twrp_image
install_os:noreboot
install_twrp:noreboot:next
install_magisk_in_boot_partition:reboot:next
wait_for_androidos :
task_wait_for_phone_state:3
wait_for_bootloader :
task_wait_for_phone_state:4
wait_for_fastboot :
task_wait_for_phone_state:5
wait_for_lineageos_recovery :
task_wait_for_phone_state:7
wait_for_safemode :
task_wait_for_phone_state:6
wait_for_sideload :
task_wait_for_phone_state:8
wait_for_twrp_image :
task_wait_for_phone_state:1
wait_for_twrp_recovery :
task_wait_for_phone_state:2
Note: use ":" to separate the task name and the parameter
[27.01.2023 12:25 ] ### The logfile used was /var/tmp/prepare_phone.sh.log
[27.01.2023 12:25 ] ### The start time was 27.01.2023 12:25:09, the script runtime is (day:hour:minute:seconds) 0:00:00:00 (= 0 seconds)
[27.01.2023 12:25 ] ### prepare_phone.sh ended at 27.01.2023 12:25:09 (The PID of this process is 1024201; the RC is 0)
[ OmniRom 13 Dev - [email protected] /data/develop/android ] $
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:
Bash:
./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:
Bash:
./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:
Code:
[ OmniRom 13 Dev - [email protected] /data/develop/android/scripts_on_linux ] $ cat ./prepare_phone.conf
SCRIPT_DIR="/data/develop/android/scripts_on_linux"
OS_IMAGE_TO_INSTALL="/data/develop/android/OmniROM_13.0/out/target/product/zenfone8/omni-13-20230115-zenfone8-MICROG.zip"
TWRP_IMAGE="/data/backup/ASUS_ZENFONE8/twrp/twrp-3.7.0_12-0-I006D-enhanced.img"
MAGISK_APK_FILE="/data/backup/Android/EssentialApps/Magisk-v25.2.apk"
ESSENTIAL_APPS_DIR="/data/backup/Android/EssentialApps"
ESSENTIAL_SCRIPTS_DIR="/data/backup/Android/EssentialScripts/"
ESSENTIAL_MAGISK_MODULES_DIR="/data/backup/Android/EssentialMagiskModules"
SCRIPT_DIR_ON_THE_PHONE="/data/local/tmp/scripts"
UPLOAD_DIR_FOR_SCRIPTS_ON_THE_PHONE="/sdcard/Download/scripts"
UPLOAD_DIR_FOR_MAGISK_MODULES_ON_THE_PHONE="/sdcard/Download/MagiskModules"
APPS_FOR_ROOT_ACCESS="com.mixplorer,com.keramidas.TitaniumBackup,io.github.muntashirakon.AppManager,com.matoski.adbm,com.fox2code.mmm"
POST_INSTALL_SCRIPT="post_install.sh"
[ OmniRom 13 Dev - [email protected] /data/develop/android/scripts_on_linux ] $
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.
Bash:
./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: ./prepare_phone.sh --list_default_tasks
Code:
[ OmniRom 13 Dev - [email protected] /data/develop/android/scripts_on_linux ] $ ./prepare_phone.sh --list_default_tasks
[25.01.2023 19:48 ] ### prepare_phone.sh started at 25.01.2023 19:48:03 (The PID of this process is 510292)
[25.01.2023 19:48 ] ### Processing the parameter ...
[25.01.2023 19:48 ] Tasks to execute are: ""
[25.01.2023 19:48 ] Parameter for the function init_tasks are: ""
[25.01.2023 19:48 ] ### The logfile used is /var/tmp/prepare_phone.sh.log
[25.01.2023 19:48 ] Checking the include file "/data/develop/android/scripts_on_linux/prepare_phone.include" ...
[25.01.2023 19:48 ] Reading the include file "/data/develop/android/scripts_on_linux/prepare_phone.include" ...
Include files used are:
/data/develop/android/scripts_on_linux/prepare_phone.include
Tasks defined are
16 default task(s) defined:
enable_disable_abort_on_error:enable
boot_phone_from_twrp_image
install_os:noreboot:factory_reset
install_twrp:noreboot:next
install_magisk_in_boot_partition_only:noreboot:next
enable_adb:reboot
install_magisk_in_data_adb_only:noreboot:copy_apk
enable_root_access_for_the_shell:reboot
wait_for_access_via_adb:60:kill
install_the_magisk_app
enable_disable_abort_on_error:disable
install_essential_scripts
install_essential_apps
install_essential_magisk_modules
enable_root_access_for_apps:reboot
execute_script_on_the_phone:ignorerc
0 task(s) will be ignored if the parameter "all" is used:
[25.01.2023 19:48 ] ### The logfile used was /var/tmp/prepare_phone.sh.log
[25.01.2023 19:48 ] ### The start time was 25.01.2023 19:48:03, the script runtime is (day:hour:minute:seconds) 0:00:00:00 (= 0 seconds)
[25.01.2023 19:48 ] ### prepare_phone.sh ended at 25.01.2023 19:48:03 (The PID of this process is 510292; the RC is 0)
[ OmniRom 13 Dev - [email protected] /data/develop/android/scripts_on_linux ] $
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
enable root access for the shell via Magisk
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:
Bash:
./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:
Bash:
./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: Manual installation and configuration of the phone
Bash:
export OS_IMAGE_TO_INSTALL="/data/develop/android/OmniROM_13.0/out/target/product/zenfone8/omni-13-20230115-zenfone8-MICROG.zip"
export TWRP_IMAGE="/data/backup/ASUS_ZENFONE8/twrp/twrp-3.7.0_12-0-I006D-enhanced.img"
export MAGISK_APK_FILE="/data/backup/Android/EssentialApps/Magisk-v25.2.apk"
cd /data/develop/android/scripts_on_linux
./boot_phone_from_twrp.sh
./install_os_via_twrp.sh factory_reset noreboot $OS_IMAGE_TO_INSTALL
./install_twrp.sh next noreboot
./install_magisk_via_twrp.sh next copy_apk delete_adb_dir noreboot magisk_apk_file=$MAGISK_APK_FILE
./enable_access_via_adb.sh reboot
adb wait-for-device
./install_magisk_via_twrp.sh adb_only copy_apk noreboot
./init_magisk_db.sh reboot
./install_apk.sh $MAGISK_APK_FILE
adb shell pm grant com.topjohnwu.magisk android.permission.POST_NOTIFICATIONS
# to install an app (example)
./install_apk.sh /data/backup/Android/EssentialApps/MiXplorer_v6.58.8_B23010320.apk
# to install a Magisk Module (example)
adb push /data/backup/Android/EssentialMagiskModules/addbin-v1.3.0.0.zip /sdcard/Download/MagiskModules/addbin-v1.3.0.0.zip
adb shell su - -c magisk --install-module /sdcard/Download/MagiskModules/addbin-v1.3.0.0.zip
# to enable root access for other apps (example)
#
./init_magisk_db.sh apps=+com.mixplorer,com.keramidas.TitaniumBackup,io.github.muntashirakon.AppManager,com.matoski.adbm,com.fox2code.mmm
To update the OS manual using the scripts use these commands (assuming Magisk is already installed):
Spoiler: Manual update the OS on the phone
Bash:
export OS_IMAGE_TO_INSTALL="/data/develop/android/OmniROM_13.0/out/target/product/zenfone8/omni-13-20230115-zenfone8-MICROG.zip"
export TWRP_IMAGE="/data/backup/ASUS_ZENFONE8/twrp/twrp-3.7.0_12-0-I006D-enhanced.img"
cd /data/develop/android/scripts_on_linux
./boot_phone_from_twrp.sh
./install_os_via_twrp.sh noreboot $OS_IMAGE_TO_INSTALL
./install_twrp.sh next noreboot
./install_magisk_via_twrp.sh next reboot
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

How To Guide How to configure the WiFI in Android via script

In the current version of Android the WiFi configuration is stored in the file
/data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
e.g.
Code:
ASUS_I006D:/ # ls -lZtr /data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
-rw------- 1 system system u:object_r:apex_system_server_data_file:s0 4884 2023-01-29 08:55 /data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
ASUS_I006D:/ #
The file is in plain ASCII xml format so it can be processed by any executable to change text files (editor, sed, etc).
But IMHO it's better to configure the WiFi manually via GUI and then use the file WifiConfigStore.xml with that configuration for configuring the WiFi via script. Therefor I use this code in the post install script to install and configure my phone (see How to install and configure the Android OS via Script):
Spoiler: script commands to enable and configure WiFi
Bash:
#
# sample post install script for the customizing of the phone
#
# This script will be copied to the phone and executed there
#
# The script is executed by the user shell; use "su - -c <command>" to execute commands as user root
#
echo ""
echo "*** Postinstall script is running ..."
echo ""
# ... other customizations ....
#
# create the WiFi config file
#
# -rw------- 1 system system u:object_r:apex_system_server_data_file:s0 4884 2023-01-29 08:55 /data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
#
WIFI_CONFIG_FILE="/data/misc/apexdata/com.android.wifi/WifiConfigStore.xml"
WIFI_CONFIG_FILE_BACKUP="${WIFI_CONFIG_FILE}.$$.bkp"
NEW_WIFI_CONFIG_FILE="/sdcard/Download/WifiConfigStore.xml"
if [ -r "${WIFI_CONFIG_FILE}" ] ; then
echo "Creating a backup of the file \"${WIFI_CONFIG_FILE}\" in \"${WIFI_CONFIG_FILE_BACKUP}\" ...."
cp "${WIFI_CONFIG_FILE}" "${WIFI_CONFIG_FILE_BACKUP}"
fi
echo "Creating the file \"${NEW_WIFI_CONFIG_FILE}\" ..."
cat >"${NEW_WIFI_CONFIG_FILE}" <<-\EOT
*** add here the contents of the file /data/misc/apexdata/com.android.wifi/WifiConfigStore.xml from the phone after manually configuring the WLAN
EOT
if [ $? -eq 0 ] ; then
echo "Creating the file \"${WIFI_CONFIG_FILE}\" ..."
su - -c cp "${NEW_WIFI_CONFIG_FILE}" "${WIFI_CONFIG_FILE}" && \
su - -c chmod 600 "${WIFI_CONFIG_FILE}" && \
su - -c chown system:system "${WIFI_CONFIG_FILE}" && \
su - -c chcon -v "u:object_r:apex_system_server_data_file:s0" "${WIFI_CONFIG_FILE}"
if [ $? -ne 0 ] ; then
echo "Error creating the file \"${WIFI_CONFIG_FILE}\" "
fi
else
echo "Error creating the file \"${NEW_WIFI_CONFIG_FILE}\" "
fi
# enable WiFi
#
echo "Enabling WiFi ..."
svc wifi enable
# optional: Disable mobile data connections
#
echo "Disabling mobile data ..."
svc data disable
# Now reboot the phone to activate the new WiFi config ..
#
echo "Waiting 15 seconds now before rebooting - press CTRL-C to abort ...."
i=0
while [ $i -lt 15 ] ; do
(( i = i + 1 ))
printf "."
sleep 1
done
printf "\n"
echo "Now rebooting the phone ..."
reboot
#
Notes:
Be aware the the file /data/misc/apexdata/com.android.wifi/WifiConfigStore.xml contains the passwords for all configured WLANs in plain text.
There should be a command to force Android to reread the file WifIConfigStore.xml but I don't know that.
Android can be forced to re-read the file WifIConfigStore.xml by killing the process system_server, e.g:
Bash:
pkill system_server
But that is more or less a warm reboot and I do not know what other side effects that restart triggers
There is an app to configure WiFi via adb command
https://github.com/steinwurf/adb-join-wifi
Bash:
adb shell am start -n com.steinwurf.adbjoinwifi/.MainActivity -e ssid myssid -e password mywlan_password -e password_type WPA
The app works but unfortunately it does not support enabling the setting to use the device MAC instead of the random MAC so it's not usable in my environment.
Another app to configure WiFi via adb command is available here:
https://github.com/pr4bh4sh/adb-wifi-setting-manager
Unfortunately that app also does not support enabling choosing the MAC address for the connection.
There is also a script to convert an old Android wpa_supplicant.conf file to the newer (post-Oreo) WifiConfigStore.xml file (not tested):
https://github.com/mnalis/android-wifi-upgrade
It's also possible to use the command wpa_cli to configure WiFi but be aware the wpa_cli only works if selinux is (temporary) disabled, example:
Spoiler: wpa_cli example
Code:
ASUS_I006D:/ $ su -
ASUS_I006D:/ #
ASUS_I006D:/ # setenforce 0
ASUS_I006D:/ #
ASUS_I006D:/ #
ASUS_I006D:/ # wpa_cli
wpa_cli v2.10-devel-11
Copyright (c) 2004-2019, Jouni Malinen <[email protected]> and contributors
This software may be distributed under the terms of the BSD license.
See README for more details.
Using interface 'wlan0'
Interactive mode
<3>Control interface command 'BSS RANGE=ALL MASK=0x2'
<3>Control interface command 'LIST_CREDS'
<3>Control interface command 'LIST_NETWORKS'
<3>Control interface command 'STA-FIRST'
>
> list_networks
network id / ssid / bssid / flags
0 Zeilsheim any [CURRENT]
1 any [DISABLED]
<3>Control interface command 'LIST_NETWORKS'
>
> quit
ASUS_I006D:/ #
Note: Use help to get list of known commands
Test Environment
I tested the WiFi config via script described above in these Android distributions:
OmniROM 13 (Android 13)
OmniROM 12 (Android 12)
ASUS Android 12
ASUS Android 13
This method seems not to work in Android 11

Categories

Resources