fix: resolve the issues

This commit is contained in:
2026-05-15 11:08:20 +07:00
parent c48c4abc17
commit d7a7688aa8
17 changed files with 298 additions and 189 deletions
+158 -73
View File
@@ -47,8 +47,10 @@ wpr() {
}
abort() {
epr "ABORT: ${1-}"
rm -rf ./${TEMP_DIR}/*tmp.* ./${TEMP_DIR}/*/*tmp.* ./${TEMP_DIR}/*-temporary-files
kill -n 9 0
rm -rf ./${TEMP_DIR}/*tmp.* ./${TEMP_DIR}/*/*tmp.* ./${TEMP_DIR}/*-temporary-files ./*-temporary-files
trap - SIGTERM SIGINT EXIT
kill -- -$$ 2>/dev/null
exit 1
}
java() { env -i java --enable-native-access=ALL-UNNAMED "$@"; }
@@ -89,6 +91,11 @@ get_prebuilts() {
local url file tag_name matches
file=$(find "$dir" -name "*${fprefix}-${name_ver#v}.*" -type f 2>/dev/null)
if [ "$ver" = "latest" ]; then
file=$(grep -v '/[^/]*dev[^/]*$' <<<"$file" | head -1)
else
file=$(grep "/[^/]*${ver#v}[^/]*\$" <<<"$file" | head -1)
fi
if [ -z "$file" ]; then
local resp asset name
resp=$(gh_req "$rv_rel" -) || return 1
@@ -115,11 +122,6 @@ get_prebuilts() {
echo "$tag: $(cut -d/ -f1 <<<"$src")/${name} " >>"${cl_dir}/changelog.md"
else
grab_cl=false
local for_err=$file
if [ "$ver" = "latest" ]; then
file=$(grep -v '/[^/]*dev[^/]*$' <<<"$file" | head -1)
else file=$(grep "/[^/]*${ver#v}[^/]*\$" <<<"$file" | head -1); fi
if [ -z "$file" ]; then abort "filter fail: '$for_err' with '$ver'"; fi
name=$(basename "$file")
tag_name=$(cut -d'-' -f3- <<<"$name")
tag_name=v${tag_name%.*}
@@ -271,7 +273,7 @@ get_patch_last_supported_ver() {
fi
fi
op=$(patches_list_versions "$cli_jar" "$patches_jar" "$pkg_name") || return 1
op=$(sed -n '/(.* patch.*/,$p' <<<"$op" | awk '{$1=$1}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
@@ -281,14 +283,28 @@ get_patch_last_supported_ver() {
}
patches_list_versions() {
local cli_jar=$1 patches_jar=$2 pkg_name=$3 op
if ! op=$(java -jar "$cli_jar" list-versions -p "$patches_jar" -f "$pkg_name" -b 2>&1); then
if ! op=$(java -jar "$cli_jar" list-versions "$patches_jar" -f "$pkg_name" 2>&1); then
epr "Could not list versions $cli_jar: '$op'"
return 1
fi
local cli_jar=$1 patches_jar=$2 pkg_name=$3 op cmd
local cmd_base="java -jar '$cli_jar' list-versions"
# TODO: remove this later
local cli_name
cli_name=$(basename "$cli_jar")
if [ "${cli_name::8}" = revanced ]; then cmd_base+=" -b"; fi
cmd="${cmd_base} --patches='$patches_jar' -f '$pkg_name'"
if op=$(eval "$cmd" 2>&1); then
echo "$op"
return
fi
echo "$op"
cmd="${cmd_base} '$patches_jar' -f '$pkg_name'"
if op=$(eval "$cmd" 2>&1); then
echo "$op"
return
fi
epr "Could not list versions $cli_jar: '$op'"
return 1
}
patches_list() {
local cli_jar=$1 patches_jar=$2 pkg_name=$3 op
@@ -330,20 +346,27 @@ merge_splits() {
# -------------------- apkmirror --------------------
apkmirror_search() {
local resp="$1" dpi="$2" arch="$3" apk_bundle="$4"
local apparch dlurl="" node app_table emptyCheck
if [ "$arch" = all ]; then
apparch=(universal noarch 'arm64-v8a + armeabi-v7a')
else apparch=("$arch" universal noarch 'arm64-v8a + armeabi-v7a'); fi
local dlurl="" node app_table emptyCheck
local apparch=('universal' 'noarch' 'arm64-v8a + armeabi-v7a')
if [ "$arch" != all ]; then
apparch+=("$arch")
fi
local appdpi=("nodpi" "anydpi")
if [ "$dpi" ]; then
appdpi+=($dpi)
fi
for ((n = 1; n < 40; n++)); do
node=$($HTMLQ "div.table-row.headerFont:nth-last-child($n)" -r "span:nth-child(n+3)" <<<"$resp")
if [ -z "$node" ]; then break; fi
emptyCheck=$($HTMLQ -t -w "div.table-cell:nth-child(1) > a:nth-child(1)" <<<"$node" | xargs)
if [ "$emptyCheck" ]; then
dlurl=$($HTMLQ --base https://www.apkmirror.com --attribute href "div:nth-child(1) > a:nth-child(1)" <<<"$node")
else break; fi
if [ -z "$emptyCheck" ]; then break; fi
app_table=$($HTMLQ --text --ignore-whitespace <<<"$node")
if [ "$(sed -n 3p <<<"$app_table")" = "$apk_bundle" ] &&
[ "$(sed -n 6p <<<"$app_table")" = "$dpi" ] &&
if [ "$(sed -n 3p <<<"$app_table")" != "$apk_bundle" ]; then continue; fi
dlurl=$($HTMLQ --base https://www.apkmirror.com --attribute href "div:nth-child(1) > a:nth-child(1)" <<<"$node")
if isoneof "$(sed -n 6p <<<"$app_table")" "${appdpi[@]}" &&
isoneof "$(sed -n 4p <<<"$app_table")" "${apparch[@]}"; then
echo "$dlurl"
return 0
@@ -358,32 +381,34 @@ apkmirror_search() {
}
dl_apkmirror() {
local url=$1 version=${2// /-} output=$3 arch=$4 dpi=$5 is_bundle=false
if [ -f "${output}.apkm" ]; then
is_bundle=true
else
if [ "$arch" = "arm-v7a" ]; then arch="armeabi-v7a"; fi
local resp node app_table apkmname dlurl=""
apkmname=$($HTMLQ "h1.marginZero" --text <<<"$__APKMIRROR_RESP__")
apkmname="${apkmname,,}" apkmname="${apkmname// /-}" apkmname="${apkmname//[^a-z0-9-]/}"
url="${url}/${apkmname}-${version//./-}-release/"
resp=$(req "$url" -) || return 1
node=$($HTMLQ "div.table-row.headerFont:nth-last-child(1)" -r "span:nth-child(n+3)" <<<"$resp")
if [ "$node" ]; then
for current_dpi in $dpi; do
for type in APK BUNDLE; do
if dlurl=$(apkmirror_search "$resp" "$current_dpi" "${arch}" "$type"); then
[[ "$type" == "BUNDLE" ]] && is_bundle=true || is_bundle=false
break 2
fi
done
done
[ -z "$dlurl" ] && return 1
resp=$(req "$dlurl" -)
fi
url=$(echo "$resp" | $HTMLQ --base https://www.apkmirror.com --attribute href "a.btn") || return 1
url=$(req "$url" - | $HTMLQ --base https://www.apkmirror.com --attribute href "span > a[rel = nofollow]") || return 1
merge_splits "${output}.apkm" "${output}"
return 0
fi
if [ "$arch" = "arm-v7a" ]; then arch="armeabi-v7a"; fi
local resp node app_table apkmname dlurl=""
apkmname=$($HTMLQ "h1.marginZero" --text <<<"$__APKMIRROR_RESP__")
apkmname="${apkmname,,}" apkmname="${apkmname// /-}" apkmname="${apkmname//[^a-z0-9-]/}"
url="${url}/${apkmname}-${version//./-}-release/"
resp=$(req "$url" -) || return 1
node=$($HTMLQ "div.table-row.headerFont:nth-last-child(1)" -r "span:nth-child(n+3)" <<<"$resp")
if [ "$node" ]; then
for type in APK BUNDLE; do
if dlurl=$(apkmirror_search "$resp" "$dpi" "$arch" "$type"); then
if [ "$type" = "BUNDLE" ]; then
is_bundle=true
else is_bundle=false; fi
break 2
fi
done
if [ -z "$dlurl" ]; then return 1; fi
resp=$(req "$dlurl" -)
fi
url=$(echo "$resp" | $HTMLQ --base https://www.apkmirror.com --attribute href "a.btn") || return 1
url=$(req "$url" - | $HTMLQ --base https://www.apkmirror.com --attribute href "span > a[rel = nofollow]") || return 1
if [ "$is_bundle" = true ]; then
req "$url" "${output}.apkm" || return 1
merge_splits "${output}.apkm" "${output}"
@@ -421,11 +446,12 @@ get_uptodown_resp() {
get_uptodown_vers() { $HTMLQ --text ".version" <<<"$__UPTODOWN_RESP__"; }
dl_uptodown() {
local uptodown_dlurl=$1 version=$2 output=$3 arch=$4 _dpi=$5
local apparch
if [ "$arch" = "arm-v7a" ]; then arch="armeabi-v7a"; fi
if [ "$arch" = all ]; then
apparch=('arm64-v8a, armeabi-v7a, x86_64' 'arm64-v8a, armeabi-v7a, x86, x86_64' 'arm64-v8a, armeabi-v7a')
else apparch=("$arch" 'arm64-v8a, armeabi-v7a, x86_64' 'arm64-v8a, armeabi-v7a, x86, x86_64' 'arm64-v8a, armeabi-v7a'); fi
local apparch=('arm64-v8a, armeabi-v7a, x86_64' 'arm64-v8a, armeabi-v7a, x86, x86_64' 'arm64-v8a, armeabi-v7a')
if [ "$arch" != all ]; then
apparch+=("$arch")
fi
local op resp data_code
data_code=$($HTMLQ "#detail-app-name" --attribute data-code <<<"$__UPTODOWN_RESP__")
@@ -478,9 +504,23 @@ get_uptodown_pkg_name() { $HTMLQ --text "tr.full:nth-child(1) > td:nth-child(3)"
# -------------------- archive --------------------
dl_archive() {
local url=$1 version=$2 output=$3 arch=$4
local path version=${version// /}
path=$(grep "${version_f#v}-${arch// /}" <<<"$__ARCHIVE_RESP__") || return 1
req "${url}/${path}" "$output"
local path output_m version=${version// /}
if [ -f "${output}.apkm" ]; then
merge_splits "${output}.apkm" "$output"
return 0
fi
path=$(grep -m1 "${version_f#v}-${arch// /}" <<<"$__ARCHIVE_RESP__") || return 1
if [ "${path##*.}" = "apkm" ]; then
output_m="${output}.apkm"
else
output_m=$output
fi
req "${url}/${path}" "$output_m" || return 1
if [ "${path##*.}" = "apkm" ]; then
merge_splits "$output_m" "$output"
fi
}
get_archive_resp() {
local r
@@ -493,7 +533,7 @@ get_archive_pkg_name() { echo "$__ARCHIVE_PKG_NAME__"; }
# -------------------- direct --------------------
dl_direct() {
local url=$1 version=${2// /-} output=$3 arch=$4 dpi=$5
local url=$1 version=${2// /-} output=$3 arch=$4 _dpi=$5
req "$url" "${output}" || return 1
}
get_direct_vers() { cut -d- -f2 <<<"$__DIRECT_APKNAME__"; }
@@ -547,17 +587,22 @@ build_rv() {
[ "${args[exclusive_patches]}" = true ] && p_patcher_args+=("--exclusive")
local tried_dl=()
for dl_p in "${DL_SRCS[@]}"; do
if [ -z "${args[${dl_p}_dlurl]}" ]; then continue; fi
if ! get_${dl_p}_resp "${args[${dl_p}_dlurl]}" || ! pkg_name=$(get_"${dl_p}"_pkg_name); then
args[${dl_p}_dlurl]=""
epr "ERROR: Could not find ${table} in ${dl_p}"
continue
fi
tried_dl+=("$dl_p")
dl_from=$dl_p
break
done
if [ "${args[pkg_name]}" ]; then
pkg_name="${args[pkg_name]}"
else
for dl_p in "${DL_SRCS[@]}"; do
if [ -z "${args[${dl_p}_dlurl]}" ]; then continue; fi
if ! get_${dl_p}_resp "${args[${dl_p}_dlurl]}" || ! pkg_name=$(get_"${dl_p}"_pkg_name); then
args[${dl_p}_dlurl]=""
epr "ERROR: Could not find ${table} in ${dl_p}"
continue
fi
tried_dl+=("$dl_p")
dl_from=$dl_p
break
done
fi
if [ -z "$pkg_name" ]; then
epr "empty pkg name, not building ${table}."
return 0
@@ -622,9 +667,23 @@ build_rv() {
return 0
fi
fi
if [ ! -f "${stock_apk}.apkm" ] && ! OP=$(check_sig "$stock_apk" "$pkg_name" 2>&1) && ! grep -qFx "ERROR: Missing META-INF/MANIFEST.MF" <<<"$OP"; then
epr "Not building $table, apk signature mismatch '$stock_apk': $OP"
return 0
local sig_op
if [ -f "${stock_apk}.apkm" ]; then
rm -rf "${stock_apk}-zip" || :
unzip -j "${stock_apk}.apkm" -d "${stock_apk}-zip" >/dev/null
for a in "${stock_apk}"-zip/*.apk; do
if ! sig_op=$(check_sig "$a" "$pkg_name" 2>&1); then
epr "Not building $table, apk signature mismatch '$a': $sig_op"
return 0
fi
done
rm -rf "${stock_apk}-zip" || :
else
if ! sig_op=$(check_sig "$stock_apk" "$pkg_name" 2>&1); then
epr "Not building $table, apk signature mismatch '$stock_apk': $sig_op"
return 0
fi
fi
log "${table}: ${version}"
@@ -672,7 +731,9 @@ build_rv() {
zip -d "$stock_apk_to_patch" "lib/x86_64/*" "lib/x86/*" >/dev/null 2>&1 || :
fi
fi
if [ "${NORB:-}" != true ] || [ ! -f "$patched_apk" ]; then
local apk_output="${BUILD_DIR}/${app_name_l}-${rv_brand_f}-v${version_f}-${arch_f}.apk"
if [ "${NORB:-}" != true ] || { [ ! -f "$patched_apk" ] && [ ! -f "$apk_output" ]; }; then
if ! patch_apk "$stock_apk_to_patch" "$patched_apk" "${patcher_args[*]}" "${args[cli]}" "${args[ptjar]}"; then
epr "Building '${table}' failed!"
return 0
@@ -680,8 +741,9 @@ build_rv() {
fi
rm "$stock_apk_to_patch"
if [ "$build_mode" = apk ]; then
local apk_output="${BUILD_DIR}/${app_name_l}-${rv_brand_f}-v${version_f}-${arch_f}.apk"
mv -f "$patched_apk" "$apk_output"
if [ "${NORB:-}" != true ] || { [ ! -f "$patched_apk" ] && [ ! -f "$apk_output" ]; }; then
mv -f "$patched_apk" "$apk_output"
fi
pr "Built ${table} (non-root): '${apk_output}'"
continue
fi
@@ -704,7 +766,30 @@ build_rv() {
local module_output="${app_name_l}-${rv_brand_f}-module-v${version_f}-${arch_f}.zip"
pr "Packing module ${table}"
cp -f "$patched_apk" "${base_template}/base.apk"
if [ "${args[include_stock]}" = true ]; then cp -f "$stock_apk" "${base_template}/${pkg_name}.apk"; fi
if [ "${args[include_stock]}" != "disable" ]; then
mkdir -p "${base_template}/stock/"
if [ "${args[include_stock]}" = "merged" ]; then
cp -f "$stock_apk" "${base_template}/stock/base.apk"
elif [ "${args[include_stock]}" = "split" ]; then
if [ ! -f "${stock_apk}.apkm" ]; then
epr "Cannot include as 'split' because stock apk of $table_name is not a bundle"
return 0
fi
if [ "$arch" = "arm64-v8a" ]; then
unzip -j "${stock_apk}.apkm" '*.apk' -x '*x86_64.apk' -x '*x86.apk' -x '*armeabi_v7a.apk' -d "${base_template}/stock/" >/dev/null 2>&1
elif [ "$arch" = "arm-v7a" ]; then
unzip -j "${stock_apk}.apkm" '*.apk' -x '*x86_64.apk' -x '*x86.apk' -x '*arm64_v8a.apk' -d "${base_template}/stock/" >/dev/null 2>&1
elif [ "$arch" = "x86" ]; then
unzip -j "${stock_apk}.apkm" '*.apk' -x '*x86_64.apk' -x '*arm64_v8a.apk' -x '*armeabi_v7a.apk' -d "${base_template}/stock/" >/dev/null 2>&1
elif [ "$arch" = "x86_64" ]; then
unzip -j "${stock_apk}.apkm" '*.apk' -x '*x86.apk' -x '*arm64_v8a.apk' -x '*armeabi_v7a.apk' -d "${base_template}/stock/" >/dev/null 2>&1
else
unzip -j "${stock_apk}.apkm" '*.apk' -x '*x86_64.apk' -x '*x86.apk' -d "${base_template}/stock/" >/dev/null 2>&1
fi
fi
fi
pushd >/dev/null "$base_template" || abort "Module template dir not found"
zip -"$COMPRESSION_LEVEL" -FSqr "${CWD}/${BUILD_DIR}/${module_output}" .
popd >/dev/null || :