Skip to content

Commit

Permalink
mount bind from different dir (fixes #46)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-hc committed Sep 12, 2022
1 parent 9a30eec commit bf309d3
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 26 deletions.
15 changes: 15 additions & 0 deletions options.toml
@@ -0,0 +1,15 @@
# A list of options for each patch.
# This file does not contain all options by default.
# Run the CLI with the "--list --with-options" flags to see all available options.
# You can also run the CLI with the aforementioned flags and a patch name to see all available options for that patch.
# To set an option, add a line with the format "option = value".
# To remove or reset an option to its default value, delete the line.
# To reset all options to their default values, delete this file.
#
# This file was generated by ReVanced Patcher version 4.3.0.

['custom-branding']
appName = "YouTube ReVanced"

[theme]
theme = "Amoled"
Binary file removed revanced-magisk/bin/arm/xdelta
Binary file not shown.
Binary file removed revanced-magisk/bin/arm64/xdelta
Binary file not shown.
1 change: 1 addition & 0 deletions revanced-magisk/uninstall.sh
@@ -0,0 +1 @@
# utils
22 changes: 13 additions & 9 deletions scripts/customize.sh
@@ -1,17 +1,12 @@
# shellcheck disable=SC2148,SC2086,SC2115
ui_print ""

grep __PKGNAME /proc/self/mountinfo | while read -r line; do
mountpoint=$(echo "$line" | cut -d' ' -f5)
umount -l "${mountpoint%%\\*}"
done

if [ $ARCH = "arm" ]; then
alias cmpr='$MODPATH/bin/arm/cmpr'
elif [ $ARCH = "arm64" ]; then
alias cmpr='$MODPATH/bin/arm64/cmpr'
else
abort "ERROR: unsupported arch: ${ARCH}!"
abort "ERROR: unsupported arch: ${ARCH}"
fi
set_perm_recursive $MODPATH/bin 0 0 0755 0777

Expand All @@ -20,6 +15,13 @@ basepath() {
echo ${basepath#*:}
}

grep __PKGNAME /proc/self/mountinfo | while read -r line; do
ui_print "* Un-mount"
mountpoint=$(echo "$line" | cut -d' ' -f5)
umount -l "${mountpoint%%\\*}"
done
am force-stop __PKGNAME

BASEPATH=$(basepath)
if [ -n "$BASEPATH" ] && cmpr $BASEPATH $MODPATH/__PKGNAME.apk; then
ui_print "* Installed __PKGNAME and module APKs are identical"
Expand All @@ -36,18 +38,20 @@ else
abort "ERROR: install __PKGNAME manually and reflash the module"
fi
fi

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=$(su -Mc mount -o bind $MODPATH/base.apk $BASEPATH 2>&1); then
RVPATH=/data/local/tmp/__PKGNAME_rv.apk
ln -f $MODPATH/base.apk $RVPATH

if ! op=$(su -Mc mount -o bind $RVPATH $BASEPATH 2>&1); then
ui_print "ERROR: Mount failed!"
abort "$op"
fi
rm -r $MODPATH/bin $MODPATH/__PKGNAME.apk
am force-stop __PKGNAME

ui_print "* Done"
ui_print " by j-hc (github.com/j-hc)"
ui_print " by j-hc (github.com/j-hc)"
ui_print " "
11 changes: 6 additions & 5 deletions scripts/service.sh
@@ -1,13 +1,14 @@
#!/system/bin/sh
# shellcheck disable=SC2086
MODDIR=${0%/*}
until [ "$(getprop sys.boot_completed)" = 1 ]; do
sleep 1
done
RVPATH=/data/local/tmp/__PKGNAME_rv.apk
until [ "$(getprop sys.boot_completed)" = 1 ]; do sleep 1; done
sleep __MNTDLY

ln -f $MODDIR/base.apk $RVPATH
BASEPATH=$(pm path __PKGNAME | grep base)
BASEPATH=${BASEPATH#*:}
if [ "$BASEPATH" ]; then
chcon u:object_r:apk_data_file:s0 $MODDIR/base.apk
su -Mc mount -o bind $MODDIR/base.apk $BASEPATH
chcon u:object_r:apk_data_file:s0 $RVPATH
su -Mc mount -o bind $RVPATH $BASEPATH
fi
2 changes: 2 additions & 0 deletions scripts/uninstall.sh
@@ -0,0 +1,2 @@
#!/system/bin/sh
rm /data/local/tmp/__PKGNAME_rv.apk
28 changes: 16 additions & 12 deletions utils.sh
Expand Up @@ -16,6 +16,7 @@ WGET_HEADER="User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/2010010
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)
UNINSTALL_SH=$(cat $MODULE_SCRIPTS_DIR/uninstall.sh)

get_prebuilts() {
echo "Getting prebuilts"
Expand Down Expand Up @@ -45,7 +46,7 @@ get_cmpr() {
dl_if_dne "${MODULE_TEMPLATE_DIR}/bin/arm/cmpr" "https://github.com/j-hc/cmpr/releases/download/20220811/cmpr-armeabi-v7a"
}

abort() { echo "$1" && exit 1; }
abort() { echo "abort: $1" && exit 1; }

set_prebuilts() {
[ -d "$TEMP_DIR" ] || abort "${TEMP_DIR} directory could not be found"
Expand All @@ -64,6 +65,7 @@ reset_template() {
echo "# utils" >"${MODULE_TEMPLATE_DIR}/service.sh"
echo "# utils" >"${MODULE_TEMPLATE_DIR}/post-fs-data.sh"
echo "# utils" >"${MODULE_TEMPLATE_DIR}/customize.sh"
echo "# utils" >"${MODULE_TEMPLATE_DIR}/uninstall.sh"
echo "# utils" >"${MODULE_TEMPLATE_DIR}/module.prop"
rm -rf ${MODULE_TEMPLATE_DIR}/*.apk
mkdir -p ${MODULE_TEMPLATE_DIR}/bin/arm ${MODULE_TEMPLATE_DIR}/bin/arm64
Expand All @@ -90,6 +92,7 @@ dl_if_dne() {
fi
}

# if you are here to copy paste this piece of code, acknowledge it:)
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")"
Expand All @@ -110,7 +113,7 @@ zip_module() {
local patched_apk=$1 module_name=$2 stock_apk=$3 pkg_name=$4
cp -f "$patched_apk" "${MODULE_TEMPLATE_DIR}/base.apk"
cp -f "$stock_apk" "${MODULE_TEMPLATE_DIR}/${pkg_name}.apk"
cd "$MODULE_TEMPLATE_DIR" || exit 1
cd "$MODULE_TEMPLATE_DIR" || abort "Module template dir not found"
zip -9 -FSr "../${BUILD_DIR}/${module_name}" .
cd ..
}
Expand Down Expand Up @@ -155,12 +158,17 @@ build_rv() {
if [ $is_root = true ]; then
local output_dir="$TEMP_DIR"
# --unsigned is only available in my revanced-cli builds
args[patcher_args]="${args[patcher_args]} --unsigned --rip-lib arm64-v8a --rip-lib armeabi-v7a"
if [ "${args[rip_all_libs]}" = true ]; then
# native libraries are already extracted. remove them all to keep apks smol
args[patcher_args]="${args[patcher_args]} --unsigned --rip-lib arm64-v8a --rip-lib armeabi-v7a"
else
args[patcher_args]="${args[patcher_args]} --unsigned"
fi
else
local output_dir="$BUILD_DIR"
fi

version=$(select_ver "${args[pkg_name]}" "${args[apkmirror_category]}" $select_ver_experimental)
version=$(select_ver "${args[pkg_name]}" "${args[apkmirror_dlurl]##*/}" $select_ver_experimental)
echo "Choosing version '${version}'"

local stock_apk="${TEMP_DIR}/${args[app_name],,}-stock-v${version}-${args[arch]}.apk"
Expand All @@ -183,6 +191,7 @@ build_rv() {
return
fi

uninstall_sh "${args[pkg_name]}"
service_sh "${args[pkg_name]}"
postfsdata_sh "${args[pkg_name]}"
customize_sh "${args[pkg_name]}" "${version}"
Expand All @@ -203,8 +212,8 @@ build_yt() {
yt_args[app_name]="YouTube"
yt_args[is_module]=true
yt_args[patcher_args]="${YT_PATCHER_ARGS} -m ${RV_INTEGRATIONS_APK}"
yt_args[apkmirror_category]="youtube"
yt_args[arch]="all"
yt_args[rip_all_libs]=true
yt_args[pkg_name]="com.google.android.youtube"
yt_args[apkmirror_dlurl]="google-inc/youtube/youtube"
yt_args[regexp]="APK</span>[^@]*@\([^#]*\)"
Expand All @@ -221,8 +230,8 @@ build_music() {
ytmusic_args[app_name]="Music"
ytmusic_args[is_module]=true
ytmusic_args[patcher_args]="${MUSIC_PATCHER_ARGS}"
ytmusic_args[apkmirror_category]="youtube-music"
ytmusic_args[arch]=$arch
ytmusic_args[rip_all_libs]=false
ytmusic_args[pkg_name]="com.google.android.apps.youtube.music"
ytmusic_args[apkmirror_dlurl]="google-inc/youtube-music/youtube-music"
if [ "$arch" = "$ARM64_V8A" ]; then
Expand All @@ -243,7 +252,6 @@ build_twitter() {
tw_args[app_name]="Twitter"
tw_args[is_module]=false
tw_args[patcher_args]="-r"
tw_args[apkmirror_category]="twitter"
tw_args[arch]="all"
tw_args[pkg_name]="com.twitter.android"
tw_args[apkmirror_dlurl]="twitter-inc/twitter/twitter"
Expand All @@ -258,7 +266,6 @@ build_reddit() {
reddit_args[app_name]="Reddit"
reddit_args[is_module]=false
reddit_args[patcher_args]="-r"
reddit_args[apkmirror_category]="reddit"
reddit_args[arch]="all"
reddit_args[pkg_name]="com.reddit.frontpage"
reddit_args[apkmirror_dlurl]="redditinc/reddit/reddit"
Expand All @@ -273,7 +280,6 @@ build_warn_wetter() {
warn_wetter_args[app_name]="WarnWetter"
warn_wetter_args[is_module]=false
warn_wetter_args[patcher_args]="-r"
warn_wetter_args[apkmirror_category]="warnwetter"
warn_wetter_args[arch]="all"
warn_wetter_args[pkg_name]="de.dwd.warnapp"
warn_wetter_args[apkmirror_dlurl]="deutscher-wetterdienst/warnwetter/warnwetter"
Expand All @@ -288,7 +294,6 @@ build_tiktok() {
tiktok_args[app_name]="TikTok"
tiktok_args[is_module]=false
tiktok_args[patcher_args]="-r"
tiktok_args[apkmirror_category]="tik-tok-including-musical-ly"
tiktok_args[arch]="all"
tiktok_args[pkg_name]="com.zhiliaoapp.musically"
tiktok_args[apkmirror_dlurl]="tiktok-pte-ltd/tik-tok-including-musical-ly/tik-tok-including-musical-ly"
Expand All @@ -299,12 +304,11 @@ build_tiktok() {
}

postfsdata_sh() { echo "${POSTFSDATA_SH//__PKGNAME/$1}" >"${MODULE_TEMPLATE_DIR}/post-fs-data.sh"; }

uninstall_sh() { echo "${UNINSTALL_SH//__PKGNAME/$1}" >"${MODULE_TEMPLATE_DIR}/uninstall.sh"; }
service_sh() {
s="${SERVICE_SH//__MNTDLY/$MOUNT_DELAY}"
echo "${s//__PKGNAME/$1}" >"${MODULE_TEMPLATE_DIR}/service.sh"
}

customize_sh() {
s="${CUSTOMIZE_SH//__PKGNAME/$1}"
echo "${s//__MDVRSN/$2}" >"${MODULE_TEMPLATE_DIR}/customize.sh"
Expand Down

0 comments on commit bf309d3

Please sign in to comment.