From 42039f26ab370bd0b21d42e9c5a6d56bf5040717 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Thu, 13 Oct 2022 01:27:01 -0500 Subject: [PATCH] Fixed version comparison logic --- build_revanced.sh | 17 ++++++++++++----- download_apkmirror.sh | 11 +++++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/build_revanced.sh b/build_revanced.sh index 5752033..e2d154c 100755 --- a/build_revanced.sh +++ b/build_revanced.sh @@ -17,6 +17,13 @@ else exit -1 fi +# Returns if $1 is less than $2 +ver_less_than() { + [ ${1:0:1} == "v" ] && var1=${1:1} || var1=$1 + [ ${2:0:1} == "v" ] && var2=${2:1} || var2=$2 + [ $(echo $var1$'\n'$var2 | sort -V | tail -n1) != $var1 ] && echo true || echo false +} + # Make sure to work in the script directory SDIR="$(dirname -- "$( readlink -f -- "$0"; )";)" cd "$SDIR" @@ -95,9 +102,9 @@ for artifact in $artifacts; do version_present=$(jq -r ".\"$basename\"" versions.json) data=$(jq -r ".tools[] | select((.repository == \"$repo\") and (.content_type | contains(\"archive\")))" latest_versions.json) version=$(echo "$data" | jq -r '.version') - if [[ ${version_present//[!0-9]/} -lt ${version//[!0-9]/} || ! -f $name ]]; then + if [[ $(ver_less_than $version_present $version) == true || ! -f $name || $2 == force ]]; then echo "Downloading $name" | tee -a build.log - [[ $name == microg.apk && -f $name ]] && microg_updated=true + [[ $name == microg.apk && -f $name && $2 != force ]] && microg_updated=true # shellcheck disable=SC2086,SC2046 curl -sLo "$name" "$(echo "$data" | jq -r '.browser_download_url')" jq ".\"$basename\" = \"$version\"" versions.json > versions.json.tmp && mv versions.json.tmp versions.json @@ -112,7 +119,7 @@ if [[ $flag == false && "$2" != "force" ]]; then fi # Download required apk files -"$SDIR/download_apkmirror.sh" "$WDIR" +"$SDIR/download_apkmirror.sh" "$WDIR" $2 # # Fetch microG # chmod +x apkeep @@ -155,12 +162,12 @@ echo "Building YouTube Music APK" echo "************************************" if [ -f "com.google.android.apps.youtube.music.apk" ]; then # echo "Building Root APK" -# java -jar revanced-cli.jar -b revanced-patches.jar --mount \ +# java -jar revanced-cli.jar -m revanced-integrations.apk -b revanced-patches.jar --mount \ # -e microg-support ${patches[@]} \ # $EXPERIMENTAL \ # -a com.google.android.apps.youtube.music.apk -o build/revanced-ytm-root.apk echo "Building Non-root APK" | tee -a build.log - java -jar revanced-cli.jar -b revanced-patches.jar \ + java -jar revanced-cli.jar -m revanced-integrations.apk -b revanced-patches.jar \ ${patches[@]} \ $EXPERIMENTAL \ -a com.google.android.apps.youtube.music.apk -o revanced-ytm-nonroot.apk diff --git a/download_apkmirror.sh b/download_apkmirror.sh index c24706b..07d1b1b 100755 --- a/download_apkmirror.sh +++ b/download_apkmirror.sh @@ -25,6 +25,13 @@ req() { wget -nv -O "$2" --header="$WGET_HEADER" "$1"; } # if [[ $max = 0 ]]; then echo ""; else echo "$max"; fi # } +# Returns if $1 is less than $2 +ver_less_than() { + [ ${1:0:1} == "v" ] && var1=${1:1} || var1=$1 + [ ${2:0:1} == "v" ] && var2=${2:1} || var2=$2 + [ $(echo $var1$'\n'$var2 | sort -V | tail -n1) != $var1 ] && echo true || echo false +} + # Wget download apk dl_apk() { local url=$1 regexp=$2 output=$3 @@ -95,8 +102,8 @@ for apk in "${!apks[@]}"; do supported_vers="$(jq -r '.[].compatiblePackages[] | select(.name == "'$apk'") | .versions | last' patches.json)" version=0 for vers in $supported_vers; do - [ $vers != "null" ] && [[ $version==0 || ${vers//[!0-9]/} -lt ${version//[!0-9]/} ]] && version=$vers + [ $vers != "null" ] && [[ $(ver_less_than $vers $version) == true || $version == 0 ]] && version=$vers done version_present=$(jq -r ".\"$apk\"" versions.json) - [[ ${version_present//[!0-9]/} -lt ${version//[!0-9]/} || ! -f $apk.apk ]] && ${apks[$apk]} || echo "Recommended version of "$apk" is already present" | tee -a build.log + [[ $(ver_less_than $version_present $version) == true || ! -f $apk.apk || $2 == force ]] && ${apks[$apk]} || echo "Recommended version of "$apk" is already present" | tee -a build.log done