From 58f8d484cf67360cf9ebdef5cb89b6ce52cf9e41 Mon Sep 17 00:00:00 2001 From: Lup Gabriel Date: Mon, 3 Apr 2023 19:47:15 +0300 Subject: [PATCH] init --- META-INF/com/google/android/update-binary | 33 +++ META-INF/com/google/android/updater-script | 1 + common/functions.sh | 232 +++++++++++++++++++++ common/install.sh | 0 customize.sh | 71 +++++++ module.prop | 6 + service.sh | 2 + system/etc/mglru-checker-loop.sh | 12 ++ uninstall.sh | 17 ++ 9 files changed, 374 insertions(+) create mode 100755 META-INF/com/google/android/update-binary create mode 100755 META-INF/com/google/android/updater-script create mode 100755 common/functions.sh create mode 100755 common/install.sh create mode 100755 customize.sh create mode 100755 module.prop create mode 100755 service.sh create mode 100755 system/etc/mglru-checker-loop.sh create mode 100755 uninstall.sh diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary new file mode 100755 index 0000000..ea4889e --- /dev/null +++ b/META-INF/com/google/android/update-binary @@ -0,0 +1,33 @@ +#!/sbin/sh + +################# +# Initialization +################# + +umask 022 + +# echo before loading util_functions +ui_print() { echo "$1"; } + +require_new_magisk() { + ui_print "*******************************" + ui_print " Please install Magisk v20.4+! " + ui_print "*******************************" + exit 1 +} + +######################### +# Load util_functions.sh +######################### + +OUTFD=$2 +ZIPFILE=$3 + +mount /data 2>/dev/null + +[ -f /data/adb/magisk/util_functions.sh ] || require_new_magisk +. /data/adb/magisk/util_functions.sh +[ $MAGISK_VER_CODE -lt 20400 ] && require_new_magisk + +install_module +exit 0 \ No newline at end of file diff --git a/META-INF/com/google/android/updater-script b/META-INF/com/google/android/updater-script new file mode 100755 index 0000000..11d5c96 --- /dev/null +++ b/META-INF/com/google/android/updater-script @@ -0,0 +1 @@ +#MAGISK diff --git a/common/functions.sh b/common/functions.sh new file mode 100755 index 0000000..6b86218 --- /dev/null +++ b/common/functions.sh @@ -0,0 +1,232 @@ +########################################################################################## +# +# MMT Extended Utility Functions +# +########################################################################################## + +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" "LIBDIR" "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)" +[ $API -lt 26 ] && DYNLIB=false +[ -z $DYNLIB ] && DYNLIB=false +[ -z $DEBUG ] && DEBUG=false +INFO=$NVBASE/modules/.$MODID-files +ORIGDIR="$MAGISKTMP/mirror" +if $DYNLIB; then + LIBPATCH="\/vendor" + LIBDIR=/system/vendor +else + LIBPATCH="\/system" + LIBDIR=/system +fi +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 +if $DYNLIB; then + for FILE in $(find $MODPATH/system/lib* -type f 2>/dev/null | sed "s|$MODPATH/system/||"); do + [ -s $MODPATH/system/$FILE ] || continue + case $FILE in + lib*/modules/*) continue;; + esac + mkdir -p $(dirname $MODPATH/system/vendor/$FILE) + mv -f $MODPATH/system/$FILE $MODPATH/system/vendor/$FILE + [ "$(ls -A `dirname $MODPATH/system/$FILE`)" ] || rm -rf `dirname $MODPATH/system/$FILE` + done + # Delete empty lib folders (busybox find doesn't have this capability) + toybox find $MODPATH/system/lib* -type d -empty -delete >/dev/null 2>&1 +fi + +# 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 diff --git a/common/install.sh b/common/install.sh new file mode 100755 index 0000000..e69de29 diff --git a/customize.sh b/customize.sh new file mode 100755 index 0000000..73dcb77 --- /dev/null +++ b/customize.sh @@ -0,0 +1,71 @@ +########################################################################################## +# +# MMT Extended Config Script +# +########################################################################################## + +########################################################################################## +# Config Flags +########################################################################################## + +# Uncomment and change 'MINAPI' and 'MAXAPI' to the minimum and maximum android version for your mod +# Uncomment DYNLIB if you want libs installed to vendor for oreo+ and system for anything older +# Uncomment DEBUG if you want full debug logs (saved to /sdcard) +#MINAPI=21 +#MAXAPI=25 +#DYNLIB=true +#DEBUG=true + +########################################################################################## +# Replace list +########################################################################################## + +# List all directories you want to directly replace in the system +# Check the documentations for more info why you would need this + +# Construct your list in the following format +# This is an example +REPLACE_EXAMPLE=" +/system/app/Youtube +/system/priv-app/SystemUI +/system/priv-app/Settings +/system/framework +" + +# Construct your own list here +REPLACE=" +" + +########################################################################################## +# Permissions +########################################################################################## + +set_permissions() { + : # Remove this if adding to this function + + # Note that all files/folders in magisk module directory have the $MODPATH prefix - keep this prefix on all of your files/folders + # Some examples: + + # For directories (includes files in them): + # set_perm_recursive (default: u:object_r:system_file:s0) + + # set_perm_recursive $MODPATH/system/lib 0 0 0755 0644 + # set_perm_recursive $MODPATH/system/vendor/lib/soundfx 0 0 0755 0644 + + # For files (not in directories taken care of above) + # set_perm (default: u:object_r:system_file:s0) + + # set_perm $MODPATH/system/lib/libart.so 0 0 0644 + # set_perm /data/local/tmp/file.txt 0 0 644 + + chmod +x $MODPATH/system/etc/mglru-checker-loop.sh + chmod +x $MODPATH/service.sh +} + +########################################################################################## +# MMT Extended Logic - Don't modify anything after this +########################################################################################## + +SKIPUNZIP=1 +unzip -qjo "$ZIPFILE" 'common/functions.sh' -d $TMPDIR >&2 +. $TMPDIR/functions.sh diff --git a/module.prop b/module.prop new file mode 100755 index 0000000..9f45fbd --- /dev/null +++ b/module.prop @@ -0,0 +1,6 @@ +id=mglru-disable +name=MGLRU Disabler +version=4.0 +versionCode=4 +author=gwolfu +description=Checks every 30 seconds the status of MGLRU feature and disables it if enabled (prevent system hang on Nothing OS 1.5.3+) diff --git a/service.sh b/service.sh new file mode 100755 index 0000000..1965ff8 --- /dev/null +++ b/service.sh @@ -0,0 +1,2 @@ +#!/system/bin/sh +./system/etc/mglru-checker-loop.sh diff --git a/system/etc/mglru-checker-loop.sh b/system/etc/mglru-checker-loop.sh new file mode 100755 index 0000000..6ad8839 --- /dev/null +++ b/system/etc/mglru-checker-loop.sh @@ -0,0 +1,12 @@ +#!/system/bin/sh + +while true +do + mglru_enabled=$(cat /sys/kernel/mm/lru_gen/enabled) + + if [ "$mglru_enabled" != "0x0000" ]; then + resetprop persist.sys.mglru_enable false + fi + + sleep 30 +done diff --git a/uninstall.sh b/uninstall.sh new file mode 100755 index 0000000..0b410f7 --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,17 @@ +# 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