forked from j-hc/revanced-magisk-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.sh
executable file
·479 lines (446 loc) · 17.4 KB
/
utils.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
#!/usr/bin/env bash
MODULE_TEMPLATE_DIR="revanced-magisk"
MODULE_SCRIPTS_DIR="scripts"
TEMP_DIR="temp"
BUILD_DIR="build"
PKGS_LIST="${TEMP_DIR}/module-pkgs"
if [ "${GITHUB_TOKEN:-}" ]; then GH_HEADER="Authorization: token ${GITHUB_TOKEN}"; else GH_HEADER=; fi
GITHUB_REPOSITORY=${GITHUB_REPOSITORY:-"j-hc/revanced-magisk-module"}
NEXT_VER_CODE=${NEXT_VER_CODE:-$(date +'%Y%m%d')}
WGET_HEADER="User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0"
REBUILD=false
OS=$(uname -o)
SERVICE_SH=$(cat $MODULE_SCRIPTS_DIR/service.sh)
CUSTOMIZE_SH=$(cat $MODULE_SCRIPTS_DIR/customize.sh)
UNINSTALL_SH=$(cat $MODULE_SCRIPTS_DIR/uninstall.sh)
# -------------------- json/toml --------------------
json_get() { grep -o "\"${1}\":[^\"]*\"[^\"]*\"" | sed -E 's/".*".*"(.*)"/\1/'; }
toml_prep() { __TOML__=$(echo "$1" | tr -d '\t\r' | tr "'" '"' | grep -o '^[^#]*' | grep -v '^$' | sed -r 's/(\".*\")|\s*/\1/g; 1i []'); }
toml_get_table_names() {
local tn
tn=$(echo "$__TOML__" | grep -x '\[.*\]' | tr -d '[]') || return 1
if [ "$(echo "$tn" | sort | uniq -u | wc -l)" != "$(echo "$tn" | wc -l)" ]; then
abort "ERROR: Duplicate tables in TOML"
fi
echo "$tn"
}
toml_get_table() { sed -n "/\[${1}]/,/^\[.*]$/p" <<<"$__TOML__"; }
toml_get() {
local table=$1 key=$2 val
val=$(grep -m 1 "^${key}=" <<<"$table") && echo "${val#*=}" | sed -e "s/^\"//; s/\"$//"
}
# ---------------------------------------------------
pr() { echo -e "\033[0;32m[+] ${1}\033[0m"; }
epr() { echo -e "\033[0;31m[-] ${1}\033[0m"; }
abort() { echo >&2 -e "\033[0;31mABORT: $1\033[0m" && exit 1; }
get_prebuilts() {
pr "Getting prebuilts"
local rv_cli_url rv_integrations_url rv_patches rv_patches_changelog rv_patches_dl rv_patches_url rv_integrations_rel rv_patches_rel
rv_cli_url=$(gh_req "https://api.github.com/repos/j-hc/revanced-cli/releases/latest" - | json_get 'browser_download_url') || return 1
RV_CLI_JAR="${PREBUILTS_DIR}/${rv_cli_url##*/}"
log "CLI: ${rv_cli_url##*/}"
if [ "$CONF_INTEGRATIONS_VER" ]; then
rv_integrations_rel="https://api.github.com/repos/${INTEGRATIONS_SRC}/releases/tags/${CONF_INTEGRATIONS_VER}"
else
rv_integrations_rel="https://api.github.com/repos/${INTEGRATIONS_SRC}/releases/latest"
fi
if [ "$CONF_PATCHES_VER" ]; then
rv_patches_rel="https://api.github.com/repos/${PATCHES_SRC}/releases/tags/${CONF_PATCHES_VER}"
else
rv_patches_rel="https://api.github.com/repos/${PATCHES_SRC}/releases/latest"
fi
rv_integrations_url=$(gh_req "$rv_integrations_rel" - | json_get 'browser_download_url')
RV_INTEGRATIONS_APK="${PREBUILTS_DIR}/${rv_integrations_url##*/}"
log "Integrations: ${rv_integrations_url##*/}"
rv_patches=$(gh_req "$rv_patches_rel" -)
rv_patches_changelog=$(echo "$rv_patches" | json_get 'body' | sed 's/\(\\n\)\+/\\n/g')
rv_patches_dl=$(json_get 'browser_download_url' <<<"$rv_patches")
RV_PATCHES_JSON="${PREBUILTS_DIR}/patches-$(json_get 'tag_name' <<<"$rv_patches").json"
rv_patches_url=$(grep 'jar' <<<"$rv_patches_dl")
RV_PATCHES_JAR="${PREBUILTS_DIR}/${rv_patches_url##*/}"
[ -f "$RV_PATCHES_JAR" ] || REBUILD=true
log "Patches: ${rv_patches_url##*/}"
log "\n${rv_patches_changelog//# [/### [}\n"
dl_if_dne "$RV_CLI_JAR" "$rv_cli_url"
dl_if_dne "$RV_INTEGRATIONS_APK" "$rv_integrations_url"
dl_if_dne "$RV_PATCHES_JAR" "$rv_patches_url"
dl_if_dne "$RV_PATCHES_JSON" "$(grep 'json' <<<"$rv_patches_dl")"
if [ "$OS" = Android ]; then
local arch
if [ "$(uname -m)" = aarch64 ]; then arch=arm64; else arch=arm; fi
dl_if_dne ${TEMP_DIR}/aapt2 https://github.com/rendiix/termux-aapt/raw/d7d4b4a344cc52b94bcdab3500be244151261d8e/prebuilt-binary/${arch}/aapt2
fi
mkdir -p ${MODULE_TEMPLATE_DIR}/bin/arm64 ${MODULE_TEMPLATE_DIR}/bin/arm
dl_if_dne "${MODULE_TEMPLATE_DIR}/bin/arm64/cmpr" "https://github.com/j-hc/cmpr/releases/latest/download/cmpr-arm64-v8a"
dl_if_dne "${MODULE_TEMPLATE_DIR}/bin/arm/cmpr" "https://github.com/j-hc/cmpr/releases/latest/download/cmpr-armeabi-v7a"
HTMLQ="${TEMP_DIR}/htmlq"
if [ ! -f "${TEMP_DIR}/htmlq" ]; then
if [ "$OS" = Android ]; then
if [ "$arch" = arm64 ]; then
arch=arm64-v8a
else
arch=armeabi-v7a
fi
dl_if_dne ${TEMP_DIR}/htmlq https://github.com/j-hc/htmlq-ndk/releases/latest/download/htmlq-${arch}
chmod +x $HTMLQ
else
req "https://github.com/mgdm/htmlq/releases/latest/download/htmlq-x86_64-linux.tar.gz" "${TEMP_DIR}/htmlq.tar.gz"
tar -xf "${TEMP_DIR}/htmlq.tar.gz" -C "$TEMP_DIR"
rm "${TEMP_DIR}/htmlq.tar.gz"
fi
fi
}
set_prebuilts() {
[ -d "$PREBUILTS_DIR" ] || abort "${PREBUILTS_DIR} directory could not be found"
RV_CLI_JAR=$(find "$PREBUILTS_DIR" -maxdepth 1 -name "revanced-cli-*.jar" | tail -n1)
[ "$RV_CLI_JAR" ] || abort "revanced cli not found"
log "CLI: ${RV_CLI_JAR#"$PREBUILTS_DIR/"}"
RV_INTEGRATIONS_APK=$(find "$PREBUILTS_DIR" -maxdepth 1 -name "revanced-integrations-*.apk" | tail -n1)
[ "$RV_INTEGRATIONS_APK" ] || abort "revanced integrations not found"
log "Integrations: ${RV_INTEGRATIONS_APK#"$PREBUILTS_DIR/"}"
RV_PATCHES_JAR=$(find "$PREBUILTS_DIR" -maxdepth 1 -name "revanced-patches-*.jar" | tail -n1)
[ "$RV_PATCHES_JAR" ] || abort "revanced patches not found"
log "Patches: ${RV_PATCHES_JAR#"$PREBUILTS_DIR/"}"
RV_PATCHES_JSON=$(find "$PREBUILTS_DIR" -maxdepth 1 -name "patches-*.json" | tail -n1)
[ "$RV_PATCHES_JSON" ] || abort "patches.json not found"
HTMLQ="${TEMP_DIR}/htmlq"
}
req() { wget -nv -O "$2" --header="$WGET_HEADER" "$1"; }
gh_req() { wget -nv -O "$2" --header="$GH_HEADER" "$1"; }
log() { echo -e "$1 " >>build.md; }
get_largest_ver() {
local max v
read -r max
semver_validate "$max" || return 1
while read -r v; do
if [ "$(semver_cmp "$max" "$v")" = 1 ]; then max=$v; fi
done
echo "$max"
}
get_patch_last_supported_ver() {
jq -r ".[] | select(.compatiblePackages[].name==\"${1}\") | .compatiblePackages[].versions" "$RV_PATCHES_JSON" | tr -d ' ,\t[]"' | sort -u | grep -v '^$' | get_largest_ver || return 1
}
semver_cmp() {
IFS=. read -r -a v1 <<<"${1//[^.0-9]/}"
IFS=. read -r -a v2 <<<"${2//[^.0-9]/}"
local c1="${1//[^.]/}"
local c2="${2//[^.]/}"
local mi=$((${#c1} < ${#c2} ? ${#c1} : ${#c2}))
for ((i = 0; i <= mi; i++)); do
if ((v1[i] > v2[i])); then
echo -1
return 0
elif ((v2[i] > v1[i])); then
echo 1
return 0
fi
done
echo 0
}
semver_validate() {
local a="${1%-*}"
local ac="${a//[.0-9]/}"
[ ${#ac} = 0 ]
}
dl_if_dne() {
if [ ! -f "$1" ]; then
pr "Getting '$1' from '$2'"
req "$2" "$1"
fi
}
isoneof() {
local i=$1 v
shift
for v; do [ "$v" = "$i" ] && return 0; done
return 1
}
# -------------------- apkmirror --------------------
dl_apkmirror() {
local url=$1 version=${2// /-} output=$3 arch=$4
local resp node app_table dlurl=""
[ "$arch" = universal ] && apparch=(universal noarch 'arm64-v8a + armeabi-v7a') || apparch=("$arch")
url="${url}/${url##*/}-${version//./-}-release/"
resp=$(req "$url" -) || return 1
for ((n = 2; n < 50; n++)); do
node=$($HTMLQ "div.table-row:nth-child($n)" -r "span.signature:nth-child(n)" <<<"$resp")
if [ -z "$node" ]; then break; fi
app_table=$($HTMLQ --text --ignore-whitespace <<<"$node")
if [ "$(sed -n 8p <<<"$app_table")" = nodpi ] &&
[ "$(sed -n 3p <<<"$app_table")" = APK ] &&
isoneof "$(sed -n 6p <<<"$app_table")" "${apparch[@]}"; then
dlurl=https://www.apkmirror.com$($HTMLQ --attribute href "div:nth-child(1) > a:nth-child(1)" <<<"$node")
break
fi
done
[ -z "$dlurl" ] && return 1
url="https://www.apkmirror.com$(req "$dlurl" - | tr '\n' ' ' | sed -n 's;.*href="\(.*key=[^"]*\)">.*;\1;p')"
url="https://www.apkmirror.com$(req "$url" - | tr '\n' ' ' | sed -n 's;.*href="\(.*key=[^"]*\)">.*;\1;p')"
req "$url" "$output"
}
get_apkmirror_vers() {
local apkmirror_category=$1 allow_alpha_version=$2
local vers apkm_resp
apkm_resp=$(req "https://www.apkmirror.com/uploads/?appcategory=${apkmirror_category}" -)
# apkm_name=$(echo "$apkm_resp" | sed -n 's;.*Latest \(.*\) Uploads.*;\1;p')
vers=$(sed -n 's;.*Version:</span><span class="infoSlide-value">\(.*\) </span>.*;\1;p' <<<"$apkm_resp")
if [ "$allow_alpha_version" = false ]; then
local IFS=$'\n'
vers=$(grep -iv "\(beta\|alpha\)" <<<"$vers")
local v
local r_vers=()
for v in $vers; do
grep -iq "${v} \(beta\|alpha\)" <<<"$apkm_resp" || r_vers+=("$v")
done
echo "${r_vers[*]}"
else
echo "$vers"
fi
}
get_apkmirror_pkg_name() { req "$1" - | sed -n 's;.*id=\(.*\)" class="accent_color.*;\1;p'; }
# --------------------------------------------------
# -------------------- uptodown --------------------
get_uptodown_resp() { req "${1}/versions" -; }
get_uptodown_vers() { sed -n 's;.*version">\(.*\)</span>$;\1;p' <<<"$1"; }
dl_uptodown() {
local uptwod_resp=$1 version=$2 output=$3
local url
url=$(echo "$uptwod_resp" | grep "${version}<\/span>" -B 2 | head -1 | sed -n 's;.*data-url="\(.*\)".*;\1;p') || return 1
url=$(req "$url" - | sed -n 's;.*data-url="\(.*\)".*;\1;p') || return 1
req "$url" "$output"
}
get_uptodown_pkg_name() {
local p
p=$(req "${1}/download" - | grep -A 1 "Package Name" | tail -1)
echo "${p:4:-5}"
}
# --------------------------------------------------
patch_apk() {
local stock_input=$1 patched_apk=$2 patcher_args=$3
declare -r tdir=$(mktemp -d -p $TEMP_DIR)
local cmd="java -jar $RV_CLI_JAR --rip-lib x86_64 --rip-lib x86 --temp-dir=$tdir -c -a $stock_input -o $patched_apk -b $RV_PATCHES_JAR --keystore=ks.keystore $patcher_args"
if [ "$OS" = Android ]; then
cmd+=" --custom-aapt2-binary=${TEMP_DIR}/aapt2"
fi
pr "$cmd"
if [ "${DRYRUN:-}" = true ]; then
cp -f "$stock_input" "$patched_apk"
else
eval "$cmd"
fi
[ -f "$patched_apk" ]
}
zip_module() {
pr "Packing module ($app_name)"
local patched_apk=$1 module_name=$2 stock_apk=$3 pkg_name=$4 template_dir=$5
cp -f "$patched_apk" "${template_dir}/base.apk"
cp -f "$stock_apk" "${template_dir}/${pkg_name}.apk"
pushd >/dev/null "$template_dir" || abort "Module template dir not found"
zip -"$COMPRESSION_LEVEL" -FSqr "../../${BUILD_DIR}/${module_name}" .
popd >/dev/null || :
}
build_rv() {
local -n args=$1
local version build_mode_arr pkg_name uptwod_resp
local mode_arg=${args[build_mode]} version_mode=${args[version]}
local app_name=${args[app_name]}
local app_name_l=${app_name,,}
local dl_from=${args[dl_from]}
local arch=${args[arch]}
local p_patcher_args=()
p_patcher_args+=("$(join_args "${args[excluded_patches]}" -e) $(join_args "${args[included_patches]}" -i)")
[ "${args[exclusive_patches]}" = true ] && p_patcher_args+=("--exclusive")
if [ "$dl_from" = apkmirror ]; then
pkg_name=$(get_apkmirror_pkg_name "${args[apkmirror_dlurl]}")
elif [ "$dl_from" = uptodown ]; then
uptwod_resp=$(get_uptodown_resp "${args[uptodown_dlurl]}")
pkg_name=$(get_uptodown_pkg_name "${args[uptodown_dlurl]}")
fi
local get_latest_ver=false
if [ "$version_mode" = auto ]; then
version=$(get_patch_last_supported_ver "$pkg_name") || get_latest_ver=true
elif [ "$version_mode" = latest ]; then
get_latest_ver=true
p_patcher_args+=("--experimental")
else
version=$version_mode
p_patcher_args+=("--experimental")
fi
if [ $get_latest_ver = true ]; then
local apkmvers uptwodvers
if [ "$dl_from" = apkmirror ]; then
apkmvers=$(get_apkmirror_vers "${args[apkmirror_dlurl]##*/}" "${args[allow_alpha_version]}")
version=$(get_largest_ver <<<"$apkmvers") || version=$(head -1 <<<"$apkmvers")
elif [ "$dl_from" = uptodown ]; then
uptwodvers=$(get_uptodown_vers "$uptwod_resp")
version=$(get_largest_ver <<<"$uptwodvers") || version=$(head -1 <<<"$uptwodvers")
fi
fi
if [ -z "$version" ]; then
pr "empty version, not building ${app_name}."
return 0
fi
pr "Choosing version '${version}' (${app_name})"
local version_f=${version// /}
local stock_apk="${TEMP_DIR}/${pkg_name}-${version_f}-${arch}.apk"
if [ ! -f "$stock_apk" ]; then
if [ "$dl_from" = apkmirror ]; then
pr "Downloading '${app_name}' from APKMirror"
local apkm_arch
if [ "$arch" = "all" ]; then
apkm_arch="universal"
elif [ "$arch" = "arm64-v8a" ]; then
apkm_arch="arm64-v8a"
elif [ "$arch" = "arm-v7a" ]; then
apkm_arch="armeabi-v7a"
fi
if ! dl_apkmirror "${args[apkmirror_dlurl]}" "$version" "$stock_apk" "$apkm_arch"; then
epr "ERROR: Could not find any release of '${app_name}' with version '${version}' and arch '${apkm_arch}' from APKMirror"
return 0
fi
elif [ "$dl_from" = uptodown ]; then
pr "Downloading '${app_name}' from Uptodown"
if ! dl_uptodown "$uptwod_resp" "$version" "$stock_apk"; then
epr "ERROR: Could not download ${app_name} from Uptodown"
return 0
fi
fi
fi
if [ "${arch}" = "all" ]; then
grep -q "${app_name}:" build.md || log "${app_name}: ${version}"
else
grep -q "${app_name} (${arch}):" build.md || log "${app_name} (${arch}): ${version}"
fi
if jq -r ".[] | select(.compatiblePackages[].name==\"${pkg_name}\") | .dependencies[]" "$RV_PATCHES_JSON" | grep -qF integrations; then
p_patcher_args+=("-m ${RV_INTEGRATIONS_APK}")
fi
local microg_patch
microg_patch=$(jq -r ".[] | select(.compatiblePackages[].name==\"${pkg_name}\") | .name" "$RV_PATCHES_JSON" | grep -F microg || :)
if [ "$microg_patch" ]; then
p_patcher_args=("${p_patcher_args[@]//-[ei] ${microg_patch}/}")
fi
local stock_bundle="${TEMP_DIR}/${pkg_name}-${version_f}-${arch}-bundle.zip"
local stock_bundle_apk="${TEMP_DIR}/${pkg_name}-${version_f}-${arch}-bundle.apk"
local is_bundle=false
if [ "$mode_arg" = module ] || [ "$mode_arg" = both ]; then
if [ -f "$stock_bundle_apk" ]; then
is_bundle=true
elif [ "$dl_from" = TODO ]; then
pr "Downloading '${app_name}' bundle from APKMirror"
if dl_apkmirror "${args[apkmirror_dlurl]}" "$version" "BUNDLE</span>[^@]*@\([^#]*\)" "$stock_bundle"; then
pr "'${app_name}' bundle was downloaded successfully and will be used for the module"
is_bundle=true
unzip "$stock_bundle" "base.apk" -d $TEMP_DIR
mv ${TEMP_DIR}/base.apk "$stock_bundle_apk"
rm -f "$stock_bundle"
else
pr "'${app_name}' bundle was not found"
fi
fi
fi
if [ "$mode_arg" = module ]; then
build_mode_arr=(module)
elif [ "$mode_arg" = apk ]; then
build_mode_arr=(apk)
elif [ "$mode_arg" = both ]; then
build_mode_arr=(apk module)
fi
local patcher_args patched_apk build_mode
for build_mode in "${build_mode_arr[@]}"; do
patcher_args=("${p_patcher_args[@]}")
pr "Building '${app_name}' (${arch}) in '$build_mode' mode"
if [ "$microg_patch" ]; then
patched_apk="${TEMP_DIR}/${app_name_l}-${RV_BRAND_F}-${version_f}-${arch}-${build_mode}.apk"
if [ "$build_mode" = apk ]; then
patcher_args+=("-i ${microg_patch}")
elif [ "$build_mode" = module ]; then
patcher_args+=("-e ${microg_patch}")
fi
else
patched_apk="${TEMP_DIR}/${app_name_l}-${RV_BRAND_F}-${version_f}-${arch}.apk"
fi
if [ "$build_mode" = module ]; then
if [ $is_bundle = false ]; then
patcher_args+=("--unsigned --rip-lib arm64-v8a --rip-lib armeabi-v7a")
else
patcher_args+=("--unsigned")
fi
fi
if [ ! -f "$patched_apk" ] || [ "$REBUILD" = true ]; then
if ! patch_apk "$stock_apk" "$patched_apk" "${patcher_args[*]}"; then
pr "Building '${app_name}' failed!"
return 0
fi
fi
if [ "$build_mode" = apk ]; then
local apk_output="${BUILD_DIR}/${app_name_l}-${RV_BRAND_F}-v${version_f}-${arch}.apk"
cp -f "$patched_apk" "$apk_output"
pr "Built ${app_name} (${arch}) (non-root): '${apk_output}'"
continue
fi
local base_template upj
base_template=$(mktemp -d -p $TEMP_DIR)
cp -a $MODULE_TEMPLATE_DIR/. "$base_template"
if [ "$BUILD_MINDETACH_MODULE" = true ] && ! grep -q "$pkg_name" $PKGS_LIST; then echo "$pkg_name" >>$PKGS_LIST; fi
if [ "$arch" = "all" ]; then
upj="${app_name_l}-update.json"
else
upj="${app_name_l}-${arch}-update.json"
fi
local isbndl extrct stock_apk_module
if [ $is_bundle = true ]; then
isbndl=""
extrct="base.apk"
stock_apk_module=$stock_bundle_apk
else
isbndl="!"
extrct="${pkg_name}.apk"
stock_apk_module=$stock_apk
fi
uninstall_sh "$pkg_name" "$isbndl" "$base_template"
service_sh "$pkg_name" "$version" "$base_template"
customize_sh "$pkg_name" "$version" "$arch" "$extrct" "$base_template"
module_prop \
"${args[module_prop_name]}" \
"${app_name} ${RV_BRAND}" \
"$version" \
"${app_name} ${RV_BRAND} Magisk module" \
"https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/update/${upj}" \
"$base_template"
local module_output="${app_name_l}-${RV_BRAND_F}-magisk-v${version}-${arch}.zip"
if [ ! -f "$module_output" ] || [ "$REBUILD" = true ]; then
zip_module "$patched_apk" "$module_output" "$stock_apk_module" "$pkg_name" "$base_template"
fi
pr "Built ${app_name} (${arch}) (root): '${BUILD_DIR}/${module_output}'"
done
}
join_args() {
echo "$1" | tr -d '\t\r' | tr ' ' '\n' | grep -v '^$' | sed "s/^/${2} /" | paste -sd " " - || :
}
uninstall_sh() {
local s="${UNINSTALL_SH//__PKGNAME/$1}"
echo "${s//__ISBNDL/$2}" >"${3}/uninstall.sh"
}
customize_sh() {
local s="${CUSTOMIZE_SH//__PKGNAME/$1}"
s="${s//__EXTRCT/$4}"
# shellcheck disable=SC2001
if [ "$3" = "arm64-v8a" ]; then
s=$(sed 's/#arm$/abort "ERROR: Wrong arch\nYour device: arm\nModule: arm64"/g' <<<"$s")
elif [ "$3" = "arm-v7a" ]; then
s=$(sed 's/#arm64$/abort "ERROR: Wrong arch\nYour device: arm64\nModule: arm"/g' <<<"$s")
fi
echo "${s//__PKGVER/$2}" >"${5}/customize.sh"
}
service_sh() {
local s="${SERVICE_SH//__PKGNAME/$1}"
echo "${s//__PKGVER/$2}" >"${3}/service.sh"
}
module_prop() {
echo "id=${1}
name=${2}
version=v${3}
versionCode=${NEXT_VER_CODE}
author=j-hc
description=${4}" >"${6}/module.prop"
if [ "$ENABLE_MAGISK_UPDATE" = true ]; then echo "updateJson=${5}" >>"${6}/module.prop"; fi
}