Skip to content

Commit

Permalink
Final FSCC bringup
Browse files Browse the repository at this point in the history
Signed-off-by: Pedrozzz0 <[email protected]>
  • Loading branch information
pedrozzz0 committed Aug 14, 2022
1 parent 800e6a4 commit a4ba4c8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 156 deletions.
143 changes: 14 additions & 129 deletions META-INF/com/google/android/update-binary
Original file line number Diff line number Diff line change
@@ -1,149 +1,34 @@
#!/sbin/sh

TMPDIR="/dev/tmp"
MOUNTPATH="/dev/magisk_img"
#################
# Initialization
#################

# Default permissions
umask 022

# Initial cleanup
rm -rf "$TMPDIR" 2>/dev/null
mkdir -p "$TMPDIR"

# echo before loading util_functions
ui_print() { echo "$1"; }

require_new_magisk() {
ui_print "*******************************"
ui_print " Please install latest Magisk! "
ui_print "*******************************"
exit 1
}

imageless_magisk() {
[[ "$MAGISK_VER_CODE" -gt "18100" ]]
return $?
ui_print "*******************************"
ui_print " Please install Magisk v20.4+! "
ui_print "*******************************"
exit 1
}

##########################################################################################
# Environment
##########################################################################################
#########################
# Load util_functions.sh
#########################

OUTFD=$2
ZIPFILE=$3

mount /data 2>/dev/null

# Load utility functions
[[ -f /data/adb/magisk/util_functions.sh ]] && {
. /data/adb/magisk/util_functions.sh
NVBASE=/data/adb
} || require_new_magisk

# Preperation for flashable zips
setup_flashable

# Mount partitions
mount_partitions

# Detect version and architecture
api_level_arch_detect

# Setup busybox and binaries
"$BOOTMODE" && boot_actions || recovery_actions

##########################################################################################
# Preparation
##########################################################################################

# Extract common files
unzip -oj "$ZIPFILE" module.prop install.sh uninstall.sh 'common/*' -d "$TMPDIR" >&2

[[ ! -f "$TMPDIR/install.sh" ]] && abort "! Unable to extract zip file!"
# Load install script
. "$TMPDIR/install.sh"

if imageless_magisk; then
"$BOOTMODE" && MODDIRNAME=modules_update || MODDIRNAME=modules
MODULEROOT="$NVBASE/$MODDIRNAME"
else
"$BOOTMODE" && IMGNAME=magisk_merge.img || IMGNAME=magisk.img
IMG="$NVBASE/$IMGNAME"
request_zip_size_check "$ZIPFILE"
mount_magisk_img
MODULEROOT=$MOUNTPATH
fi

MODID=$(grep_prop id "$TMPDIR/module.prop")
MODPATH="$MODULEROOT/$MODID"

print_modname

ui_print "******************************"
ui_print "Powered by Magisk (@topjohnwu)"
ui_print "******************************"

##########################################################################################
# Install
##########################################################################################

# Create mod paths
rm -rf "$MODPATH" 2>/dev/null
mkdir -p "$MODPATH"

on_install

# Remove placeholder
rm -f "$MODPATH/system/placeholder" 2>/dev/null

# Custom uninstaller
[[ -f "$TMPDIR/uninstall.sh" ]] && cp -af "$TMPDIR/uninstall.sh" "$MODPATH/uninstall.sh"

# Auto Mount
if imageless_magisk; then
"$SKIPMOUNT" && touch "$MODPATH/skip_mount"
else
"$SKIPMOUNT" || touch "$MODPATH/auto_mount"
fi

# prop files
"$PROPFILE" && cp -af "$TMPDIR/system.prop" "$MODPATH/system.prop"

# Module info
cp -af "$TMPDIR/module.prop" "$MODPATH/module.prop"
if "$BOOTMODE"; then
# Update info for Magisk Manager
if imageless_magisk; then
mktouch "$NVBASE/modules/$MODID/update"
cp -af "$TMPDIR/module.prop" "$NVBASE/modules/$MODID/module.prop"
else
mktouch "/sbin/.magisk/img/$MODID/update"
cp -af "$TMPDIR/module.prop" "/sbin/.magisk/img/$MODID/module.prop"
fi
fi

# post-fs-data mode scripts
"$POSTFSDATA" && cp -af "$TMPDIR/post-fs-data.sh" "$MODPATH/post-fs-data.sh"

# service mode scripts
"$LATESTARTSERVICE" && cp -af "$TMPDIR/service.sh" "$MODPATH/service.sh"

# Handle replace folders
for TARGET in "$REPLACE"; do
mktouch "$MODPATH$TARGET/.replace"
done

ui_print "- Setting permissions"
set_permissions

##########################################################################################
# Finalizing
##########################################################################################
[[ -f "/data/adb/magisk/util_functions.sh" ]] || require_new_magisk
. /data/adb/magisk/util_functions.sh

cd /
imageless_magisk || unmount_magisk_img
$BOOTMODE || recovery_cleanup
rm -rf "$TMPDIR" "$MOUNTPATH"
[[ "$MAGISK_VER_CODE" -lt "20400" ]] && require_new_magisk

