-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathutils.sh
More file actions
executable file
·2542 lines (2318 loc) · 90.3 KB
/
Copy pathutils.sh
File metadata and controls
executable file
·2542 lines (2318 loc) · 90.3 KB
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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
MODULE_TEMPLATE_DIR="module"
CWD=$(pwd)
TEMP_DIR="temp"
BIN_DIR="bin"
BUILD_DIR="build"
DL_SRCS=("direct" "github" "archive" "apkmirror" "uptodown" "apkpure" "apkcombo")
BUILD_JSON_FILE="build.json"
PATCH_OUTPUT=""
if [ "${GITHUB_TOKEN-}" ]; then GH_HEADER="Authorization: token ${GITHUB_TOKEN}"; else GH_HEADER=; fi
NEXT_VER_CODE=${NEXT_VER_CODE:-$(date +'%Y%m%d')}
OS=$(uname -o)
declare -gA __PREBUILTS_CACHE__
declare -gA __PATCHES_LIST_CACHE__
declare -gA __PATCH_VER_CACHE__
declare -gA __PKG_VERS_CACHE__
declare -gA __DL_RESP_CACHE__
toml_prep() {
if [ ! -f "$1" ]; then return 1; fi
if [ "${1##*.}" == toml ]; then
__TOML__=$($TOML --output json --file "$1" .)
elif [ "${1##*.}" == json ]; then
__TOML__=$(cat "$1")
else abort "config extension not supported"; fi
}
toml_get_table_names() { jq -r -e 'to_entries[] | select(.value | type == "object") | .key' <<<"$__TOML__"; }
toml_get_table_main() { jq -r -e 'to_entries | map(select(.value | type != "object")) | from_entries' <<<"$__TOML__"; }
toml_get_table() { jq -r -e ".\"${1}\"" <<<"$__TOML__"; }
toml_get() {
local op quote_placeholder=$'\001'
op=$(jq -r ".\"${2}\" | values" <<<"$1")
if [ "$op" ]; then
op="${op#"${op%%[![:space:]]*}"}"
op="${op%"${op##*[![:space:]]}"}"
op=${op//\\\'/$quote_placeholder}
op=${op//"''"/$quote_placeholder}
op=${op//"'"/'"'}
op=${op//$quote_placeholder/$'\''}
echo "$op"
else return 1; fi
}
pr() { echo >&2 -e "\033[0;32m[+] ${1}\033[0m"; }
epr() {
echo >&2 -e "\033[0;31m[-] ${1}\033[0m"
if [ "${GITHUB_REPOSITORY-}" ]; then echo >&2 -e "::error::utils.sh [-] ${1}\n"; fi
}
wpr() {
echo >&2 -e "\033[0;33m[!] ${1}\033[0m"
if [ "${GITHUB_REPOSITORY-}" ]; then echo >&2 -e "::warning::utils.sh [!] ${1}\n"; fi
}
abort() {
epr "ABORT: ${1-}"
rm -rf ./${TEMP_DIR}/*tmp.* ./${TEMP_DIR}/*/*tmp.* ./${TEMP_DIR}/*-temporary-files ./${TEMP_DIR}/*.apk-temporary-files ./*-temporary-files
trap - SIGTERM SIGINT EXIT
exit 1
}
java() { env -i PATH="$PATH" HOME="$HOME" LANG="${LANG:-en_US.UTF-8}" java --enable-native-access=ALL-UNNAMED "$@"; }
source_release_api_base() {
local host=${1,,} src=$2 encoded
case "$host" in
github) echo "https://api.github.com/repos/${src}/releases" ;;
gitlab)
encoded=$(jq -nr --arg v "$src" '$v | @uri')
echo "https://gitlab.com/api/v4/projects/${encoded}/releases"
;;
*) return 1 ;;
esac
}
source_release_tag_api() {
local host=${1,,} src=$2 tag=$3 base
base=$(source_release_api_base "$host" "$src") || return 1
case "$host" in
github) echo "${base}/tags/${tag}" ;;
gitlab) echo "${base}/${tag}" ;;
*) return 1 ;;
esac
}
source_release_assets_json() {
local host=${1,,}
case "$host" in
github) jq -e '[.assets[]? | select(.name | (endswith("asc") or endswith("json")) | not)]' ;;
gitlab) jq -e '[.assets.links[]? | select(.name | (endswith("asc") or endswith("json")) | not)]' ;;
*) return 1 ;;
esac
}
source_release_asset_url() {
local host=${1,,}
case "$host" in
github) jq -r '.url' ;;
gitlab) jq -r '.direct_asset_url // .url' ;;
*) return 1 ;;
esac
}
source_release_pick_from_list() {
local host=${1,,} mode=$2
case "$host" in
github)
if [ "$mode" = dev ]; then
jq -e -c 'map(select(.prerelease == true and .tag_name != null and .tag_name != "")) | sort_by(.published_at // .created_at // "") | reverse | .[0] // empty'
else
jq -e -c 'map(select(.prerelease != true and .tag_name != null and .tag_name != "")) | sort_by(.published_at // .created_at // "") | reverse | .[0] // empty'
fi
;;
gitlab)
if [ "$mode" = dev ]; then
jq -e -c 'map(select(.tag_name != null and .tag_name != "" and (.tag_name | test("(?i)(dev|alpha|beta|rc)")))) | sort_by(.released_at // .created_at // "") | reverse | .[0] // empty'
else
jq -e -c 'map(select(.tag_name != null and .tag_name != "" and (.tag_name | test("(?i)(dev|alpha|beta|rc)") | not))) | sort_by(.released_at // .created_at // "") | reverse | .[0] // empty'
fi
;;
*) return 1 ;;
esac
}
get_apkeditor() {
if [ -f "$TEMP_DIR/apkeditor.jar" ]; then return 0; fi
local api_resp dl_url
api_resp=$(gh_req "https://api.github.com/repos/REAndroid/APKEditor/releases/latest" -) || true
dl_url=$(echo "$api_resp" | jq -r '.assets[]? | select(.name | endswith(".jar")) | .browser_download_url' | head -1) || true
if [ -z "$dl_url" ] || [ "$dl_url" = "null" ]; then
dl_url="https://github.com/REAndroid/APKEditor/releases/download/V1.4.9/APKEditor-1.4.9.jar"
fi
gh_dl "$TEMP_DIR/apkeditor.jar" "$dl_url" >/dev/null || return 1
}
get_prebuilts() {
local cache_key="${1}_${2}_${3}_${4}_${5}_${6}"
if [ -n "${__PREBUILTS_CACHE__["$cache_key"]:-}" ]; then
echo "${__PREBUILTS_CACHE__["$cache_key"]}"
return 0
fi
local result
if ! result=$(_get_prebuilts "$@"); then return 1; fi
__PREBUILTS_CACHE__["$cache_key"]="$result"
echo "$result"
}
_get_prebuilts() {
local cli_host=$1 cli_src=$2 cli_ver=$3 patches_host_list=$4 patches_src_list=$5 patches_ver_list=$6
local first_patch_src
first_patch_src=$(list_args "$patches_src_list" | tr -d \"\' | head -n 1)
pr "Getting prebuilts (${first_patch_src%/*})" >&2
local cl_dir=${first_patch_src%/*}
cl_dir=${TEMP_DIR}/${cl_dir,,}-rv
[ -d "$cl_dir" ] || mkdir "$cl_dir"
local host=$cli_host src=$cli_src tag="CLI" ver=${cli_ver} fprefix="cli"
host=${host,,}
if ! isoneof "$host" github gitlab; then abort "source host '$host' is not supported"; fi
local grab_cl=false
local dir=${src%/*}
dir=${TEMP_DIR}/${dir,,}-rv
[ -d "$dir" ] || mkdir "$dir"
local rv_rel release resp tag_name matches asset name url
rv_rel=$(source_release_api_base "$host" "$src") || return 1
if [ "$ver" = "dev" ]; then
resp=$({ if [ "$host" = github ]; then gh_req "$rv_rel?per_page=100" -; else req "$rv_rel?per_page=100" -; fi; }) || return 1
release=$(source_release_pick_from_list "$host" dev <<<"$resp") || true
ver=$(jq -r '.tag_name' <<<"$release") || true
if [ -z "$ver" ] || [ "$ver" = "null" ]; then
ver=$(jq -e -r '.[].tag_name' <<<"$resp" | get_highest_ver) || return 1
release="" # Clear release if we had to fallback to get_highest_ver
fi
fi
if [ "$ver" = "latest" ]; then
resp=$({ if [ "$host" = github ]; then gh_req "$rv_rel?per_page=100" -; else req "$rv_rel?per_page=100" -; fi; }) || return 1
release=$(source_release_pick_from_list "$host" latest <<<"$resp") || return 1
elif [ -z "${release:-}" ]; then
rv_rel=$(source_release_tag_api "$host" "$src" "$ver") || return 1
release=$({ if [ "$host" = github ]; then gh_req "$rv_rel" -; else req "$rv_rel" -; fi; }) || return 1
fi
tag_name=$(jq -r '.tag_name' <<<"$release") || return 1
name_ver=$tag_name
local file
file=$(find "$dir" -name "*${fprefix}-${name_ver#v}.*" -type f 2>/dev/null | head -1)
if [ -z "$file" ]; then
matches=$(source_release_assets_json "$host" <<<"$release") || return 1
if [ "$(jq 'length' <<<"$matches")" -gt 1 ]; then
local matches_new
matches_new=$(jq -e -r 'map(select(.name | test("\\.(jar|zip)$"; "i")))' <<<"$matches" 2>/dev/null) || true
if [ -n "$matches_new" ] && [ "$(jq 'length' <<<"$matches_new")" -ge 1 ]; then
matches=$matches_new
fi
fi
if [ "$(jq 'length' <<<"$matches")" -gt 1 ]; then
local matches_new
matches_new=$(jq -e -r 'map(select(.name | contains("-dev") | not))' <<<"$matches")
if [ "$(jq 'length' <<<"$matches_new")" -eq 1 ]; then
matches=$matches_new
fi
fi
if [ "$(jq 'length' <<<"$matches")" -gt 1 ]; then
local matches_new
matches_new=$(jq -e -r 'map(select(.name | contains("debug") | not))' <<<"$matches")
if [ "$(jq 'length' <<<"$matches_new")" -ge 1 ]; then
matches=$matches_new
fi
fi
if [ "$(jq 'length' <<<"$matches")" -gt 1 ]; then
local matches_new
matches_new=$(jq --arg ver "${name_ver#v}" -e -r 'map(select(.name | contains($ver)))' <<<"$matches")
if [ "$(jq 'length' <<<"$matches_new")" -ge 1 ]; then
matches=$matches_new
fi
fi
if [ "$(jq 'length' <<<"$matches")" -eq 0 ]; then
epr "No asset was found"
return 1
elif [ "$(jq 'length' <<<"$matches")" -ne 1 ]; then
wpr "More than 1 asset was found for this release. Falling back to the first one found..."
fi
asset=$(jq -r ".[0]" <<<"$matches")
url=$(source_release_asset_url "$host" <<<"$asset")
name=$(jq -r .name <<<"$asset")
file="${dir}/${name}"
if [ "$host" = github ]; then
gh_dl "$file" "$url" >&2 || return 1
else
pr "Getting '$file' from '$url'"
_req "$url" "$file" -H "Accept: application/octet-stream" >&2 || return 1
fi
echo "$tag: $(cut -d/ -f1 <<<"$src")/${name} " >>"${cl_dir}/changelog.md"
else
grab_cl=false
name=$(basename "$file")
tag_name=$(cut -d'-' -f3- <<<"$name")
tag_name=v${tag_name%.*}
fi
echo -n "$file "
local IFS=$'\n'
local p_srcs=($(list_args "$patches_src_list" | tr -d \"\'))
local p_hosts=($(list_args "$patches_host_list" | tr -d \"\'))
local p_vers=($(list_args "$patches_ver_list" | tr -d \"\'))
unset IFS
for i in "${!p_srcs[@]}"; do
local host="${p_hosts[$i]:-${p_hosts[0]}}"
local src="${p_srcs[$i]}"
local ver="${p_vers[$i]:-${p_vers[0]}}"
host=${host,,}
if ! isoneof "$host" github gitlab; then abort "source host '$host' is not supported"; fi
local tag="Patches" fprefix="patches"
local grab_cl=true
local dir=${src%/*}
dir=${TEMP_DIR}/${dir,,}-rv
[ -d "$dir" ] || mkdir "$dir"
local rv_rel release resp tag_name matches asset name url
rv_rel=$(source_release_api_base "$host" "$src") || return 1
if [ "$ver" = "dev" ]; then
resp=$({ if [ "$host" = github ]; then gh_req "$rv_rel?per_page=100" -; else req "$rv_rel?per_page=100" -; fi; }) || return 1
release=$(source_release_pick_from_list "$host" dev <<<"$resp") || true
ver=$(jq -r '.tag_name' <<<"$release") || true
if [ -z "$ver" ] || [ "$ver" = "null" ]; then
ver=$(jq -e -r '.[].tag_name' <<<"$resp" | get_highest_ver) || return 1
release="" # Clear release if we had to fallback to get_highest_ver
fi
fi
if [ "$ver" = "latest" ]; then
resp=$({ if [ "$host" = github ]; then gh_req "$rv_rel?per_page=100" -; else req "$rv_rel?per_page=100" -; fi; }) || return 1
release=$(source_release_pick_from_list "$host" latest <<<"$resp") || return 1
elif [ -z "${release:-}" ]; then
rv_rel=$(source_release_tag_api "$host" "$src" "$ver") || return 1
release=$({ if [ "$host" = github ]; then gh_req "$rv_rel" -; else req "$rv_rel" -; fi; }) || return 1
fi
tag_name=$(jq -r '.tag_name' <<<"$release") || return 1
name_ver=$tag_name
local file
file=$(find "$dir" -name "*${fprefix}-${name_ver#v}.*" -type f 2>/dev/null | head -1)
if [ -z "$file" ]; then
matches=$(source_release_assets_json "$host" <<<"$release") || return 1
if [ "$(jq 'length' <<<"$matches")" -gt 1 ]; then
local matches_new
if echo "$cli_src" | grep -qiE "(npatch|lspatch)"; then
matches_new=$(jq -e -r 'map(select(.name | test("\\.apk$"; "i")))' <<<"$matches")
else
matches_new=$(jq -e -r 'map(select(.name | test("\\.(rvp|mpp|jar)$"; "i")))' <<<"$matches")
fi
if [ "$(jq 'length' <<<"$matches_new")" -ge 1 ]; then
matches=$matches_new
fi
fi
if [ "$(jq 'length' <<<"$matches")" -gt 1 ]; then
local matches_new
matches_new=$(jq -e -r 'map(select(.name | contains("-dev") | not))' <<<"$matches")
if [ "$(jq 'length' <<<"$matches_new")" -eq 1 ]; then
matches=$matches_new
fi
fi
if [ "$(jq 'length' <<<"$matches")" -gt 1 ]; then
local matches_new
matches_new=$(jq -e -r 'map(select(.name | contains("debug") | not))' <<<"$matches")
if [ "$(jq 'length' <<<"$matches_new")" -ge 1 ]; then
matches=$matches_new
fi
fi
if [ "$(jq 'length' <<<"$matches")" -gt 1 ]; then
local matches_new
matches_new=$(jq --arg ver "${name_ver#v}" -e -r 'map(select(.name | contains($ver)))' <<<"$matches")
if [ "$(jq 'length' <<<"$matches_new")" -ge 1 ]; then
matches=$matches_new
fi
fi
if [ "$(jq 'length' <<<"$matches")" -eq 0 ]; then
epr "No asset was found"
return 1
elif [ "$(jq 'length' <<<"$matches")" -ne 1 ]; then
wpr "More than 1 asset was found for this release. Falling back to the first one found..."
fi
asset=$(jq -r ".[0]" <<<"$matches")
url=$(source_release_asset_url "$host" <<<"$asset")
name=$(jq -r .name <<<"$asset")
file="${dir}/${name}"
if [ "$host" = github ]; then
gh_dl "$file" "$url" >&2 || return 1
else
pr "Getting '$file' from '$url'"
_req "$url" "$file" -H "Accept: application/octet-stream" >&2 || return 1
fi
echo "$tag: $(cut -d/ -f1 <<<"$src")/${name} " >>"${cl_dir}/changelog.md"
else
grab_cl=false
name=$(basename "$file")
fi
echo "$tag_name" > "${dir}/tag_name.txt"
if [ "$grab_cl" = true ]; then
if [ "$host" = github ]; then
echo -e "[Changelog](https://github.com/${src}/releases/tag/${tag_name})\n" >>"${cl_dir}/changelog.md"
else
echo -e "[Changelog](https://gitlab.com/${src}/-/releases/${tag_name})\n" >>"${cl_dir}/changelog.md"
fi
fi
if [ "$REMOVE_RV_INTEGRATIONS_CHECKS" = true ]; then
local extensions_ext
extensions_ext=$(unzip -l "${file}" "extensions/shared.*" | grep -o "shared\..*") extensions_ext="${extensions_ext#*.}"
if ! (
mkdir -p "${file}-zip" || return 1
unzip -qo "${file}" -d "${file}-zip" || return 1
java -cp "${BIN_DIR}/paccer.jar:${BIN_DIR}/dexlib2.jar" com.jhc.Main "${file}-zip/extensions/shared.${extensions_ext}" "${file}-zip/extensions/shared-patched.${extensions_ext}" || return 1
mv -f "${file}-zip/extensions/shared-patched.${extensions_ext}" "${file}-zip/extensions/shared.${extensions_ext}" || return 1
rm "${file}" || return 1
cd "${file}-zip" || abort
zip -0rq "${CWD}/${file}" . || return 1
) >&2; then
echo >&2 "Patching revanced-integrations failed"
fi
rm -r "${file}-zip" || :
fi
echo -n "$file "
done
echo
}
set_prebuilts() {
APKSIGNER="${BIN_DIR}/apksigner.jar"
local arch
arch=$(uname -m)
if [ "$arch" = aarch64 ]; then arch=arm64; elif [ "${arch:0:5}" = "armv7" ]; then arch=arm; fi
HTMLQ="${BIN_DIR}/htmlq/htmlq-${arch}"
AAPT2="${BIN_DIR}/aapt2/aapt2-${arch}"
TOML="${BIN_DIR}/toml/tq-${arch}"
}
config_update() {
if [ ! -f build.md ]; then abort "build.md not available"; fi
declare -A sources
: >"$TEMP_DIR"/skipped
local upped=()
local prcfg=false
for table_name in $(toml_get_table_names); do
if [ -z "$table_name" ]; then continue; fi
t=$(toml_get_table "$table_name")
enabled=$(toml_get "$t" enabled) || enabled=true
if [ "$enabled" = "false" ]; then continue; fi
local raw_patches_src raw_patches_host raw_patches_ver
raw_patches_src=$(toml_get "$t" patches-source) || raw_patches_src=$DEF_PATCHES_SRC
raw_patches_host=$(toml_get "$t" patches-source-host) || raw_patches_host=$DEF_PATCHES_SRC_HOST
raw_patches_ver=$(toml_get "$t" patches-version) || raw_patches_ver=$DEF_PATCHES_VER
local IFS=$'\n'
local p_srcs=($(list_args "$raw_patches_src" | tr -d \"\')); [ ${#p_srcs[@]} -eq 0 ] && p_srcs=("$raw_patches_src")
local p_hosts=($(list_args "$raw_patches_host" | tr -d \"\')); [ ${#p_hosts[@]} -eq 0 ] && p_hosts=("$raw_patches_host")
local p_vers=($(list_args "$raw_patches_ver" | tr -d \"\')); [ ${#p_vers[@]} -eq 0 ] && p_vers=("$raw_patches_ver")
unset IFS
local table_updated=false
for i in "${!p_srcs[@]}"; do
local PATCHES_SRC="${p_srcs[$i]}"
local PATCHES_HOST="${p_hosts[$i]:-${p_hosts[0]}}"
local PATCHES_VER="${p_vers[$i]:-${p_vers[0]}}"
if [[ -v sources["$PATCHES_HOST/$PATCHES_SRC/$PATCHES_VER"] ]]; then
if [ "${sources["$PATCHES_HOST/$PATCHES_SRC/$PATCHES_VER"]}" = 1 ]; then table_updated=true; fi
else
sources["$PATCHES_HOST/$PATCHES_SRC/$PATCHES_VER"]=0
local rv_rel resp last_patches
rv_rel=$(source_release_api_base "$PATCHES_HOST" "$PATCHES_SRC") || continue
if [ "$PATCHES_VER" = "dev" ]; then
resp=$({ if [ "$PATCHES_HOST" = github ]; then gh_req "$rv_rel?per_page=100" -; else req "$rv_rel?per_page=100" -; fi; }) || continue
last_patches=$(source_release_pick_from_list "$PATCHES_HOST" dev <<<"$resp") || continue
elif [ "$PATCHES_VER" = "latest" ]; then
resp=$({ if [ "$PATCHES_HOST" = github ]; then gh_req "$rv_rel?per_page=100" -; else req "$rv_rel?per_page=100" -; fi; }) || continue
last_patches=$(source_release_pick_from_list "$PATCHES_HOST" latest <<<"$resp") || continue
else
rv_rel=$(source_release_tag_api "$PATCHES_HOST" "$PATCHES_SRC" "$PATCHES_VER") || continue
last_patches=$({ if [ "$PATCHES_HOST" = github ]; then gh_req "$rv_rel" -; else req "$rv_rel" -; fi; }) || continue
fi
if ! last_patches=$(source_release_assets_json "$PATCHES_HOST" <<<"$last_patches" | jq -e -r '.[0].name'); then
abort "config_update error: '$last_patches'"
fi
if [ "$last_patches" ]; then
if ! OP=$(grep "^Patches: ${PATCHES_SRC%%/*}/" build.md | grep -m1 "$last_patches"); then
sources["$PATCHES_HOST/$PATCHES_SRC/$PATCHES_VER"]=1
prcfg=true
table_updated=true
else
echo "$OP" >>"$TEMP_DIR"/skipped
fi
fi
fi
done
[ "$table_updated" = true ] && upped+=("$table_name")
done
if [ "$prcfg" = true ]; then
local query=""
for table in "${upped[@]}"; do
if [ -n "$query" ]; then query+=" or "; fi
query+=".key == \"$table\""
done
jq "to_entries | map(select(${query} or (.value | type != \"object\"))) | from_entries" <<<"$__TOML__"
fi
}
_req() {
local ip="$1" op="$2"
shift 2
local dlp="$op"
if [ "$op" != - ]; then
if [ -f "$op" ]; then return; fi
dlp="$(dirname "$op")/tmp.$(basename "$op")"
if [ -f "$dlp" ]; then
local wait_c=0
while [ -f "$dlp" ] && [ $wait_c -lt 300 ]; do
sleep 1
wait_c=$((wait_c+1))
done
if [ -f "$op" ]; then return 0; fi
fi
fi
if ! curl -L -c "$TEMP_DIR/cookie.txt" -b "$TEMP_DIR/cookie.txt" --connect-timeout 10 --retry 1 --fail -s -S "$@" "$ip" -o "$dlp"; then
epr "Request failed: $ip"
if [ "$dlp" != - ]; then rm -f "$dlp"; fi
return 1
fi
if [ "$dlp" != - ]; then
mv -f "$dlp" "$op"
fi
}
req() { _req "$1" "$2" -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0"; }
gh_req() { _req "$1" "$2" -H "$GH_HEADER"; }
gh_dl() {
if [ ! -f "$1" ]; then
pr "Getting '$1' from '$2'"
_req "$2" "$1" -H "$GH_HEADER" -H "Accept: application/octet-stream"
fi
}
log() { echo -e "$1 " >>"build.md"; }
get_highest_ver() {
local vers m valid_vers=""
vers=$(tee)
# Try to find the highest valid semver first
while IFS= read -r v; do
if [ -n "$v" ] && semver_validate "$v"; then
valid_vers+="${v}"$'\n'
fi
done <<<"$vers"
if [ -n "$valid_vers" ]; then
sort -s -t- -k1,1Vr <<<"$valid_vers" | head -1
else
# Fallback to the original behavior if no valid semvers
m=$(head -1 <<<"$vers")
echo "$m"
fi
}
semver_validate() {
local a="${1%-*}"
local a="${a#v}"
local ac="${a//[.0-9]/}"
[ ${#ac} = 0 ]
}
get_patch_last_supported_ver() {
local cache_key="${1}_${2}_${3:-}_${4:-}_${5:-}_${6:-}"
if [ -n "${__PATCH_VER_CACHE__["$cache_key"]:-}" ]; then
echo "${__PATCH_VER_CACHE__["$cache_key"]}"
return 0
fi
local result
if ! result=$(_get_patch_last_supported_ver "$@"); then return 1; fi
__PATCH_VER_CACHE__["$cache_key"]="$result"
echo "$result"
}
_get_patch_last_supported_ver() {
local list_patches=$1 pkg_name=$2 inc_sel=${3:-} _exc_sel=${4:-} _exclusive=${5:-} cli_source=${6:-} # TODO: resolve using all of these
local op
if [ "$inc_sel" ]; then
if ! op=$(awk '{$1=$1}1' <<<"$list_patches"); then
epr "list-patches: '$op'"
return 1
fi
local ver vers="" NL=$'\n'
while IFS= read -r line; do
line="${line:1:${#line}-2}"
ver=$(sed -n "/^Name: $line\$/,/^\$/p" <<<"$op" | sed -n "/^Compatible versions:\$/,/^\$/p" | tail -n +2)
vers="${vers}${ver}${NL}"
done <<<"$(list_args "$inc_sel")"
vers=$(awk '{$1=$1}1' <<<"$vers")
if [ -n "$vers" ]; then
echo "$vers" | tr ' ' '\n' | sort | uniq -c | sort -k1,1nr | awk '
NR==1 { max=$1; print $2; next }
$1==max { print $2 }
' | get_highest_ver
return
fi
fi
op=$(patches_list_versions "$cli_jar" "$patches_jar" "$pkg_name" "$cli_source") || return 1
op=$(sed -n '/Most common compatible versions:/,$p' <<<"$op" | sed '1d' | awk '{$1=$1}1')
if [ "$op" = "Any" ]; then return; fi
pcount=$(head -1 <<<"$op") pcount=${pcount#*(} pcount=${pcount% *}
if [ -z "$pcount" ]; then
return
fi
grep -F "($pcount patch" <<<"$op" | sed 's/ (.* patch.*//' | get_highest_ver || return 1
}
get_patch_exp_ver() {
local cli_jar=$1 patches_jar=$2 pkg_name=$3 cli_source=$4
local list_stable list_all
list_stable=$(patches_list_versions "$cli_jar" "$patches_jar" "$pkg_name" "$cli_source" "") || return 1
list_all=$(patches_list_versions "$cli_jar" "$patches_jar" "$pkg_name" "$cli_source" "-x") || return 1
list_stable=$(sed -n '/Most common compatible versions:/,$p' <<<"$list_stable" | sed '1d' | awk '{print $1}')
list_all=$(sed -n '/Most common compatible versions:/,$p' <<<"$list_all" | sed '1d' | awk '{print $1}')
local exp_versions=""
for ver in $list_all; do
if [ -n "$ver" ] && ! echo "$list_stable" | grep -qFx "$ver"; then
exp_versions+="$ver"$'\n'
fi
done
if [ -n "$exp_versions" ]; then
get_highest_ver <<<"$exp_versions"
fi
}
patches_list_versions() {
local cache_key="${1}_${2}_${3}_${4}_${5:-}"
if [ -n "${__PATCH_VER_CACHE__["$cache_key"]:-}" ]; then
echo "${__PATCH_VER_CACHE__["$cache_key"]}"
return 0
fi
local result
if ! result=$(_patches_list_versions "$@"); then return 1; fi
__PATCH_VER_CACHE__["$cache_key"]="$result"
echo "$result"
}
_patches_list_versions() {
local cli_jar=$1 patches_jar=$2 pkg_name=$3 cli_source=$4 extra_args=${5:-} op
local cli_source_l="${cli_source,,}"
if [[ "$cli_source_l" == *"npatch"* ]] || [[ "$cli_source_l" == *"lspatch"* ]] || [[ "$cli_source_l" == *"instafel"* ]]; then
echo ""
return 0
fi
local p_jars=($(echo "$patches_jar" | tr ' ' '\n' | grep -v '^$'))
if [[ "$cli_source_l" == *"morphe-desktop"* ]]; then
local p_args_morphe=""
for j in "${p_jars[@]}"; do
p_args_morphe+="--patches '$j' "
done
if ! op=$(eval java -jar "'$cli_jar'" list-versions $p_args_morphe -f "'$pkg_name'" $extra_args 2>&1); then
epr "Could not list versions $cli_jar: '$op'"
return 1
fi
else
local p_args_revanced=""
for j in "${p_jars[@]}"; do
p_args_revanced+="-p '$j' "
done
if ! op=$(eval java -jar "'$cli_jar'" list-versions -b $p_args_revanced -f "'$pkg_name'" $extra_args 2>&1); then
epr "Could not list versions $cli_jar: '$op'"
return 1
fi
fi
echo "$op"
}
patches_list() {
local cache_key="${1}_${2}_${3}_${4}"
if [ -n "${__PATCHES_LIST_CACHE__["$cache_key"]:-}" ]; then
echo "${__PATCHES_LIST_CACHE__["$cache_key"]}"
return 0
fi
local result
if ! result=$(_patches_list "$@"); then return 1; fi
__PATCHES_LIST_CACHE__["$cache_key"]="$result"
echo "$result"
}
_patches_list() {
local cli_jar=$1 patches_jar=$2 pkg_name=$3 cli_source=$4 op
local cli_source_l="${cli_source,,}"
if [[ "$cli_source_l" == *"npatch"* ]] || [[ "$cli_source_l" == *"lspatch"* ]]; then
echo "Name: xposed-module-dummy"
return 0
fi
local p_jars=($(echo "$patches_jar" | tr ' ' '\n' | grep -v '^$'))
if [[ "$cli_source_l" == *"instafel"* ]]; then
local cli_dir
cli_dir=$(dirname "$cli_jar")
for j in "${p_jars[@]}"; do
cp "$j" "$cli_dir/ifl-patcher-core-8e4756f.jar" 2>/dev/null || :
cp "$j" "ifl-patcher-core-8e4756f.jar" 2>/dev/null || :
done
if ! op=$(eval java -jar "'$cli_jar'" list 2>&1); then
epr "Could not get patches list $cli_jar: '$op'"
return 1
fi
echo "$op"
return 0
fi
if [[ "$cli_source_l" == *"morphe-desktop"* ]]; then
local p_args_morphe=""
for j in "${p_jars[@]}"; do
p_args_morphe+="--patches '$j' "
done
if ! op=$(eval java -jar "'$cli_jar'" list-patches $p_args_morphe -f "'$pkg_name'" --with-versions --with-packages -x 2>&1); then
epr "Could not get patches list $cli_jar: '$op'"
return 1
fi
else
local p_args_revanced=""
for j in "${p_jars[@]}"; do
p_args_revanced+="-p '$j' "
done
if ! op=$(eval java -jar "'$cli_jar'" list-patches -b $p_args_revanced --packages --versions --options --filter-package-name="'$pkg_name'" 2>&1); then
epr "Could not get patches list $cli_jar: '$op'"
return 1
fi
fi
echo "$op"
}
isoneof() {
local i=$1 v
shift
for v; do [ "$v" = "$i" ] && return 0; done
return 1
}
merge_splits() {
local bundle=$1 output=$2
if unzip -l "$bundle" 2>/dev/null | grep -q '^[[:space:]]*[0-9].*AndroidManifest\.xml$'; then
pr "Downloaded bundle is actually a standard APK. Bypassing merge."
mv -f "$bundle" "$output"
return 0
fi
pr "Merging splits"
get_apkeditor || return 1
if ! OP=$(java -jar "$TEMP_DIR/apkeditor.jar" merge -i "$bundle" -o "${output}-unsigned" -clean-meta -f 2>&1); then
epr "APKEditor error: $OP"
return 1
fi
# sign the merged stock apk
if ! OP=$(java -jar "$APKSIGNER" sign --ks ks-p12.keystore --ks-pass pass:123456789 --key-pass pass:123456789 --ks-key-alias jhc \
--out "${output}" "${output}-unsigned"); then
epr "apksigner error: $OP"
return 1
fi
rm "${output}.idsig" "${output}-unsigned" 2>/dev/null || :
return 0
}
_trawl_8191_get() {
local url=$1 referer=${2:-}
local max_retries=1 attempt
local solver_url="${TRAWL_URL:-http://localhost:8191}/scrape"
local extra_headers=""
[ -n "$referer" ] && extra_headers=",\"headers\":{\"Referer\":\"$referer\"}"
for attempt in $(seq 1 $max_retries); do
local response status
response=$(curl -m 90 -s -X POST "$solver_url" \
-H 'Content-Type: application/json' \
-d "{\"url\":\"$url\",\"maxTimeout\":60000,\"skipHttp\":true${extra_headers}}") || true
status=$(echo "$response" | jq -r '.statusCode // empty')
if [[ "$status" == "200" ]]; then
html=$(echo "$response" | jq -r '.html // empty')
if [[ -n "$html" && "$html" != *"Attention Required!"* && "$html" != *"Just a moment..."* && "$html" != *"Please Wait... | Cloudflare"* && "$html" != *"Verify you are human"* ]]; then
export CF_COOKIES
CF_COOKIES=$(echo "$response" | jq -r '[.cookies[] | .name + "=" + .value] | join("; ")')
user_agent=$(echo "$response" | jq -r '.userAgent // empty')
return 0
fi
fi
if [[ "${__SILENT_CF_GET__:-false}" != true ]]; then
wpr "Trawl:8191 attempt $attempt/$max_retries failed for: $url"
fi
sleep 5
done
if [[ "${__SILENT_CF_GET__:-false}" != true ]]; then
wpr "[!] Trawl:8191 failed after $max_retries attempts: $url"
fi
return 1
}
_fallback_get(){
local url=$1
html=$(curl -L -c "$TEMP_DIR/cookie.txt" -b "$TEMP_DIR/cookie.txt" --connect-timeout 10 --retry 1 -s -f "$url" -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0") || return 1
if [[ "$html" == *"Attention Required!"* || "$html" == *"Just a moment..."* || "$html" == *"Please Wait... | Cloudflare"* || "$html" == *"Verify you are human"* ]]; then
return 1
fi
CF_COOKIES=""
user_agent="Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0"
}
_unqueued_cf_get() {
if [[ "${CF_BYPASS_SOLVER_TRAWL_8191_ENABLED:-false}" == true ]]; then
_trawl_8191_get "$@" && return 0
else
_fallback_get "$@" && return 0
fi
if [[ "${__SILENT_CF_GET__:-false}" != true ]]; then
epr "All methods failed for: $1"
fi
return 1
}
_cf_get() {
mkdir -p "$TEMP_DIR"
local lock=$TEMP_DIR/cf_get.lock
exec 200>"$lock"
flock -x 200
trap 'exec 200>&-' RETURN EXIT INT TERM
_unqueued_cf_get "$@"
}
# -------------------- apkmirror --------------------
get_apkmirror_resp() {
local url="${1}"
if [ -n "${__DL_RESP_CACHE__["apkmirror_resp_$url"]:-}" ]; then
__APKMIRROR_RESP__="${__DL_RESP_CACHE__["apkmirror_resp_$url"]}"
__APKMIRROR_CAT__="${__DL_RESP_CACHE__["apkmirror_cat_$url"]}"
return 0
fi
local html=""
_cf_get "${url}" || return 1
__APKMIRROR_RESP__="$html"
local clean_url="${url%/}"
__APKMIRROR_CAT__="${clean_url##*/}"
__DL_RESP_CACHE__["apkmirror_resp_$url"]="$__APKMIRROR_RESP__"
__DL_RESP_CACHE__["apkmirror_cat_$url"]="$__APKMIRROR_CAT__"
set +u
__APKMIRROR_EXAMPLE_URL__="${args[apkmirror_example_url]:-}"
set -u
}
get_apkmirror_vers() {
local vers apkm_resp html=""
_cf_get "https://www.apkmirror.com/uploads/?appcategory=${__APKMIRROR_CAT__}" || return 1
apkm_resp="$html"
if [ -n "${HTMLQ:-}" ] && [ -x "$HTMLQ" ]; then
local main_content
main_content=$($HTMLQ "#primary" <<<"$apkm_resp" 2>/dev/null || true)
[ -z "$main_content" ] && main_content=$($HTMLQ "#content" <<<"$apkm_resp" 2>/dev/null || true)
[ -n "$main_content" ] && apkm_resp="$main_content"
fi
vers=$(sed -n 's;.*Version:</span><span class="infoSlide-value">\(.*\) </span>.*;\1;p' <<<"$apkm_resp" | awk '{$1=$1}1')
if [ "${__AAV__:-false}" = false ]; then
local IFS=$'\n'
vers=$(grep -iv "\(beta\|alpha\)" <<<"$vers" || true)
local v 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() {
local resp="$__APKMIRROR_RESP__"
if [ -n "${HTMLQ:-}" ] && [ -x "$HTMLQ" ]; then
local main_content
main_content=$($HTMLQ "#primary" <<<"$resp" 2>/dev/null || true)
[ -z "$main_content" ] && main_content=$($HTMLQ "#content" <<<"$resp" 2>/dev/null || true)
[ -n "$main_content" ] && resp="$main_content"
fi
sed -n 's;.*id=\(.*\)" class="accent_color.*;\1;p' <<<"$resp"
}
apkmirror_search() {
local resp="$1" dpi="$2" arch="$3" apk_bundle="$4" clean_search_version="$5" search_version="$6"
local dlurl="" node app_table emptyCheck
local appdpi=("nodpi" "anydpi")
local match_any_dpi=false
if [ "$dpi" ]; then
appdpi+=($dpi)
if isoneof "auto" "${appdpi[@]}"; then
match_any_dpi=true
fi
fi
local best_fallback_url=""
local specific_arch_url=""
local specific_arch_fallback_url=""
for ((n = 1; n < 40; n++)); do
node=$($HTMLQ "div.table-row.headerFont:nth-last-child($n)" <<<"$resp")
if [ -z "$node" ]; then break; fi
dlurl=$($HTMLQ --base https://www.apkmirror.com --attribute href "div.table-cell:nth-child(1) > a:nth-child(1)" <<<"$node")
if [ -z "$dlurl" ]; then continue; fi
local node_apk_bundle node_arch node_dpi
node_apk_bundle=$($HTMLQ "div.table-cell:nth-child(1) span.apkm-badge:first-of-type" --text <<<"$node" | xargs)
[ -z "$node_apk_bundle" ] && node_apk_bundle="APK"
node_arch=$($HTMLQ "div.table-cell:nth-child(2)" --text <<<"$node" | xargs)
node_dpi=$($HTMLQ "div.table-cell:nth-child(4)" --text <<<"$node" | xargs)
if [ "$node_apk_bundle" != "$apk_bundle" ]; then continue; fi
if [ -n "$clean_search_version" ]; then
if [[ "$dlurl" != *"$clean_search_version"* ]] && [[ "$dlurl" != *"$search_version"* ]]; then
continue
fi
fi
# Pass 1 Logic: Return Universal/Fat Bundles immediately to optimize cache size
if isoneof "$node_arch" 'universal' 'noarch' 'arm64-v8a + x86_64' 'arm64-v8a + armeabi-v7a'; then
if isoneof "$node_dpi" "${appdpi[@]}"; then
echo "$dlurl"
return 0
elif [ "$match_any_dpi" = true ] && [ -z "$best_fallback_url" ]; then
best_fallback_url="$dlurl"
fi
# Pass 2 Logic: If it's strictly the requested arch, save it as a fallback in case no universal is found
elif [ "$node_arch" = "$arch" ]; then
if isoneof "$node_dpi" "${appdpi[@]}"; then
[ -z "$specific_arch_url" ] && specific_arch_url="$dlurl"
elif [ "$match_any_dpi" = true ] && [ -z "$specific_arch_fallback_url" ]; then
specific_arch_fallback_url="$dlurl"
fi
fi
done
if [ -n "$best_fallback_url" ]; then
echo "$best_fallback_url"
return 0
elif [ -n "$specific_arch_url" ]; then
echo "$specific_arch_url"
return 0
elif [ -n "$specific_arch_fallback_url" ]; then
echo "$specific_arch_fallback_url"
return 0
fi
return 1
}
dl_apkmirror() {
local url=$1 version=${2// /-} output=$3 arch=$4 dpi=$5 is_bundle=false
local base_url="https://www.apkmirror.com"
local html=""
if [ -f "${output%.apk}.apkm" ]; then
merge_splits "${output%.apk}.apkm" "${output}"
return 0
fi
if [ "$arch" = "arm-v7a" ]; then arch="armeabi-v7a"; fi
local clean_version="${version//[^0-9.]/}"
local clean_search_version="${clean_version//./-}"
local short_version="" short_search_version=""
if [[ "$clean_version" == *.*.*.* ]]; then
short_version=$(echo "$clean_version" | cut -d. -f1-3)
elif [[ "$clean_version" == *.*.* ]]; then
short_version=$(echo "$clean_version" | cut -d. -f1-2)
fi
if [ -n "$short_version" ]; then
short_search_version="${short_version//./-}"
fi
local resp release_url=""
if [ -n "${__APKMIRROR_EXAMPLE_URL__:-}" ]; then
local example_path="${__APKMIRROR_EXAMPLE_URL__#$base_url}"
local slug_ver target_ver
slug_ver=$(echo "$example_path" | grep -oP '\d+(-\d+)+' | tail -1)
target_ver=$(echo "$version" | tr '.' '-' | grep -oP '\d+(-\d+)+')
if [ -n "$slug_ver" ] && [ -n "$target_ver" ]; then
release_url="${base_url}${example_path/$slug_ver/$target_ver}"
__SILENT_CF_GET__=true _cf_get "$release_url" || true
resp="$html"
if [[ "$resp" == *"Page Not Found"* ]] || [[ "$resp" == *"404 Whoops"* ]] || [ -z "$resp" ]; then
release_url=""
fi
fi
fi
local search_version="${version//./-}"
search_version="${search_version//_/-}"
search_version="${search_version,,}"
search_version="${search_version//[^a-z0-9-]/}"
search_version="${search_version//---/-}"
if [ -z "$release_url" ]; then
local apkmname
apkmname=$($HTMLQ "h1.marginZero" --text <<<"$__APKMIRROR_RESP__")
apkmname="${apkmname,,}" apkmname="${apkmname// /-}" apkmname="${apkmname//[^a-z0-9-]/}"
release_url="${url%/}/${apkmname}-${search_version}-release/"
__SILENT_CF_GET__=true _cf_get "$release_url" || true
resp="$html"
if [[ "$resp" == *"Page Not Found"* ]] || [[ "$resp" == *"404 Whoops"* ]] || [ -z "$resp" ]; then
release_url=""
fi
fi
if [ -z "$release_url" ]; then
local list_url="${url%/}"
local version_href=""
for page_num in $(seq 1 10); do
local page_url="$list_url/"
[[ $page_num -gt 1 ]] && page_url="$list_url/page/$page_num/"
_cf_get "$page_url" || return 1
local html_flat=$(echo "$html" | tr -d '\n\r')
local html_split="${html_flat//<\/a>/<\/a>
}"
local all_links=$(echo "$html_split" | grep -oP 'href="\K/apk/[^"]+')
# 1. Exact URL match (strict)
version_href=$(echo "$all_links" | grep -F "$search_version-release" | head -1) || true
# 2. Exact text match
if [ -z "$version_href" ]; then
version_href=$(echo "$html_split" | grep -F "$version" | grep -oP 'href="\K[^"]+' | head -1) || true
fi
# 3. Clean text match
if [ -z "$version_href" ] && [ -n "$clean_version" ] && [ "$clean_version" != "$version" ]; then
version_href=$(echo "$html_split" | grep -F "$clean_version" | grep -oP 'href="\K[^"]+' | head -1) || true
fi
# 4. Clean URL match
if [ -z "$version_href" ] && [ -n "$clean_search_version" ]; then
version_href=$(echo "$all_links" | grep -E "${clean_search_version}(-[a-z0-9]+)*-release" | head -1) || true
fi
# 5. Safe Short URL match (for grouped versions)
if [ -z "$version_href" ] && [ -n "$short_search_version" ] && [ "$short_search_version" != "$clean_search_version" ]; then
version_href=$(echo "$all_links" | grep -E "${short_search_version}(-[0-9])?-release/?$" | head -1) || true
fi
if [ -n "$version_href" ]; then
release_url="$base_url$version_href"
_cf_get "$release_url" || return 1
resp="$html"