[HELP] Variable Section - Tasker Tips & Tricks

I'm trying to get the time from a full date string. However occasionally it encounter the following error. Can someone help to fix this issue?
12.56.24/Variables doreplresult: |%time| -> |20-8-2022 15.00|
12.56.24/E Variable Section: %time -> %time
12.56.24/E Variable Section: ->
12.56.24/E FROM: 14 LENGTH 5
12.56.24/E Variable Section: %time: only 5 chars, last request 18
12.56.24/E result: stop task (error)
12.56.24/Variables doreplresult: |%time| -> |20-8-2022 15.00|
12.56.24/E Error: 1
12.56.24/MacroEdit action finished exeID 1 action no 7 code 597 status: Err next 7

Related

[GUIDE][Difficulty: Intermediate] Save top 100 quotes from your favourite subreddit

Greetings.
After successfully implementing this, I've tried
to take this task a further and tried to save the quotes in one (text) file at user desired location along with a prompt of how many posts user wants to pull from reddit.
Taker Detail : Get desired (totally customizable from variables) titles/quotes from popular subreddits (like r/quotes) and save them in a text file for future use.
GUIDE :
1. Task -> New Task
2. Variable -> Set -> Name "%subreddit" Value "quotes" {or your desired subreddit}
3. Variable -> Set -> Name "%NoOfPosts" Value "25" {25 by default, you can change it as well}
Go back to main Task view.
4. Scene -> New Scene -> Name : Reddit1.
5. Add a TextFiled -> Name : How many posts?
6. Add Element -> NumberPicker -> Set Min : 1 , Max=100, Default = 25. Go to VALUE SELECTED Tab ->
New Action -> Variable Set -> Name : "%NoOfPosts" to "%new_val" {Thanks to Reddit API, max can be 100 only}
7. Go Back to main scene edit screen.
8. Add Element -> Button -> Label : "OK" -> Go to TAP tab -> Add Action -> Destroy Scene -> Name : "Reddit1".
9. Go Back to TASKS tab.
10. Go to previously created task. {from step 3}
11. SCENE -> Show Scene -> Select "Reddit1" -> UnCheck : Continue Task Immediately
12. Add -> Alert -> Flash -> Text : Getting your data from %subreddit.
13. Add -> NET -> HTTP Get -> Serverort = "json.reddit.com/r/%subreddit/top/?sort=top&t=all&limit=%NoOfPosts" -> TimeOut : 82 {Again thanks to Reddit api} {You can change sort modes by looking at the reddit api}
14. Add -> Alert -> Flash -> Text : Saving %NoOfPosts posts from r/%subreddit...
15. Add -> Code -> Java Scriptlet -> Add following code :
Code:
var arr = JSON.parse(global("HTTPD"));
var i = 0;
var mytext = "";
var myarr = [];
var i2 = 0;
var path1 ="/storage/emulated/0/apks/myquotes3.txt";
var newtext = "";
for (;arr.data.children[i];) {
myarr.push(arr.data.children[i].data.title);
i++;
}
for(;myarr[i2];)
{
newtext = myarr[i2] + "\n \n" ;
var ok = writeFile(path1, newtext, true )
i2++;
}
{you need to change the 'path1' variable}
16. Add-> Variable Clear -> Name : %HTTPD*
17. Add -> Alert -> Text : Saved!
Congratulations. You've saved some of the good life quotes directly from reddit.
Future enhancements : We can make some automated task where from this text file, daily (or at some interval) we can grab one quote and post it to any particular WhatsApp group or even send a text message.
New Ideas are always welcomed.
Screenshots here.
@tjhackz : Thank you for sharing! By the way, there is a ";" missing after ")" , before i2++. I was getting a error because that. You should edit your post and add it, because new tasker beginners ( like me ) will have a problem . Once again, thank you!

[question] task to set values in terminal after boot

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.

Failed to initialize editor

