Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 110 additions & 27 deletions common/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@
#
##########################################################################################

require_new_ksu() {
ui_print "**********************************"
ui_print " Please install KernelSU v0.6.6+! "
ui_print "**********************************"
exit 1
}

umount_mirrors() {
[ -d $ORIGDIR ] || return 0
for i in $ORIGDIR/*; do
umount -l $i 2>/dev/null
done
rm -rf $ORIGDIR 2>/dev/null
$KSU && mount -o ro,remount $MAGISKTMP
}

cleanup() {
rm -rf $MODPATH/common 2>/dev/null
if $KSU || [ $MAGISK_VER_CODE -ge 27000 ]; then umount_mirrors; fi
rm -rf $MODPATH/common $MODPATH/install.zip 2>/dev/null
}

abort() {
Expand Down Expand Up @@ -78,9 +95,16 @@ cp_ch() {

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;;
-b) shift;
if $KSU; then
local INPATH=$NVBASE/boot-completed.d
else
local INPATH=$SERVICED
sed -i -e '1i (\nwhile [ "$(getprop sys.boot_completed)" != "1" ]; do\n sleep 1\ndone\nsleep 3\n' -e '$a)&' $1
fi;;
-l) shift; local INPATH=$SERVICED;;
-p) shift; local INPATH=$POSTFSDATAD;;
*) local INPATH=$SERVICED;;
esac
[ "$(grep "#!/system/bin/sh" $1)" ] || sed -i "1i #!/system/bin/sh" $1
local i; for i in "MODPATH" "LIBDIR" "MODID" "INFO" "MODDIR"; do
Expand All @@ -90,9 +114,9 @@ install_script() {
*) 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) ;;
case $1 in
"$MODPATH/post-fs-data.sh"|"$MODPATH/service.sh"|"$MODPATH/uninstall.sh") sed -i "s|^MODPATH=.*|MODPATH=\$MODDIR|" $1;; # MODPATH=MODDIR for these scripts (located in module directory)
"$MODPATH/boot-completed.sh") $KSU && sed -i "s|^MODPATH=.*|MODPATH=\$MODDIR|" $1 || { cp_ch -n $1 $INPATH/$MODID-$(basename $1) 0755; rm -f $MODPATH/boot-completed.sh; };;
*) cp_ch -n $1 $INPATH/$(basename $1) 0755;;
esac
}
Expand All @@ -105,6 +129,23 @@ prop_process() {
done < $1
}

mount_mirrors() {
$KSU && mount -o rw,remount $MAGISKTMP
mkdir -p $ORIGDIR/system
if $SYSTEM_ROOT; then
mkdir -p $ORIGDIR/system_root
mount -o ro / $ORIGDIR/system_root
mount -o bind $ORIGDIR/system_root/system $ORIGDIR/system
else
mount -o ro /system $ORIGDIR/system
fi
for i in /vendor $PARTITIONS; do
[ ! -d $i -o -d $ORIGDIR$i ] && continue
mkdir -p $ORIGDIR$i
mount -o ro $i $ORIGDIR$i
done
}

# Credits
ui_print "**************************************"
ui_print "* MMT Extended by Zackptg5 @ XDA *"
Expand All @@ -115,20 +156,60 @@ ui_print " "
[ -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!"; }

# Min KSU v0.6.6
[ -z $KSU ] && KSU=false
$KSU && { [ $KSU_VER_CODE -lt 11184 ] && require_new_ksu; }
# APatch is fork of KSU, treat same
[ -z $APATCH ] && APATCH=false
[ "$APATCH" == "true" ] && KSU=true

# Start debug
set -x

# Set variables
[ -z $ARCH32 ] && ARCH32="$(echo $ABI32 | cut -c-3)"
[ $API -lt 26 ] && DYNLIB=false
[ -z $DYNLIB ] && DYNLIB=false
[ -z $DEBUG ] && DEBUG=false
[ -z $PARTOVER ] && PARTOVER=false
[ -z $SYSTEM_ROOT ] && SYSTEM_ROOT=$SYSTEM_AS_ROOT # renamed in magisk v26.3
[ -z $NVBASE ] && NVBASE="/data/adb" # removed in magisk v28
[ -z $SERVICED ] && SERVICED=$NVBASE/service.d # removed in magisk v26.2
[ -z $POSTFSDATAD ] && POSTFSDATAD=$NVBASE/post-fs-data.d # removed in magisk v26.2
INFO=$NVBASE/modules/.$MODID-files
ORIGDIR="$MAGISKTMP/mirror"
if $KSU; then
MAGISKTMP="/mnt"
ORIGDIR="$MAGISKTMP/mirror"
mount_mirrors
elif [ "$(magisk --path 2>/dev/null)" ]; then
if [ $MAGISK_VER_CODE -ge 27000 ]; then # Atomic Mount
if [ -z $MAGISKTMP ]; then
[ -d /sbin ] && MAGISKTMP=/sbin || MAGISKTMP=/debug_ramdisk
fi
ORIGDIR="$MAGISKTMP/mirror"
mount_mirrors
else
ORIGDIR="$(magisk --path 2>/dev/null)/.magisk/mirror"
fi
elif [ "$(echo $MAGISKTMP | awk -F/ '{ print $NF}')" == ".magisk" ]; then
ORIGDIR="$MAGISKTMP/mirror"
else
ORIGDIR="$MAGISKTMP/.magisk/mirror"
fi
if $DYNLIB; then
LIBPATCH="\/vendor"
LIBDIR=/system/vendor
else
LIBPATCH="\/system"
LIBDIR=/system
fi
# Detect extra partition compatibility (KernelSU or Magisk Delta/Kitsune)
EXTRAPART=false
if $KSU || [ "$(echo $MAGISK_VER | awk -F- '{ print $NF}')" == "delta" ] || [ "$(echo $MAGISK_VER | awk -F- '{ print $NF}')" == "kitsune" ]; then
EXTRAPART=true
elif ! $PARTOVER; then
unset PARTITIONS
fi

if ! $BOOTMODE; then
ui_print "- Only uninstall is supported in recovery"
ui_print " Uninstalling!"
Expand All @@ -140,14 +221,6 @@ if ! $BOOTMODE; then
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
Expand Down Expand Up @@ -192,9 +265,15 @@ ui_print " Installing for $ARCH SDK $API device..."
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/boot-completed.sh") install_script -b $i;;
"$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
"$MODPATH/uninstall.sh") if [ -s $INFO ] || [ "$(head -n1 $MODPATH/uninstall.sh)" != "# Don't modify anything after this" ]; then
cp -f $MODPATH/uninstall.sh $MODPATH/$MODID-uninstall.sh # Fallback script in case module manually deleted
sed -i "1i[ -d \"\$MODPATH\" ] && exit 0" $MODPATH/$MODID-uninstall.sh
echo 'rm -f $0' >> $MODPATH/$MODID-uninstall.sh
install_script -l $MODPATH/$MODID-uninstall.sh
rm -f $MODPATH/$MODID-uninstall.sh
install_script $MODPATH/uninstall.sh
else
rm -f $INFO $MODPATH/uninstall.sh
Expand Down Expand Up @@ -223,15 +302,19 @@ fi
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
for i in /system/vendor /vendor /system/vendor/app /vendor/app /system/vendor/etc /vendor/etc /system/odm/etc /odm/etc /system/vendor/odm/etc /vendor/odm/etc /system/vendor/overlay /vendor/overlay; do
if [ -d "$MODPATH$i" ] && [ ! -L "$MODPATH$i" ]; then
case $i in
*"/vendor") set_perm_recursive $MODPATH$i 0 0 0755 0644 u:object_r:vendor_file:s0;;
*"/app") set_perm_recursive $MODPATH$i 0 0 0755 0644 u:object_r:vendor_app_file:s0;;
*"/overlay") set_perm_recursive $MODPATH$i 0 0 0755 0644 u:object_r:vendor_overlay_file:s0;;
*"/etc") set_perm_recursive $MODPATH$i 0 2000 0755 0644 u:object_r:vendor_configs_file:s0;;
esac
fi
done
for i in $(find $MODPATH/system/vendor $MODPATH/vendor -type f -name *".apk" 2>/dev/null); do
chcon u:object_r:vendor_app_file:s0 $i
done
set_permissions

# Complete install
Expand Down
10 changes: 5 additions & 5 deletions common/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ POLS="$(find /system /vendor -type f -name "*audio_*policy*.conf" -o -name "*aud
UPCS="$(find /system /vendor -type f -name "usb_audio_policy_configuration.xml")"
APS="$(find /system /vendor -type f -name "*audio_*policy*.conf")"
CFGS="$(find /system /vendor -type f -name "*audio_effects*.conf" -o -name "*audio_effects*.xml")"
if [ -d "$NVBASE/modules/nhr" ]; then
if [ -d "/data/adb/modules/nhr" ]; then
ui_print " "
ui_print "! Old Notification Helper Remover detected! Removing..."
touch $NVBASE/modules/nhr/remove
touch /data/adb/modules/nhr/remove
fi
if [ -d "$NVBASE/modules/upp" ]; then
if [ -d "/data/adb/modules/upp" ]; then
ui_print " "
ui_print "! Old USB Policy Patcher detected! Removing..."
touch $NVBASE/modules/upp/remove
touch /data/adb/modules/upp/remove
fi

# Tell user aml is needed if applicable
FILES=$(find $NVBASE/modules/*/system $MODULEROOT/*/system -type f -name "usb_audio_policy_configuration.xml" -o -name "*audio_*policy*.conf" -o -name "*audio_effects*.conf" -o -name "*audio_effects*.xml" 2>/dev/null)
FILES=$(find /data/adb/modules/*/system $MODULEROOT/*/system -type f -name "usb_audio_policy_configuration.xml" -o -name "*audio_*policy*.conf" -o -name "*audio_effects*.conf" -o -name "*audio_effects*.xml" 2>/dev/null)
if [ ! -z "$FILES" ] && [ ! "$(echo $FILES | grep '/aml/')" ]; then
ui_print " "
ui_print " ! Conflicting audio mod found!"
Expand Down