rework module

This commit is contained in:
j-hc 2022-08-08 16:25:32 +03:00
parent 73eeb8e8ae
commit cecf561d4a
No known key found for this signature in database
GPG Key ID: 242B44D16774A2ED
25 changed files with 176 additions and 374 deletions

4
.gitignore vendored
View File

@ -1,10 +1,8 @@
*.jar
*.apk
*.zip
*.so*
xdelta_*
/revanced-cache
/temp
/build
build.log
test.sh
/test

View File

@ -4,11 +4,9 @@
This repo includes a simple script that downloads all the latest version of necessary prebuilt revanced tools and build patched apps according to your config file (so do not create issues related to revanced in this repo).
You will need to **install the stock YouTube (or YT Music) app matching with the module's version on your phone** from the link is provided in releases section. Patching **may fail** if you install from some different source.
You can get the [latest CI release from here](https://github.com/j-hc/revanced-magisk-module/releases).
The [mindetach module](https://github.com/j-hc/mindetach-magisk) in the releases section detaches YouTube and YouTube Music from Play Store and blocks it from updating them.
The [**mindetach module**](https://github.com/j-hc/mindetach-magisk) in the releases section detaches YouTube and YouTube Music from Play Store and blocks it from updating them.
## To include/exclude patches or build non-root variant
* Star the repo :eyes:

View File

@ -5,7 +5,7 @@ MUSIC_PATCHER_ARGS="-e music-microg-support"
BUILD_YT=true
BUILD_MUSIC_ARM64_V8A=true
BUILD_MUSIC_ARM_V7A=false
BUILD_MUSIC_ARM_V7A=true
BUILD_TWITTER=true
BUILD_REDDIT=true

View File

@ -49,4 +49,5 @@ if [ "$BUILD_MINDETACH_MODULE" = true ]; then
cd ../../
fi
reset_template
echo "Done"

View File

@ -1,239 +0,0 @@
# MMT Extended functions (all credits goes to Zackptg5)
cleanup() {
rm -rf $MODPATH/common 2>/dev/null
}
abort() {
ui_print "$1"
rm -rf $MODPATH 2>/dev/null
cleanup
rm -rf $TMPDIR 2>/dev/null
exit 1
}
device_check() {
local opt=$(getopt -o dm -- "$@") type=device
eval set -- "$opt"
while true; do
case "$1" in
-d)
local type=device
shift
;;
-m)
local type=manufacturer
shift
;;
--)
shift
break
;;
*) abort "Invalid device_check argument $1! Aborting!" ;;
esac
done
local prop=$(echo "$1" | tr '[:upper:]' '[:lower:]')
for i in /system /vendor /odm /product; do
if [ -f $i/build.prop ]; then
for j in "ro.product.$type" "ro.build.$type" "ro.product.vendor.$type" "ro.vendor.product.$type"; do
[ "$(sed -n "s/^$j=//p" $i/build.prop 2>/dev/null | head -n 1 | tr '[:upper:]' '[:lower:]')" == "$prop" ] && return 0
done
[ "$type" == "device" ] && [ "$(sed -n "s/^"ro.build.product"=//p" $i/build.prop 2>/dev/null | head -n 1 | tr '[:upper:]' '[:lower:]')" == "$prop" ] && return 0
fi
done
return 1
}
cp_ch() {
local opt=$(getopt -o nr -- "$@") BAK=true UBAK=true FOL=false
eval set -- "$opt"
while true; do
case "$1" in
-n)
UBAK=false
shift
;;
-r)
FOL=true
shift
;;
--)
shift
break
;;
*) abort "Invalid cp_ch argument $1! Aborting!" ;;
esac
done
local SRC="$1" DEST="$2" OFILES="$1"
$FOL && local OFILES=$(find $SRC -type f 2>/dev/null)
[ -z $3 ] && PERM=0644 || PERM=$3
case "$DEST" in
$TMPDIR/* | $MODULEROOT/* | $NVBASE/modules/$MODID/*) BAK=false ;;
esac
for OFILE in ${OFILES}; do
if $FOL; then
if [ "$(basename $SRC)" == "$(basename $DEST)" ]; then
local FILE=$(echo $OFILE | sed "s|$SRC|$DEST|")
else
local FILE=$(echo $OFILE | sed "s|$SRC|$DEST/$(basename $SRC)|")
fi
else
[ -d "$DEST" ] && local FILE="$DEST/$(basename $SRC)" || local FILE="$DEST"
fi
if $BAK && $UBAK; then
[ ! "$(grep "$FILE$" $INFO 2>/dev/null)" ] && echo "$FILE" >>$INFO
[ -f "$FILE" -a ! -f "$FILE~" ] && {
mv -f $FILE $FILE~
echo "$FILE~" >>$INFO
}
elif $BAK; then
[ ! "$(grep "$FILE$" $INFO 2>/dev/null)" ] && echo "$FILE" >>$INFO
fi
install -D -m $PERM "$OFILE" "$FILE"
done
}
install_script() {
case "$1" in
-l)
shift
local INPATH=$NVBASE/service.d
;;
-p)
shift
local INPATH=$NVBASE/post-fs-data.d
;;
*) local INPATH=$NVBASE/service.d ;;
esac
[ "$(grep "#!/system/bin/sh" $1)" ] || sed -i "1i #!/system/bin/sh" $1
local i
for i in "MODPATH" "MODID" "INFO" "MODDIR"; do
case $i in
"MODPATH") sed -i "1a $i=$NVBASE/modules/$MODID" $1 ;;
"MODDIR") sed -i "1a $i=\${0%/*}" $1 ;;
*) sed -i "1a $i=$(eval echo \$$i)" $1 ;;
esac
done
[ "$1" == "$MODPATH/uninstall.sh" ] && return 0
case $(basename $1) in
post-fs-data.sh | service.sh) ;;
*) cp_ch -n $1 $INPATH/$(basename $1) 0755 ;;
esac
}
prop_process() {
sed -i -e "/^#/d" -e "/^ *$/d" $1
[ -f $MODPATH/system.prop ] || mktouch $MODPATH/system.prop
while read LINE; do
echo "$LINE" >>$MODPATH/system.prop
done <$1
}
# Check for min/max api version
[ -z $MINAPI ] || { [ $API -lt $MINAPI ] && abort "! Your system API of $API is less than the minimum api of $MINAPI! Aborting!"; }
[ -z $MAXAPI ] || { [ $API -gt $MAXAPI ] && abort "! Your system API of $API is greater than the maximum api of $MAXAPI! Aborting!"; }
# Set variables
[ -z $ARCH32 ] && ARCH32="$(echo $ABI32 | cut -c-3)"
[ -z $DEBUG ] && DEBUG=false
INFO=$NVBASE/modules/.$MODID-files
if ! $BOOTMODE; then
ui_print "- Only uninstall is supported in recovery"
ui_print " Uninstalling!"
touch $MODPATH/remove
[ -s $INFO ] && install_script $MODPATH/uninstall.sh || rm -f $INFO $MODPATH/uninstall.sh
recovery_cleanup
cleanup
rm -rf $NVBASE/modules_update/$MODID $TMPDIR 2>/dev/null
exit 0
fi
# Debug
if $DEBUG; then
ui_print "- Debug mode"
ui_print " Module install log will include debug info"
ui_print " Be sure to save it after module install"
set -x
fi
# Extract files
ui_print "- Extracting module files"
unzip -o "$ZIPFILE" -x 'META-INF/*' 'common/functions.sh' -d $MODPATH >&2
[ -f "$MODPATH/common/addon.tar.xz" ] && tar -xf $MODPATH/common/addon.tar.xz -C $MODPATH/common 2>/dev/null
# Run addons
if [ "$(ls -A $MODPATH/common/addon/*/install.sh 2>/dev/null)" ]; then
ui_print " "
ui_print "- Running Addons -"
for i in $MODPATH/common/addon/*/install.sh; do
ui_print " Running $(echo $i | sed -r "s|$MODPATH/common/addon/(.*)/install.sh|\1|")..."
. $i
done
fi
# Remove files outside of module directory
ui_print "- Removing old files"
if [ -f $INFO ]; then
while read LINE; do
if [ "$(echo -n $LINE | tail -c 1)" == "~" ]; then
continue
elif [ -f "$LINE~" ]; then
mv -f $LINE~ $LINE
else
rm -f $LINE
while true; do
LINE=$(dirname $LINE)
[ "$(ls -A $LINE 2>/dev/null)" ] && break 1 || rm -rf $LINE
done
fi
done <$INFO
rm -f $INFO
fi
### Install
ui_print "- Installing"
[ -f "$MODPATH/common/install.sh" ] && . $MODPATH/common/install.sh
ui_print " Installing for $ARCH SDK $API device..."
# Remove comments from files and place them, add blank line to end if not already present
for i in $(find $MODPATH -type f -name "*.sh" -o -name "*.prop" -o -name "*.rule"); do
[ -f $i ] && {
sed -i -e "/^#/d" -e "/^ *$/d" $i
[ "$(tail -1 $i)" ] && echo "" >>$i
} || continue
case $i in
"$MODPATH/service.sh") install_script -l $i ;;
"$MODPATH/post-fs-data.sh") install_script -p $i ;;
"$MODPATH/uninstall.sh") if [ -s $INFO ] || [ "$(head -n1 $MODPATH/uninstall.sh)" != "# Don't modify anything after this" ]; then
install_script $MODPATH/uninstall.sh
else
rm -f $INFO $MODPATH/uninstall.sh
fi ;;
esac
done
$IS64BIT || for i in $(find $MODPATH/system -type d -name "lib64"); do rm -rf $i 2>/dev/null; done
[ -d "/system/priv-app" ] || mv -f $MODPATH/system/priv-app $MODPATH/system/app 2>/dev/null
[ -d "/system/xbin" ] || mv -f $MODPATH/system/xbin $MODPATH/system/bin 2>/dev/null
ui_print " by j-hc (github.com/j-hc)"
# Set permissions
ui_print " "
ui_print "- Setting Permissions"
set_perm_recursive $MODPATH 0 0 0755 0644
if [ -d $MODPATH/system/vendor ]; then
set_perm_recursive $MODPATH/system/vendor 0 0 0755 0644 u:object_r:vendor_file:s0
[ -d $MODPATH/system/vendor/app ] && set_perm_recursive $MODPATH/system/vendor/app 0 0 0755 0644 u:object_r:vendor_app_file:s0
[ -d $MODPATH/system/vendor/etc ] && set_perm_recursive $MODPATH/system/vendor/etc 0 0 0755 0644 u:object_r:vendor_configs_file:s0
[ -d $MODPATH/system/vendor/overlay ] && set_perm_recursive $MODPATH/system/vendor/overlay 0 0 0755 0644 u:object_r:vendor_overlay_file:s0
for FILE in $(find $MODPATH/system/vendor -type f -name *".apk"); do
[ -f $FILE ] && chcon u:object_r:vendor_app_file:s0 $FILE
done
fi
set_permissions
# Complete install
cleanup

View File

@ -1 +0,0 @@
# utils

View File

@ -1,11 +1,47 @@
MINAPI=21
#MAXAPI=25
#DEBUG=true
# shellcheck disable=SC2148,SC2086,SC2115
ui_print ""
am force-stop com.google.android.apps.youtube.music
grep com.google.android.apps.youtube.music /proc/mounts | while read -r line; do
ui_print "* Un-mount"
echo "$line" | cut -d" " -f2 | xargs -r umount -l
done
pm uninstall com.google.android.apps.youtube.music >/dev/null 2>&1 && ui_print "* Uninstalled current com.google.android.apps.youtube.music"
set_permissions() {
:
}
ui_print "* Installing stock com.google.android.apps.youtube.music APK"
set_perm $MODPATH/stock.apk 0 0 644 u:object_r:apk_data_file:s0
if ! op=$(pm install -r -g $MODPATH/stock.apk 2>&1); then
ui_print "ERROR: APK installation failed!"
abort "${op}"
fi
SKIPUNZIP=1
unzip -qjo "$ZIPFILE" 'common/functions.sh' -d $TMPDIR >&2
. $TMPDIR/functions.sh
ui_print "* Patching com.google.android.apps.youtube.music (v5.17.51) on the fly"
BASEPATH=$(pm path com.google.android.apps.youtube.music | grep base | cut -d: -f2)
[ -z "$BASEPATH" ] && abort "ERROR: Base path not found!"
if [ "$ARCH" = "arm" ]; then
export LD_LIBRARY_PATH=$MODPATH/lib/arm
ln -s $MODPATH/xdelta_arm $MODPATH/xdelta
elif [ "$ARCH" = "arm64" ]; then
export LD_LIBRARY_PATH=$MODPATH/lib/aarch64
ln -s $MODPATH/xdelta_aarch64 $MODPATH/xdelta
else
abort "ERROR: unsupported arch: ${ARCH}"
fi
chmod +x $MODPATH/xdelta
if ! op=$($MODPATH/xdelta -d -f -s $BASEPATH $MODPATH/rvc.xdelta $MODPATH/base.apk 2>&1); then
ui_print "ERROR: Patching failed!"
abort "$op"
fi
ui_print "* Patching done"
ui_print "* Setting Permissions"
set_perm $MODPATH/base.apk 1000 1000 644 u:object_r:apk_data_file:s0
ui_print "* Mounting com.google.android.apps.youtube.music"
if ! op=$(mount -o bind $MODPATH/base.apk $BASEPATH 2>&1); then
ui_print "ERROR: Mount failed!"
abort "$op"
fi
ui_print " "
rm -r $MODPATH/lib $MODPATH/*xdelta* $MODPATH/stock.apk
am force-stop com.google.android.apps.youtube.music

View File

@ -0,0 +1 @@
liblzma.so.5.2.5

View File

@ -0,0 +1 @@
liblzma.so.5.2.5

Binary file not shown.

View File

@ -0,0 +1 @@
liblzma.so.5.2.5

View File

@ -0,0 +1 @@
liblzma.so.5.2.5

Binary file not shown.

View File

@ -1 +1,7 @@
# utils
id=ytmusicrv-arm-magisk
name=YouTube Music ReVanced
version=v5.17.51
versionCode=20220808
author=j-hc
description=mounts base.apk for YouTube Music ReVanced
updateJson=https://raw.githubusercontent.com/j-hc/revanced-magisk-module/update/music-update-arm-v7a.json

View File

@ -1 +1,4 @@
# utils
#!/system/bin/sh
grep com.google.android.apps.youtube.music /proc/mounts | while read -r line; do
echo "$line" | cut -d" " -f2 | xargs -r umount -l
done

BIN
revanced-magisk/rvc.xdelta Normal file

Binary file not shown.

View File

@ -1 +1,11 @@
# utils
#!/system/bin/sh
# shellcheck disable=SC2086
MODDIR=${0%/*}
until [ "$(getprop sys.boot_completed)" = 1 ]; do
sleep 1
done
BASEPATH=$(pm path com.google.android.apps.youtube.music | grep base | cut -d: -f2)
if [ "$BASEPATH" ]; then
chcon u:object_r:apk_data_file:s0 $MODDIR/base.apk
mount -o bind $MODDIR/base.apk $BASEPATH
fi

View File

@ -1,17 +0,0 @@
# Don't modify anything after this
if [ -f $INFO ]; then
while read LINE; do
if [ "$(echo -n $LINE | tail -c 1)" == "~" ]; then
continue
elif [ -f "$LINE~" ]; then
mv -f $LINE~ $LINE
else
rm -f $LINE
while true; do
LINE=$(dirname $LINE)
[ "$(ls -A $LINE 2>/dev/null)" ] && break 1 || rm -rf $LINE
done
fi
done < $INFO
rm -f $INFO
fi

BIN
revanced-magisk/xdelta_aarch64 Executable file

Binary file not shown.

BIN
revanced-magisk/xdelta_arm Executable file

Binary file not shown.

47
scripts/customize.sh Executable file
View File

@ -0,0 +1,47 @@
# shellcheck disable=SC2148,SC2086,SC2115
ui_print ""
am force-stop __PKGNAME
grep __PKGNAME /proc/mounts | while read -r line; do
ui_print "* Un-mount"
echo "$line" | cut -d" " -f2 | xargs -r umount -l
done
pm uninstall __PKGNAME >/dev/null 2>&1 && ui_print "* Uninstalled current __PKGNAME"
ui_print "* Installing stock __PKGNAME APK"
set_perm $MODPATH/stock.apk 0 0 644 u:object_r:apk_data_file:s0
if ! op=$(pm install -r -g $MODPATH/stock.apk 2>&1); then
ui_print "ERROR: APK installation failed!"
abort "${op}"
fi
ui_print "* Patching __PKGNAME (v__MDVRSN) on the fly"
BASEPATH=$(pm path __PKGNAME | grep base | cut -d: -f2)
[ -z "$BASEPATH" ] && abort "ERROR: Base path not found!"
if [ "$ARCH" = "arm" ]; then
export LD_LIBRARY_PATH=$MODPATH/lib/arm
ln -s $MODPATH/xdelta_arm $MODPATH/xdelta
elif [ "$ARCH" = "arm64" ]; then
export LD_LIBRARY_PATH=$MODPATH/lib/aarch64
ln -s $MODPATH/xdelta_aarch64 $MODPATH/xdelta
else
abort "ERROR: unsupported arch: ${ARCH}"
fi
chmod +x $MODPATH/xdelta
if ! op=$($MODPATH/xdelta -d -f -s $BASEPATH $MODPATH/rvc.xdelta $MODPATH/base.apk 2>&1); then
ui_print "ERROR: Patching failed!"
abort "$op"
fi
ui_print "* Patching done"
ui_print "* Setting Permissions"
set_perm $MODPATH/base.apk 1000 1000 644 u:object_r:apk_data_file:s0
ui_print "* Mounting __PKGNAME"
if ! op=$(mount -o bind $MODPATH/base.apk $BASEPATH 2>&1); then
ui_print "ERROR: Mount failed!"
abort "$op"
fi
ui_print " "
rm -r $MODPATH/lib $MODPATH/*xdelta* $MODPATH/stock.apk
am force-stop __PKGNAME

4
scripts/post-fs-data.sh Normal file
View File

@ -0,0 +1,4 @@
#!/system/bin/sh
grep __PKGNAME /proc/mounts | while read -r line; do
echo "$line" | cut -d" " -f2 | xargs -r umount -l
done

11
scripts/service.sh Normal file
View File

@ -0,0 +1,11 @@
#!/system/bin/sh
# shellcheck disable=SC2086
MODDIR=${0%/*}
until [ "$(getprop sys.boot_completed)" = 1 ]; do
sleep 1
done
BASEPATH=$(pm path __PKGNAME | grep base | cut -d: -f2)
if [ "$BASEPATH" ]; then
chcon u:object_r:apk_data_file:s0 $MODDIR/base.apk
mount -o bind $MODDIR/base.apk $BASEPATH
fi

135
utils.sh
View File

@ -1,23 +1,26 @@
#!/bin/bash
MODULE_TEMPLATE_DIR="revanced-magisk"
MODULE_SCRIPTS_DIR="scripts"
TEMP_DIR="temp"
BUILD_DIR="build"
ARM64_V8A="arm64-v8a"
ARM_V7A="arm-v7a"
GITHUB_REPOSITORY=${GITHUB_REPOSITORY:-$GITHUB_REPO_FALLBACK}
NEXT_VER_CODE=${NEXT_VER_CODE:-$(date +'%Y%m%d')}
WGET_HEADER="User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0"
SERVICE_SH=$(cat $MODULE_SCRIPTS_DIR/service.sh)
POSTFSDATA_SH=$(cat $MODULE_SCRIPTS_DIR/post-fs-data.sh)
CUSTOMIZE_SH=$(cat $MODULE_SCRIPTS_DIR/customize.sh)
get_prebuilts() {
echo "Getting prebuilts"
mkdir -p "$TEMP_DIR"
RV_CLI_URL=$(req https://api.github.com/repos/revanced/revanced-cli/releases/latest - | tr -d ' ' | sed -n 's/.*"browser_download_url":"\(.*jar\)".*/\1/p')
RV_CLI_JAR="${TEMP_DIR}/$(echo "$RV_CLI_URL" | awk -F/ '{ print $NF }')"
log "CLI: ${RV_CLI_JAR#"$TEMP_DIR/"}"
RV_INTEGRATIONS_URL=$(req https://api.github.com/repos/revanced/revanced-integrations/releases/latest - | tr -d ' ' | sed -n 's/.*"browser_download_url":"\(.*apk\)".*/\1/p')
RV_INTEGRATIONS_APK="${TEMP_DIR}/$(echo "$RV_INTEGRATIONS_URL" | awk '{n=split($0, arr, "/"); printf "%s-%s.apk", substr(arr[n], 0, length(arr[n]) - 4), arr[n-1]}')"
log "Integrations: ${RV_INTEGRATIONS_APK#"$TEMP_DIR/"}"
@ -33,6 +36,7 @@ get_prebuilts() {
extract_deb() {
local output=$1 url=$2 path=$3
if [ -f "$output" ] || [ -n "$(ls -A "$output")" ]; then return; fi
local deb_path="${TEMP_DIR}/${url##*/}"
dl_if_dne "$deb_path" "$url"
ar x "$deb_path" data.tar.xz
@ -46,36 +50,46 @@ extract_deb() {
}
get_xdelta() {
echo "Getting xdelta binaries"
extract_deb "${MODULE_TEMPLATE_DIR}/xdelta_aarch64" "https://grimler.se/termux/termux-main/pool/main/x/xdelta3/xdelta3_3.1.0-1_aarch64.deb" "./data/data/com.termux/files/usr/bin/xdelta3"
extract_deb "${MODULE_TEMPLATE_DIR}/xdelta_arm" "https://grimler.se/termux/termux-main/pool/main/x/xdelta3/xdelta3_3.1.0-1_arm.deb" "./data/data/com.termux/files/usr/bin/xdelta3"
echo "Getting liblzma libs"
extract_deb "${MODULE_TEMPLATE_DIR}/lib/arm/" "https://grimler.se/termux/termux-main/pool/main/libl/liblzma/liblzma_5.2.5-1_arm.deb" "./data/data/com.termux/files/usr/lib/*so*"
extract_deb "${MODULE_TEMPLATE_DIR}/lib/aarch64/" "https://grimler.se/termux/termux-main/pool/main/libl/liblzma/liblzma_5.2.5-1_aarch64.deb" "./data/data/com.termux/files/usr/lib/*so*"
}
abort() { echo "$1" && exit 1; }
set_prebuilts() {
[ -d "$TEMP_DIR" ] || {
echo "${TEMP_DIR} directory could not be found"
exit 1
}
[ -d "$TEMP_DIR" ] || abort "${TEMP_DIR} directory could not be found"
RV_CLI_JAR=$(find "$TEMP_DIR" -maxdepth 1 -name "revanced-cli-*" | tail -n1)
[ -z "$RV_CLI_JAR" ] && abort "revanced cli not found"
log "CLI: ${RV_CLI_JAR#"$TEMP_DIR/"}"
RV_INTEGRATIONS_APK=$(find "$TEMP_DIR" -maxdepth 1 -name "app-release-unsigned-*" | tail -n1)
[ -z "$RV_CLI_JAR" ] && abort "revanced integrations not found"
log "Integrations: ${RV_INTEGRATIONS_APK#"$TEMP_DIR/"}"
RV_PATCHES_JAR=$(find "$TEMP_DIR" -maxdepth 1 -name "revanced-patches-*" | tail -n1)
[ -z "$RV_CLI_JAR" ] && abort "revanced patches not found"
log "Patches: ${RV_PATCHES_JAR#"$TEMP_DIR/"}"
}
reset_template() {
echo "# utils" >"${MODULE_TEMPLATE_DIR}/service.sh"
echo "# utils" >"${MODULE_TEMPLATE_DIR}/post-fs-data.sh"
echo "# utils" >"${MODULE_TEMPLATE_DIR}/common/install.sh"
echo "# utils" >"${MODULE_TEMPLATE_DIR}/customize.sh"
echo "# utils" >"${MODULE_TEMPLATE_DIR}/module.prop"
rm -rf "${MODULE_TEMPLATE_DIR}/rv.xdelta"
mkdir -p "${MODULE_TEMPLATE_DIR}/lib/arm" "${MODULE_TEMPLATE_DIR}/lib/aarch64"
rm -rf ${MODULE_TEMPLATE_DIR}/rvc.xdelta ${MODULE_TEMPLATE_DIR}/*.apk
mkdir -p ${MODULE_TEMPLATE_DIR}/lib/arm ${MODULE_TEMPLATE_DIR}/lib/aarch64
}
req() { wget -nv -O "$2" --header="$WGET_HEADER" "$1"; }
log() { echo -e "$1 " >>build.log; }
get_apk_vers() { req "$1" - | sed -n 's;.*Version:</span><span class="infoSlide-value">\(.*\) </span>.*;\1;p'; }
get_patch_last_supported_ver() {
declare -r supported_versions=$(unzip -p "$RV_PATCHES_JAR" | strings -s , | sed -rn "s/.*${1},versions,(([0-9.]*,*)*),Lk.*/\1/p")
echo "${supported_versions##*,}"
}
dl_if_dne() {
if [ ! -f "$1" ]; then
@ -84,8 +98,6 @@ dl_if_dne() {
fi
}
log() { echo -e "$1 " >>build.log; }
dl_apk() {
local url=$1 regexp=$2 output=$3
url="https://www.apkmirror.com$(req "$url" - | tr '\n' ' ' | sed -n "s/href=\"/@/g; s;.*${regexp}.*;\1;p")"
@ -95,13 +107,6 @@ dl_apk() {
req "$url" "$output"
}
get_apk_vers() { req "$1" - | sed -n 's;.*Version:</span><span class="infoSlide-value">\(.*\) </span>.*;\1;p'; }
get_patch_last_supported_ver() {
declare -r supported_versions=$(unzip -p "$RV_PATCHES_JAR" | strings -s , | sed -rn "s/.*${1},versions,(([0-9.]*,*)*),Lk.*/\1/p")
echo "${supported_versions##*,}"
}
xdelta_patch() {
if [ -f "$3" ]; then return; fi
echo "Binary diffing ${2} against ${1}"
@ -116,8 +121,9 @@ patch_apk() {
}
zip_module() {
local xdelta_patch=$1 module_name=$2
cp -f "$xdelta_patch" "${MODULE_TEMPLATE_DIR}/rv.xdelta"
local xdelta_patch=$1 module_name=$2 stock_apk=$3
cp -f "$xdelta_patch" "${MODULE_TEMPLATE_DIR}/rvc.xdelta"
cp -f "$stock_apk" "${MODULE_TEMPLATE_DIR}/stock.apk"
cd "$MODULE_TEMPLATE_DIR" || exit 1
zip -FSr "../${BUILD_DIR}/${module_name}" .
cd ..
@ -183,7 +189,7 @@ build_yt() {
service_sh "com.google.android.youtube"
postfsdata_sh "com.google.android.youtube"
install_sh "com.google.android.youtube" "$last_ver"
customize_sh "com.google.android.youtube" "$last_ver"
module_prop "ytrv-magisk" \
"YouTube ReVanced" \
"$last_ver" \
@ -193,7 +199,7 @@ build_yt() {
local output="youtube-revanced-magisk-v${last_ver}-all.zip"
local xdelta="${TEMP_DIR}/youtube-revanced-v${last_ver}.xdelta"
xdelta_patch "$stock_apk" "$patched_apk" "$xdelta"
zip_module "$xdelta" "$output"
zip_module "$xdelta" "$output" "$stock_apk"
echo "Built YouTube: '${BUILD_DIR}/${output}'"
}
@ -227,7 +233,7 @@ build_music() {
service_sh "com.google.android.apps.youtube.music"
postfsdata_sh "com.google.android.apps.youtube.music"
install_sh "com.google.android.apps.youtube.music" "$last_ver"
customize_sh "com.google.android.apps.youtube.music" "$last_ver"
local update_json="https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/update/music-update-${arch}.json"
if [ "$arch" = "$ARM64_V8A" ]; then
@ -247,80 +253,15 @@ build_music() {
local output="music-revanced-magisk-v${last_ver}-${arch}.zip"
local xdelta="${TEMP_DIR}/music-revanced-v${last_ver}.xdelta"
xdelta_patch "$stock_apk" "$patched_apk" "$xdelta"
zip_module "$xdelta" "$output"
echo "Built Music '${BUILD_DIR}/${output}'"
zip_module "$xdelta" "$output" "$stock_apk"
echo "Built Music (${arch}) '${BUILD_DIR}/${output}'"
}
service_sh() {
#shellcheck disable=SC2016
local s='until [ "$(getprop sys.boot_completed)" = 1 ]; do
sleep 1
done
BASEPATH=$(pm path __PKGNAME | grep base | cut -d: -f2)
if [ "$BASEPATH" ]; then
chcon u:object_r:apk_data_file:s0 $MODDIR/base.apk
mount -o bind $MODDIR/base.apk $BASEPATH
fi'
echo "${s//__PKGNAME/$1}" >"${MODULE_TEMPLATE_DIR}/service.sh"
}
postfsdata_sh() {
#shellcheck disable=SC2016
local s='grep __PKGNAME /proc/mounts | while read -r line; do
echo "$line" | cut -d" " -f2 | xargs -r umount -l
done'
echo "${s//__PKGNAME/$1}" >"${MODULE_TEMPLATE_DIR}/post-fs-data.sh"
}
install_sh() {
#shellcheck disable=SC2016
local s='ui_print ""
DUMP=$(dumpsys package __PKGNAME)
MODULE_VER=__MDVRSN
CUR_VER=$(echo "$DUMP" | grep versionName | head -n1 | cut -d= -f2)
[ -z "$CUR_VER" ] && "ERROR: __PKGNAME is not installed!"
am force-stop __PKGNAME
grep __PKGNAME /proc/mounts | while read -r line; do
ui_print "* Un-mount"
echo "$line" | cut -d" " -f2 | xargs -r umount -l
done
if [ "$MODULE_VER" != "$CUR_VER" ]; then
ui_print "ERROR: __PKGNAME version mismatch!"
ui_print " installed : ${CUR_VER}"
ui_print " module : ${MODULE_VER}"
abort ""
fi
ui_print "* Patching __PKGNAME"
if [ "$ARCH" = "arm" ]; then
export LD_LIBRARY_PATH=$MODPATH/lib/arm
ln -s $MODPATH/xdelta_arm $MODPATH/xdelta
elif [ "$ARCH" = "arm64" ]; then
export LD_LIBRARY_PATH=$MODPATH/lib/aarch64
ln -s $MODPATH/xdelta_aarch64 $MODPATH/xdelta
else
abort "ERROR: unsupported arch: ${ARCH}"
fi
chmod +x $MODPATH/xdelta
BASEPATH=$(echo "$DUMP" | grep path | cut -d: -f2 | xargs)
[ -z "$BASEPATH" ] && abort "ERROR: Base path not found!"
if ! op=$($MODPATH/xdelta -d -f -s $BASEPATH $MODPATH/rv.xdelta $MODPATH/base.apk 2>&1); then
ui_print "ERROR: Patching failed!"
ui_print "Make sure you installed __PKGNAME from the link given in releases section."
abort "$op"
fi
ui_print "* Patching done"
chcon u:object_r:apk_data_file:s0 $MODPATH/base.apk
if ! op=$(mount -o bind $MODPATH/base.apk $BASEPATH 2>&1); then
ui_print "ERROR: Mount failed!"
abort "$op"
fi
ui_print "* Mounted __PKGNAME"
rm -r $MODPATH/lib $MODPATH/*xdelta*
am force-stop __PKGNAME'
s="${s//__PKGNAME/$1}"
echo "${s//__MDVRSN/$2}" >"${MODULE_TEMPLATE_DIR}/common/install.sh"
service_sh() { echo "${SERVICE_SH//__PKGNAME/$1}" >"${MODULE_TEMPLATE_DIR}/service.sh"; }
postfsdata_sh() { echo "${POSTFSDATA_SH//__PKGNAME/$1}" >"${MODULE_TEMPLATE_DIR}/post-fs-data.sh"; }
customize_sh() {
s="${CUSTOMIZE_SH//__PKGNAME/$1}"
echo "${s//__MDVRSN/$2}" >"${MODULE_TEMPLATE_DIR}/customize.sh"
}
module_prop() {