Last active
October 14, 2024 06:27
-
-
Save xymopen/642f847f34f6990e32b5be6652b2bcec to your computer and use it in GitHub Desktop.
Shell implemented mounting app of ReVanced Manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/data/adb/magisk/busybox ash | |
# shellcheck shell=ash | |
# @see https://github.com/ReVanced/revanced-manager/blob/main/lib/services/root_api.dart | |
REVANCED_PATH="/data/adb/revanced" | |
SERVICE_D_PATH="/data/adb/service.d" | |
main () { | |
local packageName="$1" | |
if [ -z "$packageName" ]; then | |
echo "Usage: dismount <PACKAGE NAME>" >&2 | |
elif ! pm path "$packageName" >&-; then | |
echo "ERROR: $packageName is not installed" >&2 | |
else | |
grep "$packageName" /proc/mounts | while read -r line; do | |
echo $line | cut -d " " -f 2 | sed "s/apk.*/apk/" | xargs -r umount -l; | |
done | |
rm -rf "$REVANCED_PATH/$packageName" "$SERVICE_D_PATH/$packageName.sh" | |
fi | |
} | |
main "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/data/adb/magisk/busybox ash | |
# shellcheck shell=ash | |
# @see https://github.com/ReVanced/revanced-manager/blob/main/lib/services/root_api.dart | |
REVANCED_PATH="/data/adb/revanced" | |
SERVICE_D_PATH="/data/adb/service.d" | |
main () { | |
local packageName="$1" | |
local patchedFilePath="$2" | |
if [ -z "$packageName" ] || [ -z "$patchedFilePath" ]; then | |
echo "Usage: mount <PACKAGE_NAME> <PATCHED_FILE_PATH>" >&2 | |
elif ! pm path "$packageName" >&-; then | |
echo "ERROR: $packageName is not installed" >&2 | |
elif [ ! -f "$patchedFilePath" ]; then | |
echo "ERROR: $patchedFilePath is not found" >&2 | |
else | |
local newPatchedFilePath="$REVANCED_PATH/$packageName/base.apk" | |
mkdir -p $REVANCED_PATH/$packageName | |
chmod 0755 $REVANCED_PATH/$packageName | |
chown shell:shell $REVANCED_PATH/$packageName | |
cp "$patchedFilePath" "$newPatchedFilePath" | |
chmod 0644 "$newPatchedFilePath" | |
chown system:system "$newPatchedFilePath" | |
chcon u:object_r:apk_data_file:s0 "$newPatchedFilePath" | |
mkdir -p $SERVICE_D_PATH | |
local scriptFilePath="$SERVICE_D_PATH/$packageName.sh" | |
cat > "$scriptFilePath" <<- EOF | |
#!/sbin/busybox ash | |
# Mount using Magisk mirror, if available. | |
MAGISKTMP="\$(magisk --path)" || MAGISKTMP=/sbin | |
MIRROR="\$MAGISKTMP/.magisk/mirror" | |
if [ ! -f "\$MIRROR" ]; then | |
MIRROR="" | |
fi | |
until [ "\$(getprop sys.boot_completed)" = 1 ]; do | |
sleep 3; | |
done | |
until [ -d "/sdcard/Android" ]; do | |
sleep 1; | |
done | |
# Unmount any existing installation to prevent multiple unnecessary mounts. | |
grep "$packageName" /proc/mounts | while read -r line; do | |
echo "\$line" | cut -d " " -f 2 | sed "s/apk.*/apk/" | xargs -r umount -l; | |
done | |
base_path=$REVANCED_PATH/$packageName/base.apk | |
stock_path=\$(pm path "$packageName" | grep base | sed "s/package://g" ) | |
chcon u:object_r:apk_data_file:s0 "\$base_path" | |
mount -o bind "\$MIRROR\$base_path" "\$stock_path" | |
# Kill the app to force it to restart the mounted APK in case it is already running | |
am force-stop "$packageName" | |
EOF | |
chmod 0744 "$scriptFilePath" | |
. "$SERVICE_D_PATH/$packageName.sh" | |
fi | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment