33set -euo pipefail
44shopt -s nullglob
55trap " rm -rf temp/*tmp.* temp/*/*tmp.* temp/*-temporary-files; kill 0; exit 130" INT
6+ [[ " ${1-} " == " clean" ]] && { rm -rf temp build logs build.md; exit 0; }
67
7- if [ " ${1-} " = " clean" ]; then
8- rm -rf temp build logs build.md
9- exit 0
10- fi
11-
8+ # shellcheck disable=SC1091
129source utils.sh
1310set_prebuilts
1411_UA=$( ua)
@@ -18,96 +15,89 @@ install_pkg jq
1815install_pkg java openjdk-21-jdk
1916install_pkg unzip
2017
21- if [ " ${1-} " = " separate-config" ] || [ " ${1-} " = " combine-logs" ] || [ " ${1-} " = " get-matrix" ]; then
22- case " ${1} " in
23- separate-config) separate_config " ${@: 2} " ;;
24- combine-logs) combine_logs " ${@: 2} " ;;
25- get-matrix) get_matrix " ${@: 2} " ;;
26- esac
27- exit 0
28- fi
18+ case " ${1-} " in
19+ separate-config) separate_config " ${@: 2} " ; exit 0 ;;
20+ combine-logs) combine_logs " ${@: 2} " ; exit 0 ;;
21+ get-matrix) get_matrix " ${@: 2} " ; exit 0 ;;
22+ esac
2923
30- vtf () { if ! isoneof " ${1} " " true" " false" ; then abort " ERROR: '${1} ' is not a valid option for '${2} ': only true or false is allowed" ; fi ; }
24+ vtf () { isoneof " $1 " " true" " false" || abort " ERROR: '$1 ' is not a valid option for '$2 ': only true or false is allowed" ; }
3125
3226# -- Main config --
3327toml_prep " ${1:- config.toml} " || abort " could not find config file '${1:- config.toml} '\n\tUsage: $0 <config.toml>"
34- main_config_t=$( toml_get_table_main)
35- PARALLEL_JOBS=$( toml_get " $main_config_t " parallel-jobs) || PARALLEL_JOBS=$( nproc)
36- DEF_PATCHES_VER=$( toml_get " $main_config_t " patches-version) || DEF_PATCHES_VER=" latest"
37- DEF_CLI_VER=$( toml_get " $main_config_t " cli-version) || DEF_CLI_VER=" latest"
38- DEF_PATCHES_SRC=$( toml_get " $main_config_t " patches-source) || DEF_PATCHES_SRC=" MorpheApp/morphe-patches"
39- DEF_CLI_SRC=$( toml_get " $main_config_t " cli-source) || DEF_CLI_SRC=" MorpheApp/morphe-cli"
40- DEF_BRAND=$( toml_get " $main_config_t " brand) || DEF_BRAND=" Morphe"
41- DEF_DPI_LIST=$( toml_get " $main_config_t " dpi) || DEF_DPI_LIST=" nodpi anydpi 120-640dpi"
28+ main_config_t=" $( toml_get_table_main) "
29+ PARALLEL_JOBS=" $( toml_get " $main_config_t " parallel-jobs) " || PARALLEL_JOBS=" $( nproc) "
30+ DEF_PATCHES_VER=" $( toml_get " $main_config_t " patches-version) " || DEF_PATCHES_VER=" latest"
31+ DEF_CLI_VER=" $( toml_get " $main_config_t " cli-version) " || DEF_CLI_VER=" latest"
32+ DEF_PATCHES_SRC=" $( toml_get " $main_config_t " patches-source) " || DEF_PATCHES_SRC=" MorpheApp/morphe-patches"
33+ DEF_CLI_SRC=" $( toml_get " $main_config_t " cli-source) " || DEF_CLI_SRC=" MorpheApp/morphe-cli"
34+ DEF_BRAND=" $( toml_get " $main_config_t " brand) " || DEF_BRAND=" Morphe"
35+ DEF_DPI_LIST=" $( toml_get " $main_config_t " dpi) " || DEF_DPI_LIST=" nodpi anydpi 120-640dpi"
4236mkdir -p " $TEMP_DIR " " $BUILD_DIR "
4337
4438: > build.md
4539
4640for file in " $TEMP_DIR " /* /changelog.md; do
47- [ -f " $file " ] && : > " $file "
41+ [[ -f " $file " ] ] && : > " $file "
4842done
4943
5044idx=0
5145for table_name in $( toml_get_table_names) ; do
52- if [ -z " $table_name " ]; then continue ; fi
53- t=$( toml_get_table " $table_name " )
54- enabled=$( toml_get " $t " enabled) || enabled=true
46+ [[ -z " $table_name " ]] && continue
47+ t=" $( toml_get_table " $table_name " ) "
48+ enabled=" $( toml_get " $t " enabled) " || enabled=" true"
5549 vtf " $enabled " " enabled"
56- if [ " $enabled " = false ] ; then continue ; fi
50+ [[ " $enabled " == " false" ]] && continue
5751 if (( idx >= PARALLEL_JOBS)) ; then
5852 wait -n
59- idx= $(( idx - 1 ))
53+ (( idx -- ))
6054 fi
6155
6256 declare -A app_args
63- patches_src=$( toml_get " $t " patches-source) || patches_src=$DEF_PATCHES_SRC
57+ patches_src=" $( toml_get " $t " patches-source) " || patches_src=" $DEF_PATCHES_SRC "
6458
65- if [ " ${BUILD_MODE:- } " = " dev" ]; then
59+ if [[ " ${BUILD_MODE:- } " == " dev" ] ]; then
6660 patches_ver=" dev"
6761 else
68- patches_ver=$( toml_get " $t " patches-version) || patches_ver=$DEF_PATCHES_VER
62+ patches_ver=" $( toml_get " $t " patches-version) " || patches_ver=" $DEF_PATCHES_VER "
6963 fi
70-
71- cli_src=$( toml_get " $t " cli-source) || cli_src=$DEF_CLI_SRC
72- cli_ver=$( toml_get " $t " cli-version) || cli_ver=$DEF_CLI_VER
7364
74- if ! PREBUILTS=" $( get_prebuilts " $cli_src " " $cli_ver " " $patches_src " " $patches_ver " ) " ; then
75- abort " could not download prebuilts"
76- fi
77- read -r cli_jar patches_jar <<< " $PREBUILTS"
78- app_args[cli]=$cli_jar
79- app_args[ptjar]=$patches_jar
80- app_args[brand]=$( toml_get " $t " brand) || app_args[brand]=$DEF_BRAND
81-
82- app_args[excluded_patches]=$( toml_get " $t " excluded-patches) || app_args[excluded_patches]=" "
83- if [ -n " ${app_args[excluded_patches]} " ] && [[ ${app_args[excluded_patches]} != * ' "' * ]]; then abort " patch names inside excluded-patches must be quoted" ; fi
84- app_args[included_patches]=$( toml_get " $t " included-patches) || app_args[included_patches]=" "
85- if [ -n " ${app_args[included_patches]} " ] && [[ ${app_args[included_patches]} != * ' "' * ]]; then abort " patch names inside included-patches must be quoted" ; fi
86- app_args[exclusive_patches]=$( toml_get " $t " exclusive-patches) && vtf " ${app_args[exclusive_patches]} " " exclusive-patches" || app_args[exclusive_patches]=false
87- app_args[version]=$( toml_get " $t " version) || app_args[version]=" auto"
88- app_args[app_name]=$( toml_get " $t " app-name) || app_args[app_name]=$table_name
89- app_args[patcher_args]=$( toml_get " $t " patcher-args) || app_args[patcher_args]=" "
90- app_args[table]=$table_name
91-
65+ cli_src=" $( toml_get " $t " cli-source) " || cli_src=" $DEF_CLI_SRC "
66+ cli_ver=" $( toml_get " $t " cli-version) " || cli_ver=" $DEF_CLI_VER "
67+
68+ PREBUILTS=" $( get_prebuilts " $cli_src " " $cli_ver " " $patches_src " " $patches_ver " ) " || abort " could not download prebuilts"
69+ read -r cli_jar patches_mpp <<< " $PREBUILTS"
70+ app_args[cli]=" $cli_jar "
71+ app_args[ptmpp]=" $patches_mpp "
72+ app_args[brand]=" $( toml_get " $t " brand) " || app_args[brand]=" $DEF_BRAND "
73+
74+ app_args[excluded_patches]=" $( toml_get " $t " excluded-patches) " || app_args[excluded_patches]=" "
75+ [[ -n " ${app_args[excluded_patches]} " && " ${app_args[excluded_patches]} " != * ' "' * ]] && abort " patch names inside excluded-patches must be quoted"
76+ app_args[included_patches]=" $( toml_get " $t " included-patches) " || app_args[included_patches]=" "
77+ [[ -n " ${app_args[included_patches]} " && " ${app_args[included_patches]} " != * ' "' * ]] && abort " patch names inside included-patches must be quoted"
78+ app_args[exclusive_patches]=" $( toml_get " $t " exclusive-patches) " && vtf " ${app_args[exclusive_patches]} " " exclusive-patches" || app_args[exclusive_patches]=" false"
79+ app_args[version]=" $( toml_get " $t " version) " || app_args[version]=" auto"
80+ app_args[app_name]=" $( toml_get " $t " app-name) " || app_args[app_name]=" $table_name "
81+ app_args[patcher_args]=" $( toml_get " $t " patcher-args) " || app_args[patcher_args]=" "
82+ app_args[table]=" $table_name "
83+
9284 for dl_from in " direct" " uptodown" " apkmirror" " archive" ; do
93- if app_args[${dl_from} _dlurl]=$( toml_get " $t " ${dl_from} -dlurl) ; then
94- app_args[${dl_from} _dlurl]=${app_args[${dl_from}_dlurl]%/ }
95- app_args[${dl_from} _dlurl]=${app_args[${dl_from}_dlurl]% download}
96- app_args[${dl_from} _dlurl]=${app_args[${dl_from}_dlurl]%/ }
97- app_args[dl_from]=${dl_from}
85+ if dl_url=" $( toml_get " $t " " ${dl_from} -dlurl" ) " ; then
86+ dl_url=" ${dl_url%/ } " ;
87+ dl_url=" ${dl_url% download} " ;
88+ dl_url=" ${dl_url%/ } "
89+ app_args[${dl_from} _dlurl]=" $dl_url "
90+ app_args[dl_from]=" $dl_from "
9891 else
9992 app_args[${dl_from} _dlurl]=" "
10093 fi
10194 done
102- if [ -z " ${app_args[dl_from]-} " ]; then abort " ERROR: no 'apkmirror-dlurl', 'uptodown-dlurl' or 'archive-dlurl' option was set for '$table_name '." ; fi
103- app_args[arch]=$( toml_get " $t " arch) || app_args[arch]=" all"
104- if ! isoneof " ${app_args[arch]} " " both" " all" " arm64-v8a" " arm-v7a" " x86_64" " x86" ; then
105- abort " wrong arch '${app_args[arch]} ' for '$table_name '"
106- fi
107-
108- app_args[dpi]=$( toml_get " $t " dpi) || app_args[dpi]=" $DEF_DPI_LIST "
95+ [[ -z " ${app_args[dl_from]-} " ]] && abort " ERROR: no 'apkmirror-dlurl', 'uptodown-dlurl' or 'archive-dlurl' option was set for '$table_name '."
96+ app_args[arch]=" $( toml_get " $t " arch) " || app_args[arch]=" all"
97+ isoneof " ${app_args[arch]} " " both" " all" " arm64-v8a" " arm-v7a" " x86_64" " x86" || abort " wrong arch '${app_args[arch]} ' for '$table_name '"
98+ app_args[dpi]=" $( toml_get " $t " dpi) " || app_args[dpi]=" $DEF_DPI_LIST "
10999
110- if [ " ${app_args[arch]} " = both ]; then
100+ if [[ " ${app_args[arch]} " == " both" ] ]; then
111101 app_args[table]=" $table_name (arm64-v8a)"
112102 app_args[arch]=" arm64-v8a"
113103 idx=$(( idx + 1 ))
@@ -121,16 +111,14 @@ for table_name in $(toml_get_table_names); do
121111 idx=$(( idx + 1 ))
122112 build_uni " $( declare -p app_args) " &
123113 else
124- if ! isoneof " ${app_args[arch]} " " all" ; then
125- app_args[table]=" ${table_name} (${app_args[arch]} )"
126- fi
114+ isoneof " ${app_args[arch]} " " all" || app_args[table]=" ${table_name} (${app_args[arch]} )"
127115 idx=$(( idx + 1 ))
128116 build_uni " $( declare -p app_args) " &
129117 fi
130118done
131119wait
132120rm -rf temp/tmp.*
133- if [ -z " $( ls -A1 " ${ BUILD_DIR} " ) " ]; then abort " All builds failed." ; fi
121+ [[ -z " $( ls -A1 " $BUILD_DIR " ) " ]] && abort " All builds failed."
134122
135123log " \n- ▶️ » Install [MicroG-RE](https://github.com/MorpheApp/MicroG-RE/releases) for YouTube and YT Music APKs\n"
136124log " $( cat " $TEMP_DIR " /* /changelog.md) "
0 commit comments