Skip to content

Commit

Permalink
Revamped codebase, added version checking, removed apkmd binary
Browse files Browse the repository at this point in the history
  • Loading branch information
dng-nguyn committed Jan 1, 2024
1 parent 9973daf commit 5b507a3
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ yt.apk
revanced.apk
revanced.keystore
revanced-options.json
version.txt
Binary file removed apkmd
Binary file not shown.
85 changes: 66 additions & 19 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#!/bin/bash
### PLEASE LOOK THROUGH THE SCRIPT BEFORE EXECUTING!!! ###
# Remove old files if present:
rm patch.jar cli.jar integrations.apk download.json yt.apk
rm -d downloads
# remove ReVanced cache
rm -rd revanced-resource-cache

update_function() {
# Download patches, integrations and cli
echo "Downloading files..."
curl -s https://api.github.com/repos/ReVanced/revanced-patches/releases/latest | grep "browser_download_url.*.jar" | cut -d : -f 2,3 | tr -d \" | wget -i - -O patch.jar
curl -s https://api.github.com/repos/ReVanced/revanced-cli/releases/latest | grep "browser_download_url.*.jar" | cut -d : -f 2,3 | tr -d \" | wget -i - -O cli.jar
curl -s https://api.github.com/repos/ReVanced/revanced-integrations/releases/latest | grep "browser_download_url.*.apk" | cut -d : -f 2,3 | tr -d \" | wget -i - -O integrations.apk
echo "Downloading required files..."
curl -s https://api.github.com/repos/ReVanced/revanced-patches/releases/latest | grep "browser_download_url.*.jar" | cut -d : -f 2,3 | tr -d \" | wget --show-progress -qi - -O patch.jar
curl -s https://api.github.com/repos/ReVanced/revanced-cli/releases/latest | grep "browser_download_url.*.jar" | cut -d : -f 2,3 | tr -d \" | wget --show-progress -qi - -O cli.jar
curl -s https://api.github.com/repos/ReVanced/revanced-integrations/releases/latest | grep "browser_download_url.*.apk" | cut -d : -f 2,3 | tr -d \" | wget --show-progress -qi - -O integrations.apk

# Get apkmd from source
curl -s https://api.github.com/repos/tanishqmanuja/apkmirror-downloader/releases/latest | grep "browser_download_url.*apkmd" | grep -v "apkmd.exe" | cut -d : -f 2,3 | tr -d \" | wget --show-progress -qi - -O apkmd
# Add execution permissions for apkmd
chmod +x apkmd
# Command to get the version
echo "Getting version..."
version_command=$(java -jar cli.jar list-versions -f com.google.android.youtube patch.jar | awk '/^[[:space:]]+[0-9]+\.[0-9]+\.[0-9]+/{print $1; exit}')
current_version=$(java -jar cli.jar list-versions -f com.google.android.youtube patch.jar | grep -oP '\d+\.\d+\.\d+' | sed 's/^\s*//' | sort -V | tail -n 1)

# Create a new JSON file with the updated version
cat <<EOL > download.json
Expand All @@ -26,17 +27,18 @@ cat <<EOL > download.json
"name": "yt",
"org": "google-inc",
"repo": "youtube",
"version": "$version_command"
"version": "$current_version"
}
]
}
EOL
echo "Downloading youtube version "$version_command"..."

echo "Downloading youtube version "$current_version"..."
./apkmd download.json
mv ./downloads/yt.apk yt.apk
echo "Patching youtube..."
java -jar cli.jar patch \
--patch-bundle patch.jar \
--patch-bundle=patch.jar \
--exclude="Spoof SIM country" \
--exclude="Spoof Wi-Fi connection" \
--exclude="Predictive back gesture" \
Expand All @@ -48,13 +50,58 @@ java -jar cli.jar patch \
--merge=integrations.apk \
yt.apk \
-o revanced.apk

echo "Finished! Output: revanced.apk"
echo "Cleaning residual files..."
rm patch.jar cli.jar integrations.apk download.json yt.apk
rm -d downloads

echo "$current_version" > version.txt
echo "Saved version.txt for further updates!"
# Optional: Install apk directly
# adb install revanced.apk
}

remove_files () {
echo "Cleaning files..."
rm -f patch.jar cli.jar integrations.apk download.json yt.apk apkmd
rm -fd downloads
# remove ReVanced cache
rm -rd revanced-resource-cache
rm -rf revanced-resource-cache
# This is used for signing the apk. If planned to continue updating, consider keeping this file.
#rm revanced.keystore
# Optional: Install apk directly
#adb install revanced.apk
}
# Remove files before installation:
remove_files

echo "Checking for updates..."

latest_version="$(curl -s https://raw.githubusercontent.com/ReVanced/revanced-patches/main/patches.json | jq -r '.[] | select(.compatiblePackages) | select(.compatiblePackages[] | .name == "com.google.android.youtube") | .compatiblePackages[].versions | if . == null then [] else map(select(. != null and . != "")) end | select(length > 0) | max_by(. // "0" | split(".") | map(tonumber))' | awk 'NR==1 {print}')"
version_file="version.txt"

# Check if version.txt exists
if [ -e "$version_file" ]; then
# Read the local version from the version.txt file
local_version=$(cat "$version_file")

# Check if local_version is empty
if [ -z "$local_version" ]; then
echo "version.txt is found, but it is empty. Executing the script..."
update_function
remove_files
else
# Compare versions
if [ "$latest_version" \> "$local_version" ]; then
echo "Updating to the latest version: $latest_version"
update_function
remove_files
elif [ "$latest_version" = "$local_version" ]; then
echo "You're running on the latest version: $latest_version!"
exit
else
echo "You're running a newer version than expected: Current: $local_version, Source: $latest_version. Please double-check your version.txt!"
exit 1
fi
fi
else
echo "version.txt not found. Executing the script..."
update_function
remove_files
fi

0 comments on commit 5b507a3

Please sign in to comment.