diff --git a/utils.sh b/utils.sh index 55dc42c..2b4ac82 100755 --- a/utils.sh +++ b/utils.sh @@ -180,22 +180,16 @@ dl_apkmirror() { node=$($HTMLQ "div.table-row:nth-child($n)" -r "span:nth-child(n+3)" <<<"$resp") if [ -z "$node" ]; then break; fi app_table=$($HTMLQ --text --ignore-whitespace <<<"$node") - if [ "$(sed -n 3p <<<"$app_table")" = "$apkorbundle" ]; then - if [ "$apkorbundle" = APK ]; then - if [ "$(sed -n 6p <<<"$app_table")" = "$dpi" ] && isoneof "$(sed -n 4p <<<"$app_table")" "${apparch[@]}"; then - dlurl=https://www.apkmirror.com$($HTMLQ --attribute href "div:nth-child(1) > a:nth-child(1)" <<<"$node") - break - fi - elif [ "$apkorbundle" = BUNDLE ]; then - dlurl=https://www.apkmirror.com$($HTMLQ --attribute href "div:nth-child(1) > a:nth-child(1)" <<<"$node") - break - else - abort "unreachable" - fi + if [ "$(sed -n 3p <<<"$app_table")" = "$apkorbundle" ] && { [ "$apkorbundle" = BUNDLE ] || + { [ "$apkorbundle" = APK ] && [ "$(sed -n 6p <<<"$app_table")" = "$dpi" ] && + isoneof "$(sed -n 4p <<<"$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" - | sed -n 's;.*href="\(.*key=[^"]*\)">.*;\1;p')" + url="https://www.apkmirror.com$(req "$dlurl" - | sed -n 's;.*href="\(.*key=[^"]*\)">.*;\1;p' | tail -1)" + if [ "$apkorbundle" = BUNDLE ] && [[ "$url" != *"&forcebaseapk=true" ]]; then url="${url}&forcebaseapk=true"; fi url="https://www.apkmirror.com$(req "$url" - | sed -n 's;.*href="\(.*key=[^"]*\)">.*;\1;p')" req "$url" "$output" } @@ -364,7 +358,6 @@ build_rv() { 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 @@ -372,12 +365,13 @@ build_rv() { is_bundle=true elif [ "$dl_from" = apkmirror ]; then pr "Downloading '${app_name}' bundle from APKMirror" - if dl_apkmirror "${args[apkmirror_dlurl]}" "$version" "$stock_bundle" 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" + if dl_apkmirror "${args[apkmirror_dlurl]}" "$version" "$stock_bundle_apk" BUNDLE "" ""; then + if (($(stat -c%s "$stock_apk") - $(stat -c%s "$stock_bundle_apk") > 10000000)); then + pr "'${app_name}' bundle was downloaded successfully and will be used for the module" + is_bundle=true + else + pr "'${app_name}' bundle was downloaded but will not be used" + fi else pr "'${app_name}' bundle was not found" fi