mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-12 05:07:45 +02:00
Fix output of addon.d, and add support for addon.d-v2
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
#!/sbin/sh
|
||||
# ADDOND_VERSION=2
|
||||
##########################################################################################
|
||||
#
|
||||
# Magisk Survival Script for ROMs with addon.d support
|
||||
@ -9,42 +10,44 @@
|
||||
##########################################################################################
|
||||
|
||||
. /tmp/backuptool.functions
|
||||
[ -z $backuptool_ab ] && backuptool_ab=false
|
||||
|
||||
main() {
|
||||
# Magisk binaries
|
||||
MAGISKBIN=/data/adb/magisk
|
||||
APK=/data/adb/magisk.apk
|
||||
[ -f $APK ] || APK=/data/magisk/magisk.apk
|
||||
[ -f $APK ] || APK=/data/app/com.topjohnwu.magisk*/*.apk
|
||||
initialize() {
|
||||
# This path should work in any cases
|
||||
TMPDIR=/dev/tmp
|
||||
|
||||
mount /data 2>/dev/null
|
||||
|
||||
MAGISKBIN=/data/adb/magisk
|
||||
if [ ! -d $MAGISKBIN ]; then
|
||||
echo "! Cannot find Magisk binaries!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Wait for post addon.d processes to finish
|
||||
sleep 5
|
||||
|
||||
# Load utility functions
|
||||
. $MAGISKBIN/util_functions.sh
|
||||
|
||||
APK=/data/adb/magisk.apk
|
||||
[ -f $APK ] || APK=/data/magisk/magisk.apk
|
||||
[ -f $APK ] || APK=/data/app/com.topjohnwu.magisk*/*.apk
|
||||
}
|
||||
|
||||
show_logo() {
|
||||
ui_print "************************"
|
||||
ui_print "* Magisk v$MAGISK_VER addon.d"
|
||||
ui_print "************************"
|
||||
}
|
||||
|
||||
mount_partitions
|
||||
|
||||
api_level_arch_detect
|
||||
|
||||
recovery_actions
|
||||
|
||||
remove_system_su
|
||||
|
||||
detection() {
|
||||
find_boot_image
|
||||
find_dtbo_image
|
||||
[ -z $BOOTIMAGE ] && abort "! Unable to detect boot image"
|
||||
ui_print "- Found boot image: $BOOTIMAGE"
|
||||
ui_print "- Found boot/ramdisk image: $BOOTIMAGE"
|
||||
[ -z $DTBOIMAGE ] || ui_print "- Found dtbo image: $DTBOIMAGE"
|
||||
get_flags
|
||||
}
|
||||
|
||||
installation() {
|
||||
[ -f $APK ] && eval $BOOTSIGNER -verify < $BOOTIMAGE && BOOTSIGNED=true
|
||||
$BOOTSIGNED && ui_print "- Boot image is signed with AVB 1.0"
|
||||
|
||||
@ -52,23 +55,54 @@ main() {
|
||||
cd $MAGISKBIN
|
||||
|
||||
# Source the boot patcher
|
||||
. $MAGISKBIN/boot_patch.sh "$BOOTIMAGE"
|
||||
. ./boot_patch.sh "$BOOTIMAGE"
|
||||
|
||||
flash_boot_image new-boot.img "$BOOTIMAGE"
|
||||
rm -f new-boot.img
|
||||
|
||||
if [ -f stock_boot* ]; then
|
||||
rm -f /data/stock_boot* 2>/dev/null
|
||||
mv stock_boot* /data
|
||||
$DATA && mv stock_boot* /data
|
||||
fi
|
||||
|
||||
$KEEPVERITY || patch_dtbo_image
|
||||
|
||||
if [ -f stock_dtbo* ]; then
|
||||
rm -f /data/stock_dtbo* 2>/dev/null
|
||||
$DATA && mv stock_dtbo* /data
|
||||
fi
|
||||
|
||||
cd /
|
||||
recovery_cleanup
|
||||
}
|
||||
|
||||
finalize() {
|
||||
ui_print "- Done"
|
||||
exit 0
|
||||
}
|
||||
|
||||
main_v1() {
|
||||
# Wait for post addon.d processes to finish
|
||||
sleep 5
|
||||
recovery_actions
|
||||
show_logo
|
||||
mount_partitions
|
||||
detection
|
||||
installation
|
||||
recovery_cleanup
|
||||
finalize
|
||||
}
|
||||
|
||||
main_v2() {
|
||||
boot_actions
|
||||
show_logo
|
||||
mount_partitions
|
||||
# Swap the slot
|
||||
if [ ! -z $SLOT ]; then [ $SLOT = _a ] && SLOT=_b || SLOT=_a; fi
|
||||
detection
|
||||
installation
|
||||
finalize
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
backup)
|
||||
# Stub
|
||||
@ -86,9 +120,15 @@ case "$1" in
|
||||
# Stub
|
||||
;;
|
||||
post-restore)
|
||||
# Get the FD for ui_print
|
||||
OUTFD=`ps | grep -v grep | grep -oE "update(.*)" | cut -d" " -f3`
|
||||
# Run the main function in a parallel subshell
|
||||
(main) &
|
||||
initialize
|
||||
if $backuptool_ab; then
|
||||
# addon.d-v2
|
||||
main_v2
|
||||
else
|
||||
OUTFD=1
|
||||
get_outfd
|
||||
# Run in background, hack for addon.d-v1
|
||||
(main_v1) &
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
Reference in New Issue
Block a user