Update patch.sh (#1)

This commit is contained in:
FiorenMas
2023-04-08 22:31:13 +07:00
committed by GitHub
parent 97c66da4bf
commit b5b68467cd

155
patch.sh
View File

@@ -1,77 +1,53 @@
#!/bin/bash #!/bin/bash
# Config to patch Revanced and Revanced Extended # Input *ytversion number/blank(or # before) to set specific/auto choose YouTube version
# Input YTVERSION number of version/blank to select specific/auto select YouTube version supported
# Revanced # Set variables for Revanced
cat > keywords.rv << EOF revanced_name="revanced"
NAME="revanced" revanced_user="revanced"
USER="revanced" revanced_patch="patches.rv"
PATCH="patches.rv" revanced_ytversion="" # Input version supported.Exp: 18.03.36
#YTVERSION="18.03.36"
EOF
# Revanced Extended # Set variables for Revanced Extended
cat > keywords.rve << EOF revanced_extended_name="revanced-extended"
NAME="revanced-extended" revanced_extended_user="inotia00"
USER="inotia00" revanced_extended_patch="patches.rve"
PATCH="patches.rve" revanced_extended_ytversion="" # Input version supported.Exp: 18.07.35
#YTVERSION="18.07.35"
EOF
#for var in keywords.rv # Revanced # Function prepare patches keywords
#for var in keywords.rve # Revanced Extended get_patch() {
for var in keywords.rv keywords.rve # Both excluded_start=$(grep -n -m1 'EXCLUDE PATCHES' "$patch_file" \
do | cut -d':' -f1)
source $var included_start=$(grep -n -m1 'INCLUDE PATCHES' "$patch_file" \
| cut -d':' -f1)
# Prepair patches keywords excluded_patches=$(tail -n +$excluded_start $patch_file \
patch_file=$PATCH | head -n "$(( included_start - excluded_start ))" \
| grep '^[^#[:blank:]]')
# Get line numbers where included & excluded patches start from. included_patches=$(tail -n +$included_start $patch_file \
# We rely on the hardcoded messages to get the line numbers using grep | grep '^[^#[:blank:]]')
excluded_start="$(grep -n -m1 'EXCLUDE PATCHES' "$patch_file" \ patches=()
| cut -d':' -f1)" if [ -n "$excluded_patches" ]; then
included_start="$(grep -n -m1 'INCLUDE PATCHES' "$patch_file" \ while read -r patch; do
| cut -d':' -f1)" patches+=("-e $patch")
done <<< "$excluded_patches"
# Get everything but hashes from between the EXCLUDE PATCH & INCLUDE PATCH line fi
# Note: '^[^#[:blank:]]' ignores starting hashes and/or blank characters i.e, whitespace & tab excluding newline if [ -n "$included_patches" ]; then
excluded_patches="$(tail -n +$excluded_start $patch_file \ while read -r patch; do
| head -n "$(( included_start - excluded_start ))" \ patches+=("-i $patch")
| grep '^[^#[:blank:]]')" done <<< "$included_patches"
fi
# Get everything but hashes starting from INCLUDE PATCH line until EOF
included_patches="$(tail -n +$included_start $patch_file \
| grep '^[^#[:blank:]]')"
# Array for storing patches
declare -a patches declare -a patches
# Function for populating patches array, using a function here reduces redundancy & satisfies DRY principals
populate_patches() {
# Note: <<< defines a 'here-string'. Meaning, it allows reading from variables just like from a file
while read -r patch; do
patches+=("$1 $patch")
done <<< "$2"
} }
# Function download latest github releases
# If the variables are NOT empty, call populate_patches with proper arguments
[[ ! -z "$excluded_patches" ]] && populate_patches "-e" "$excluded_patches"
[[ ! -z "$included_patches" ]] && populate_patches "-i" "$included_patches"
# Download resources
echo -e "⏬ Downloading $NAME resources..."
urls_res() { urls_res() {
curl -s "https://api.github.com/repos/$USER/revanced-patches/releases/latest" \ wget -q -O - "https://api.github.com/repos/$user/revanced-patches/releases/latest" \
| jq -r '.assets[].browser_download_url' | jq -r '.assets[].browser_download_url'
curl -s "https://api.github.com/repos/$USER/revanced-cli/releases/latest" \ wget -q -O - "https://api.github.com/repos/$user/revanced-cli/releases/latest" \
| jq -r '.assets[].browser_download_url' | jq -r '.assets[].browser_download_url'
curl -s "https://api.github.com/repos/$USER/revanced-integrations/releases/latest" \ wget -q -O - "https://api.github.com/repos/$user/revanced-integrations/releases/latest" \
| jq -r '.assets[].browser_download_url' | jq -r '.assets[].browser_download_url'
} }
urls_res | wget -qi -
# Download YouTube APK supported # Function download YouTube apk from APKmirror
WGET_HEADER="User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:111.0) Gecko/20100101 Firefox/111.0" WGET_HEADER="User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:111.0) Gecko/20100101 Firefox/111.0"
req() { req() {
@@ -80,7 +56,6 @@ req() {
dl_yt() { dl_yt() {
rm -rf $2 rm -rf $2
echo "⏬ Downloading YouTube v$1..."
url="https://www.apkmirror.com/apk/google-inc/youtube/youtube-${1//./-}-release/" url="https://www.apkmirror.com/apk/google-inc/youtube/youtube-${1//./-}-release/"
url="$url$(req "$url" - \ url="$url$(req "$url" - \
| grep Variant -A50 \ | grep Variant -A50 \
@@ -95,35 +70,49 @@ dl_yt() {
| sed -n 's;.*href="\(.*key=[^"]*\)">.*;\1;p')" | sed -n 's;.*href="\(.*key=[^"]*\)">.*;\1;p')"
req "$url" "$2" req "$url" "$2"
} }
# Function Patch APK
# Download specific or auto choose Youtube version patch_apk() {
if [ $YTVERSION ] ;
then dl_yt $YTVERSION youtube-v$YTVERSION.apk
else YTVERSION=$(jq -r '.[] | select(.name == "microg-support") | .compatiblePackages[] | select(.name == "com.google.android.youtube") | .versions[-1]' patches.json)
dl_yt $YTVERSION youtube-v$YTVERSION.apk
fi
# Patch APK
echo "⚙️ Patching YouTube..."
java -jar revanced-cli*.jar \ java -jar revanced-cli*.jar \
-m revanced-integrations*.apk \ -m revanced-integrations*.apk \
-b revanced-patches*.jar \ -b revanced-patches*.jar \
-a youtube-v$YTVERSION.apk \ -a youtube-v$ytversion.apk \
${patches[@]} \ ${patches[@]} \
--keystore=ks.keystore \ --keystore=ks.keystore \
-o yt-$NAME.apk -o yt-$name.apk
}
# Refresh caches # Function clean caches to new build
echo "🧹 Clean caches..." clean_cache() {
rm -f revanced-cli*.jar \ rm -f revanced-cli*.jar \
revanced-integrations*.apk \ revanced-integrations*.apk \
revanced-patches*.jar \ revanced-patches*.jar \
patches.json \ patches.json \
options.toml \ options.toml \
youtube*.apk \ youtube*.apk \
}
unset patches # Function patch Revanced, Revanced Extended
unset YTVERSION for name in $revanced_name $revanced_extended_name ; do
# Select variables based on name
# Finish if [ "$name" = "$revanced_name" ]; then
user="$revanced_user"
patch_file="$revanced_patch"
ytversion="$revanced_ytversion"
else
user="$revanced_extended_user"
patch_file="$revanced_extended_patch"
ytversion="$revanced_extended_ytversion"
fi
get_patch
echo "⏬ Downloading $name resources..."
urls_res | xargs wget -q -i
if [ $ytversion ] ;
then dl_yt $ytversion youtube-v$ytversion.apk
echo "⏬ Downloading YouTube v$ytversion.."
else ytversion=$(jq -r '.[] | select(.name == "microg-support") | .compatiblePackages[] | select(.name == "com.google.android.youtube") | .versions[-1]' patches.json)
dl_yt $ytversion youtube-v$ytversion.apk
echo "⏬ Downloading YouTube v$ytversion..."
fi
echo "⚙️ Patching YouTube..."
patch_apk
echo "🧹 Clean caches..."
clean_cache
done done