sync the author code

This commit is contained in:
2026-07-21 11:01:29 +07:00
parent a14e4f9c7d
commit 7d5e85fc3e
18 changed files with 186 additions and 521 deletions
+42 -24
View File
@@ -45,11 +45,16 @@ wpr() {
echo >&2 -e "\033[0;33m[!] ${1}\033[0m"
if [ "${GITHUB_REPOSITORY-}" ]; then echo >&2 -e "::warning::utils.sh [!] ${1}\n"; fi
}
_clean_tmp() {
rm -rf ./${TEMP_DIR}/*tmp.* ./${TEMP_DIR}/*tmp_* ./${TEMP_DIR}/*/*tmp.* ./${TEMP_DIR}/*-temporary-files ./*-temporary-files
}
abort() {
epr "ABORT: ${1-}"
rm -rf ./${TEMP_DIR}/*tmp.* ./${TEMP_DIR}/*/*tmp.* ./${TEMP_DIR}/*-temporary-files ./*-temporary-files
_clean_tmp
trap - SIGTERM SIGINT EXIT
kill -- -$$ 2>/dev/null
kill -9 -- -$$ 2>/dev/null
exit 1
}
java() { env -i java --enable-native-access=ALL-UNNAMED "$@"; }
@@ -61,15 +66,9 @@ get_prebuilts() {
cl_dir=${TEMP_DIR}/${cl_dir,,}-rv
[ -d "$cl_dir" ] || mkdir "$cl_dir"
for src_ver in "$cli_src CLI $cli_ver cli" "$patches_src Patches $patches_ver patches"; do
for src_ver in "Patches $patches_src $patches_ver" "CLI $cli_src $cli_ver"; do
set -- $src_ver
local src=$1 tag=$2 ver=${3-} fprefix=$4
if [ "$tag" = "CLI" ]; then
local grab_cl=false
elif [ "$tag" = "Patches" ]; then
local grab_cl=true
else abort unreachable; fi
local tag=$1 src=$2 ver=${3-}
local dir=${src%/*}
dir=${TEMP_DIR}/${dir,,}-rv
@@ -89,8 +88,16 @@ get_prebuilts() {
name_ver="$ver"
fi
local url file tag_name matches
file=$(find "$dir" -name "*${fprefix}-${name_ver#v}.*" -type f 2>/dev/null)
local file
if [ "$tag" = "CLI" ]; then
file=$(find "$dir" -maxdepth 1 -name "*cli-${name_ver#v}*.jar" -o -name "*desktop-${name_ver#v}*.jar" -type f 2>/dev/null)
local grab_cl=false
elif [ "$tag" = "Patches" ]; then
file=$(find "$dir" -maxdepth 1 -name "*patches-${name_ver#v}.*" -type f 2>/dev/null)
local grab_cl=true
else abort unreachable; fi
local url tag_name matches
if [ "$ver" = "latest" ]; then
file=$(grep -v '/[^/]*dev[^/]*$' <<<"$file" | head -1)
else
@@ -244,7 +251,7 @@ get_highest_ver() {
local vers m
vers=$(tee)
m=$(head -1 <<<"$vers")
if ! semver_validate "$m"; then echo "$m"; else sort -rV <<<"$vers" | head -1; fi
if ! semver_validate "$m"; then echo "$m"; else sort -s -t- -k1,1Vr <<<"$vers" | head -1; fi
}
semver_validate() {
local a="${1%-*}"
@@ -349,7 +356,7 @@ apkmirror_search() {
local dlurl="" node app_table emptyCheck
local apparch=('universal' 'noarch' 'arm64-v8a + armeabi-v7a')
if [ "$arch" != all ]; then
if [ "$arch" != "all" ]; then
apparch+=("$arch")
fi
@@ -504,7 +511,7 @@ 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 output_m version=${version// /}
local path version=${version// /}
if [ -f "${output}.apkm" ]; then
merge_splits "${output}.apkm" "$output"
@@ -513,13 +520,10 @@ dl_archive() {
path=$(grep -m1 "${version_f#v}-${arch// /}" <<<"$__ARCHIVE_RESP__") || return 1
if [ "${path##*.}" = "apkm" ]; then
output_m="${output}.apkm"
req "${url}/${path}" "${output}.apkm" || return 1
merge_splits "${output}.apkm" "$output"
else
output_m=$output
fi
req "${url}/${path}" "$output_m" || return 1
if [ "${path##*.}" = "apkm" ]; then
merge_splits "$output_m" "$output"
req "${url}/${path}" "${output}" || return 1
fi
}
get_archive_resp() {
@@ -534,7 +538,16 @@ get_archive_pkg_name() { echo "$__ARCHIVE_PKG_NAME__"; }
# -------------------- direct --------------------
dl_direct() {
local url=$1 version=${2// /-} output=$3 arch=$4 _dpi=$5
req "$url" "${output}" || return 1
if ! grep -q "${version_f#v}-${arch// /}" <<<"$url"; then
epr "Given direct-dlurl for $output is not compatible. Set proper 'arch' and 'version' options."
return 1
fi
if [ "${url##*.}" = "apkm" ]; then
req "$url" "${output}.apkm" || return 1
merge_splits "${output}.apkm" "$output"
else
req "$url" "${output}" || return 1
fi
}
get_direct_vers() { cut -d- -f2 <<<"$__DIRECT_APKNAME__"; }
get_direct_pkg_name() { cut -d- -f1 <<<"$__DIRECT_APKNAME__"; }
@@ -543,8 +556,11 @@ get_direct_resp() { __DIRECT_APKNAME__=$(awk -F/ '{print $NF}' <<<"$1"); }
patch_apk() {
local stock_input=$1 patched_apk=$2 patcher_args=$3 cli_jar=$4 patches_jar=$5
local cmd="java -jar '$cli_jar' patch '$stock_input' --purge -o '$patched_apk' -p '$patches_jar' --keystore=ks.keystore \
--keystore-entry-password=123456789 --keystore-password=123456789 --signer=jhc --keystore-entry-alias=jhc $patcher_args"
local tmp_files
tmp_files="$(pwd)/$(mktemp -d -p "$TEMP_DIR")"
local cmd="java -jar '$cli_jar' patch '$stock_input' -o '$patched_apk' -p '$patches_jar' --keystore=ks.keystore \
--keystore-entry-password=123456789 --keystore-password=123456789 --signer=jhc --keystore-entry-alias=jhc -t '$tmp_files' $patcher_args"
# TODO: remove this later
local cli_name
@@ -743,6 +759,8 @@ build_rv() {
if [ "$build_mode" = apk ]; then
if [ "${NORB:-}" != true ] || { [ ! -f "$patched_apk" ] && [ ! -f "$apk_output" ]; }; then
mv -f "$patched_apk" "$apk_output"
else
cp -f "$patched_apk" "$apk_output"
fi
pr "Built ${table} (non-root): '${apk_output}'"
continue