update template stuff

This commit is contained in:
j-hc 2022-07-24 17:20:45 +03:00
parent 1c2d14b145
commit 52270c20d9
No known key found for this signature in database
GPG Key ID: 242B44D16774A2ED
4 changed files with 72 additions and 88 deletions

View File

@ -1,8 +1,4 @@
########################################################################################## # MMT Extended functions (all credits goes to Zackptg5)
#
# MMT Extended Utility Functions
#
##########################################################################################
cleanup() { cleanup() {
rm -rf $MODPATH/common 2>/dev/null rm -rf $MODPATH/common 2>/dev/null
@ -17,14 +13,23 @@ abort() {
} }
device_check() { device_check() {
local opt=`getopt -o dm -- "$@"` type=device local opt=$(getopt -o dm -- "$@") type=device
eval set -- "$opt" eval set -- "$opt"
while true; do while true; do
case "$1" in case "$1" in
-d) local type=device; shift;; -d)
-m) local type=manufacturer; shift;; local type=device
--) shift; break;; shift
*) abort "Invalid device_check argument $1! Aborting!";; ;;
-m)
local type=manufacturer
shift
;;
--)
shift
break
;;
*) abort "Invalid device_check argument $1! Aborting!" ;;
esac esac
done done
local prop=$(echo "$1" | tr '[:upper:]' '[:lower:]') local prop=$(echo "$1" | tr '[:upper:]' '[:lower:]')
@ -40,21 +45,30 @@ device_check() {
} }
cp_ch() { cp_ch() {
local opt=`getopt -o nr -- "$@"` BAK=true UBAK=true FOL=false local opt=$(getopt -o nr -- "$@") BAK=true UBAK=true FOL=false
eval set -- "$opt" eval set -- "$opt"
while true; do while true; do
case "$1" in case "$1" in
-n) UBAK=false; shift;; -n)
-r) FOL=true; shift;; UBAK=false
--) shift; break;; shift
*) abort "Invalid cp_ch argument $1! Aborting!";; ;;
-r)
FOL=true
shift
;;
--)
shift
break
;;
*) abort "Invalid cp_ch argument $1! Aborting!" ;;
esac esac
done done
local SRC="$1" DEST="$2" OFILES="$1" local SRC="$1" DEST="$2" OFILES="$1"
$FOL && local OFILES=$(find $SRC -type f 2>/dev/null) $FOL && local OFILES=$(find $SRC -type f 2>/dev/null)
[ -z $3 ] && PERM=0644 || PERM=$3 [ -z $3 ] && PERM=0644 || PERM=$3
case "$DEST" in case "$DEST" in
$TMPDIR/*|$MODULEROOT/*|$NVBASE/modules/$MODID/*) BAK=false;; $TMPDIR/* | $MODULEROOT/* | $NVBASE/modules/$MODID/*) BAK=false ;;
esac esac
for OFILE in ${OFILES}; do for OFILE in ${OFILES}; do
if $FOL; then if $FOL; then
@ -67,10 +81,13 @@ cp_ch() {
[ -d "$DEST" ] && local FILE="$DEST/$(basename $SRC)" || local FILE="$DEST" [ -d "$DEST" ] && local FILE="$DEST/$(basename $SRC)" || local FILE="$DEST"
fi fi
if $BAK && $UBAK; then if $BAK && $UBAK; then
[ ! "$(grep "$FILE$" $INFO 2>/dev/null)" ] && echo "$FILE" >> $INFO [ ! "$(grep "$FILE$" $INFO 2>/dev/null)" ] && echo "$FILE" >>$INFO
[ -f "$FILE" -a ! -f "$FILE~" ] && { mv -f $FILE $FILE~; echo "$FILE~" >> $INFO; } [ -f "$FILE" -a ! -f "$FILE~" ] && {
mv -f $FILE $FILE~
echo "$FILE~" >>$INFO
}
elif $BAK; then elif $BAK; then
[ ! "$(grep "$FILE$" $INFO 2>/dev/null)" ] && echo "$FILE" >> $INFO [ ! "$(grep "$FILE$" $INFO 2>/dev/null)" ] && echo "$FILE" >>$INFO
fi fi
install -D -m $PERM "$OFILE" "$FILE" install -D -m $PERM "$OFILE" "$FILE"
done done
@ -78,22 +95,29 @@ cp_ch() {
install_script() { install_script() {
case "$1" in case "$1" in
-l) shift; local INPATH=$NVBASE/service.d;; -l)
-p) shift; local INPATH=$NVBASE/post-fs-data.d;; shift
*) local INPATH=$NVBASE/service.d;; local INPATH=$NVBASE/service.d
;;
-p)
shift
local INPATH=$NVBASE/post-fs-data.d
;;
*) local INPATH=$NVBASE/service.d ;;
esac esac
[ "$(grep "#!/system/bin/sh" $1)" ] || sed -i "1i #!/system/bin/sh" $1 [ "$(grep "#!/system/bin/sh" $1)" ] || sed -i "1i #!/system/bin/sh" $1
local i; for i in "MODPATH" "LIBDIR" "MODID" "INFO" "MODDIR"; do local i
for i in "MODPATH" "LIBDIR" "MODID" "INFO" "MODDIR"; do
case $i in case $i in
"MODPATH") sed -i "1a $i=$NVBASE/modules/$MODID" $1;; "MODPATH") sed -i "1a $i=$NVBASE/modules/$MODID" $1 ;;
"MODDIR") sed -i "1a $i=\${0%/*}" $1;; "MODDIR") sed -i "1a $i=\${0%/*}" $1 ;;
*) sed -i "1a $i=$(eval echo \$$i)" $1;; *) sed -i "1a $i=$(eval echo \$$i)" $1 ;;
esac esac
done done
[ "$1" == "$MODPATH/uninstall.sh" ] && return 0 [ "$1" == "$MODPATH/uninstall.sh" ] && return 0
case $(basename $1) in case $(basename $1) in
post-fs-data.sh|service.sh) ;; post-fs-data.sh | service.sh) ;;
*) cp_ch -n $1 $INPATH/$(basename $1) 0755;; *) cp_ch -n $1 $INPATH/$(basename $1) 0755 ;;
esac esac
} }
@ -101,16 +125,10 @@ prop_process() {
sed -i -e "/^#/d" -e "/^ *$/d" $1 sed -i -e "/^#/d" -e "/^ *$/d" $1
[ -f $MODPATH/system.prop ] || mktouch $MODPATH/system.prop [ -f $MODPATH/system.prop ] || mktouch $MODPATH/system.prop
while read LINE; do while read LINE; do
echo "$LINE" >> $MODPATH/system.prop echo "$LINE" >>$MODPATH/system.prop
done < $1 done <$1
} }
# Credits
ui_print "**************************************"
ui_print "* MMT Extended by Zackptg5 @ XDA *"
ui_print "**************************************"
ui_print " "
# Check for min/max api version # 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 $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!"; } [ -z $MAXAPI ] || { [ $API -gt $MAXAPI ] && abort "! Your system API of $API is greater than the maximum api of $MAXAPI! Aborting!"; }
@ -155,7 +173,8 @@ unzip -o "$ZIPFILE" -x 'META-INF/*' 'common/functions.sh' -d $MODPATH >&2
# Run addons # Run addons
if [ "$(ls -A $MODPATH/common/addon/*/install.sh 2>/dev/null)" ]; then if [ "$(ls -A $MODPATH/common/addon/*/install.sh 2>/dev/null)" ]; then
ui_print " "; ui_print "- Running Addons -" ui_print " "
ui_print "- Running Addons -"
for i in $MODPATH/common/addon/*/install.sh; do for i in $MODPATH/common/addon/*/install.sh; do
ui_print " Running $(echo $i | sed -r "s|$MODPATH/common/addon/(.*)/install.sh|\1|")..." ui_print " Running $(echo $i | sed -r "s|$MODPATH/common/addon/(.*)/install.sh|\1|")..."
. $i . $i
@ -178,7 +197,7 @@ if [ -f $INFO ]; then
[ "$(ls -A $LINE 2>/dev/null)" ] && break 1 || rm -rf $LINE [ "$(ls -A $LINE 2>/dev/null)" ] && break 1 || rm -rf $LINE
done done
fi fi
done < $INFO done <$INFO
rm -f $INFO rm -f $INFO
fi fi
@ -190,30 +209,33 @@ ui_print "- Installing"
ui_print " Installing for $ARCH SDK $API device..." ui_print " Installing for $ARCH SDK $API device..."
# Remove comments from files and place them, add blank line to end if not already present # 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 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 [ -f $i ] && {
sed -i -e "/^#/d" -e "/^ *$/d" $i
[ "$(tail -1 $i)" ] && echo "" >>$i
} || continue
case $i in case $i in
"$MODPATH/service.sh") install_script -l $i;; "$MODPATH/service.sh") install_script -l $i ;;
"$MODPATH/post-fs-data.sh") install_script -p $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
install_script $MODPATH/uninstall.sh install_script $MODPATH/uninstall.sh
else else
rm -f $INFO $MODPATH/uninstall.sh rm -f $INFO $MODPATH/uninstall.sh
fi;; fi ;;
esac esac
done done
$IS64BIT || for i in $(find $MODPATH/system -type d -name "lib64"); do rm -rf $i 2>/dev/null; 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/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 [ -d "/system/xbin" ] || mv -f $MODPATH/system/xbin $MODPATH/system/bin 2>/dev/null
if $DYNLIB; then if $DYNLIB; then
for FILE in $(find $MODPATH/system/lib* -type f 2>/dev/null | sed "s|$MODPATH/system/||"); do for FILE in $(find $MODPATH/system/lib* -type f 2>/dev/null | sed "s|$MODPATH/system/||"); do
[ -s $MODPATH/system/$FILE ] || continue [ -s $MODPATH/system/$FILE ] || continue
case $FILE in case $FILE in
lib*/modules/*) continue;; lib*/modules/*) continue ;;
esac esac
mkdir -p $(dirname $MODPATH/system/vendor/$FILE) mkdir -p $(dirname $MODPATH/system/vendor/$FILE)
mv -f $MODPATH/system/$FILE $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` [ "$(ls -A $(dirname $MODPATH/system/$FILE))" ] || rm -rf $(dirname $MODPATH/system/$FILE)
done done
# Delete empty lib folders (busybox find doesn't have this capability) # Delete empty lib folders (busybox find doesn't have this capability)
toybox find $MODPATH/system/lib* -type d -empty -delete >/dev/null 2>&1 toybox find $MODPATH/system/lib* -type d -empty -delete >/dev/null 2>&1

View File

@ -1 +0,0 @@
# utils

View File

@ -1,48 +1,12 @@
##########################################################################################
#
# 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 MINAPI=21
#MAXAPI=25 #MAXAPI=25
#DYNLIB=true #DYNLIB=true
#DEBUG=true #DEBUG=true
##########################################################################################
# Permissions
##########################################################################################
set_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 <dirname> <owner> <group> <dirpermission> <filepermission> <contexts> (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 <filename> <owner> <group> <permission> <contexts> (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
} }
##########################################################################################
# MMT Extended Logic - Don't modify anything after this
##########################################################################################
SKIPUNZIP=1 SKIPUNZIP=1
unzip -qjo "$ZIPFILE" 'common/functions.sh' -d $TMPDIR >&2 unzip -qjo "$ZIPFILE" 'common/functions.sh' -d $TMPDIR >&2
. $TMPDIR/functions.sh . $TMPDIR/functions.sh

View File

@ -45,7 +45,6 @@ set_prebuilts() {
} }
reset_template() { reset_template() {
echo "# utils" >"${MODULE_TEMPLATE_DIR}/common/install.sh"
echo "# utils" >"${MODULE_TEMPLATE_DIR}/service.sh" echo "# utils" >"${MODULE_TEMPLATE_DIR}/service.sh"
echo "# utils" >"${MODULE_TEMPLATE_DIR}/module.prop" echo "# utils" >"${MODULE_TEMPLATE_DIR}/module.prop"
rm -f "${MODULE_TEMPLATE_DIR}/base.apk" rm -f "${MODULE_TEMPLATE_DIR}/base.apk"