Hello,
I have fresh install OS
Linux Mint 20 Ulyana (Cinnamon)
and android-studio works propely, except the activity design editor. It yust says: "Failed to initialize editor". For a more information I launched it in terminal.
I tried to reinstall and resyc everything, still not work. Even with a new basic template activity project.
Here is log from terminal:
[email protected] /opt/android-studio/bin $ sh studio.sh
2020-07-19 15:47:21,571 [ 916] WARN - com.intellij.ide.ui.LafManager - List.rowHeight = 0 in Darcula; it may lead to performance degradation
2020-07-19 15:47:21,572 [ 917] WARN - com.intellij.ide.ui.LafManager - Table.rowHeight = 0 in Darcula; it may lead to performance degradation
2020-07-19 15:47:21,572 [ 917] WARN - com.intellij.ide.ui.LafManager - Tree.rowHeight = 0 in Darcula; it may lead to performance degradation
2020-07-19 15:47:21,627 [ 972] WARN - nSystem.impl.ActionManagerImpl - keymap "ReSharper" not found [Plugin: com.android.tools.ndk]
2020-07-19 15:47:24,108 [ 3453] WARN - #com.android.ddmlib - * daemon not running; starting now at tcp:5037
2020-07-19 15:47:24,233 [ 3578] WARN - #com.android.ddmlib - * daemon started successfully
2020-07-19 15:47:24,682 [ 4027] WARN - ugins.textmate.TextMateService - Missing builtin bundles, checked:
/home/martin/.AndroidStudio4.0/config/plugins/textmate/lib/bundles
/opt/android-studio/plugins/textmate/lib/bundles
2020-07-19 15:47:25,121 [ 4466] WARN - com.intellij.util.xmlb.Binding - no accessors for class org.jetbrains.kotlin.idea.highlighter.KotlinDefaultHighlightingSettingsProvider
2020-07-19 15:47:29,314 [ 8659] WARN - com.intellij.util.xmlb.Binding - no accessors for class org.jetbrains.kotlin.idea.scripting.gradle.GradleScriptInputsWatcher$Storage
2020-07-19 15:47:29,330 [ 8675] WARN - com.intellij.util.xmlb.Binding - no accessors for class org.jetbrains.kotlin.idea.core.script.configuration.utils.ScriptClassRootsStorage
2020-07-19 15:47:42,804 [ 22149] WARN - mon.editor.DesignerEditorPanel - Failed to initialize DesignerEditorPanel
java.util.concurrent.CompletionException: java.lang.IllegalStateException: Could not init NlModel. AndroidFacet is unexpectedly null. That might happen if the file does not belong to an Android module of the project.
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)
at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1606)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: Could not init NlModel. AndroidFacet is unexpectedly null. That might happen if the file does not belong to an Android module of the project.
at com.android.tools.idea.common.editor.DesignerEditorPanel.createAndInitNeleModel(DesignerEditorPanel.java:223)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604)
... 3 more
Click to expand...
Click to collapse
Solution
MartinK7 said:
Hello,
I have fresh install OS
Linux Mint 20 Ulyana (Cinnamon)
and android-studio works propely, except the activity design editor. It yust says: "Failed to initialize editor". For a more information I launched it in terminal.
I tried to reinstall and resyc everything, still not work. Even with a new basic template activity project.
Here is log from terminal:
Click to expand...
Click to collapse
Newer mind I FOUND a solution
Change in stytes.xml this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to this:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

How to convert image to base64 and store it in a variable

I am trying to convert image saved by the AutoNotifications but it's not working.
Code:
GET APP DETAILS (3)
A1: AutoNotification Query [ Configurationersistency Type: Non-Persistent Only
Package: %evtprm(1)
Get All Fields : true Timeout (Seconds):2 Structure Output:On ]
A2: Variable Split [ Name:%anstatusbaricon Splitter:, Delete Base:Off Regex:Off ]
A3: Text Dialog [ Title:. Text:%anstatusbaricon1 Button 1: Button 2: Button 3: Close After (Seconds):30 Use HTML:Off ]
A4: Read Binary [ File:%anstatusbaricon1 To Var:%b64img ]
A5: Text Dialog [ Title:Base 64 string Text:%b64img Button 1:Ok Button 2: Button 3: Close After (Seconds):30 Use HTML:Off ]

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

Categories

Resources