ui_print "- Done"
install_module
exit 0
52 changes: 26 additions & 26 deletions common/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ device_check() {
done
prop=$(echo "$1" | tr '[:upper:]' '[:lower:]')
for i in /system /vendor /odm /product; do
[[ -f "$i"/build.prop ]] && {
[[ -f "$i/build.prop" ]] && {
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
[[ "$type" == "device" ]] && [[ "$(sed -n "s/^"ro.build.product"=//p" "$i/build.prop" 2>/dev/null | head -n 1 | tr '[:upper:]' '[:lower:]')" == "$prop" ]] && return 0
}
done
}
Expand Down Expand Up @@ -73,7 +73,7 @@ cp_ch() {
"$FOL" && OFILES=$(find "$SRC" -type f 2>/dev/null)
[[ -z "$3" ]] && PERM=0644 || PERM="$3"
case "$DEST" in
$TMPDIR/* | $MODULEROOT/* | $NVBASE/modules/$MODID/*) BAK=false ;;
"$TMPDIR"/* | "$MODULEROOT"/* | "$NVBASE/modules/$MODID"/*) BAK=false ;;
esac
for OFILE in "$OFILES"; do
"$FOL" && {
Expand All @@ -94,13 +94,13 @@ install_script() {
case "$1" in
-l)
shift
INPATH="$NVBASE"/service.d
INPATH="$NVBASE/service.d"
;;
-p)
shift
INPATH="$NVBASE"/post-fs-data.d
INPATH="$NVBASE/post-fs-data.d"
;;
*) INPATH="$NVBASE"/service.d ;;
*) INPATH="$NVBASE/service.d" ;;
esac
[[ "$(grep "#!/system/bin/sh" "$1")" ]] || sed -i "1i #!/system/bin/sh" "$1"
for i in "MODPATH" "LIBDIR" "MODID" "INFO" "MODDIR"; do
Expand All @@ -119,23 +119,23 @@ install_script() {

prop_process() {
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
echo "$LINE" >>"$MODPATH"/system.prop
echo "$LINE" >>"$MODPATH/system.prop"
done <"$1"
}

# Credits
ui_print ""
ui_print "****************************************************"
ui_print "* MMT Extended by Zackptg5 @ XDA *"
ui_print "* Modified by pedrozzz0 @ GitHub to King Tweaks™ *"
ui_print "****************************************************"
ui_print "*************************************"
ui_print "* MMT Extended by Zackptg5 @ XDA *"
ui_print "* Modified by pedrozzz0 @ GitHub *"
ui_print "*************************************"
ui_print ""

# 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!"; }
[[ -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 "$ARCH" | cut -c-3)
Expand All @@ -156,7 +156,7 @@ ORIGDIR="$MAGISKTMP/mirror"
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
[[ -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
Expand All @@ -172,9 +172,9 @@ ORIGDIR="$MAGISKTMP/mirror"
}

# Extract files
ui_print "[*] Extracting King Tweaks Reborn files..."
ui_print "[*] Extracting FSCC 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
[[ -f "$MODPATH/common/addon.tar.xz" ]] && tar -xf "$MODPATH/common/addon.tar.xz" -C "$MODPATH/common" 2>/dev/null

# Run addons
[[ "$(ls -A "$MODPATH"/common/addon/*/install.sh 2>/dev/null)" ]] && {
Expand All @@ -201,7 +201,7 @@ ui_print "[*] Removing old files..."
}

# Install process
ui_print "[*] Installing King Tweaks Reborn..."
ui_print "[*] Installing FSCC..."

[[ -f "$MODPATH/common/install.sh" ]] && . "$MODPATH/common/install.sh"

Expand All @@ -213,24 +213,24 @@ for i in $(find "$MODPATH" -type f -name *.sh -o -name *.prop -o -name *.rule);
[[ "$(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) [[ -s "$INFO" ]] || [[ "$(head -1 "$MODPATH"/uninstall.sh)" != "# Don't modify anything after this" ]] && install_script "$MODPATH"/uninstall.sh || rm -f "$INFO" "$MODPATH"/uninstall.sh ;;
"$MODPATH/service.sh") install_script -l "$i" ;;
"$MODPATH/post-fs-data.sh") install_script -p "$i" ;;
"$MODPATH/uninstall.sh") [[ -s "$INFO" ]] || [[ "$(head -1 "$MODPATH/uninstall.sh")" != "# Don't modify anything after this" ]] && install_script "$MODPATH/uninstall.sh" || rm -f "$INFO" "$MODPATH"/uninstall.sh ;;
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
[[ -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
"$DYNLIB" && {
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")"
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
Expand Down
5 changes: 5 additions & 0 deletions libcommon.sh → fscc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ apx1="/apex/com.android.art/javalib"
apx2="/apex/com.android.runtime/javalib"
fscc_file_list=""
fscc_log="/data/media/0/ktsr/fscc.log"
ver="1.0.0"

log_i() {
echo "[$(date +%T)]: [*] $1" >>"$fscc_log"
Expand Down Expand Up @@ -167,4 +168,8 @@ fscc_add_apex_lib "bouncycastle.jar"
}
fscc_stop
fscc_start
log_i "FSCC - Filesystem optimizer
Version: $ver
Status: $(fscc_status)
"
notif_end
2 changes: 1 addition & 1 deletion module.prop
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version=1.0.0
versionCode=99
author=pedro (pedrozzz0 @ GitHub), Matt Yang (yc9559 @ GitHub)
description=A filesystem optimizer which focus on optimizing user-experience.
build_date=Fri Jul 29 20:10:26 -03 2022
build_date=Sun Aug 14 12:09:12 -03 2022

0 comments on commit a4ba4c8

Please sign in to comment.