scripts: refactor and major addon.d fixes
- remove redundant addon.d.sh script bits that were covered elsewhere ($TMPDIR in util_functions.sh, find_dtbo_image in patch_dtbo_image) - refactor addon.d.sh and flash_script.sh for simplicity and readability, and put common flashing script in util_functions.sh (as patch_boot_image), which should greatly help avoid them getting out of sync going forward and fixes compressing ramdisk support and post-patch cleanup for addon.d - add check_data to addon.d.sh since moving stock_boot* and stock_dtbo* backups depend on it and so weren't occuring with addon.d - fix find_manager_apk with working fallback for recovery addon.d execution (where `magisk --sqlite` will not work for hidden Manager), Manager DynAPK hiding, and print a useful log warning if an APK can't be found
This commit is contained in:
parent
4cd154675f
commit
6dd34aec47
@ -20,9 +20,6 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
initialize() {
|
initialize() {
|
||||||
# This path should work in any cases
|
|
||||||
TMPDIR=/dev/tmp
|
|
||||||
|
|
||||||
mount /data 2>/dev/null
|
mount /data 2>/dev/null
|
||||||
|
|
||||||
MAGISKBIN=/data/adb/magisk
|
MAGISKBIN=/data/adb/magisk
|
||||||
@ -43,71 +40,43 @@ initialize() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
show_logo() {
|
|
||||||
ui_print "************************"
|
|
||||||
ui_print "* Magisk v$MAGISK_VER addon.d"
|
|
||||||
ui_print "************************"
|
|
||||||
}
|
|
||||||
|
|
||||||
installation() {
|
|
||||||
find_manager_apk
|
|
||||||
get_flags
|
|
||||||
find_boot_image
|
|
||||||
find_dtbo_image
|
|
||||||
[ -z $BOOTIMAGE ] && abort "! Unable to detect target image"
|
|
||||||
ui_print "- Target image: $BOOTIMAGE"
|
|
||||||
[ -z $DTBOIMAGE ] || ui_print "- DTBO image: $DTBOIMAGE"
|
|
||||||
|
|
||||||
remove_system_su
|
|
||||||
|
|
||||||
[ -f $APK ] && eval $BOOTSIGNER -verify < $BOOTIMAGE && BOOTSIGNED=true
|
|
||||||
$BOOTSIGNED && ui_print "- Boot image is signed with AVB 1.0"
|
|
||||||
|
|
||||||
SOURCEDMODE=true
|
|
||||||
cd $MAGISKBIN
|
|
||||||
|
|
||||||
# Source the boot patcher
|
|
||||||
. ./boot_patch.sh "$BOOTIMAGE"
|
|
||||||
|
|
||||||
ui_print "- Flashing new boot image"
|
|
||||||
flash_image new-boot.img "$BOOTIMAGE" || abort "! Insufficient partition size"
|
|
||||||
rm -f new-boot.img
|
|
||||||
|
|
||||||
if [ -f stock_boot* ]; then
|
|
||||||
rm -f /data/stock_boot* 2>/dev/null
|
|
||||||
$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 /
|
|
||||||
}
|
|
||||||
|
|
||||||
finalize() {
|
|
||||||
ui_print "- Done"
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
if ! $backuptool_ab; then
|
if ! $backuptool_ab; then
|
||||||
# Wait for post addon.d-v1 processes to finish
|
# Wait for post addon.d-v1 processes to finish
|
||||||
sleep 5
|
sleep 5
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$BOOTMODE || recovery_actions
|
$BOOTMODE || recovery_actions
|
||||||
show_logo
|
|
||||||
|
ui_print "************************"
|
||||||
|
ui_print "* Magisk v$MAGISK_VER addon.d"
|
||||||
|
ui_print "************************"
|
||||||
|
|
||||||
mount_partitions
|
mount_partitions
|
||||||
|
check_data
|
||||||
|
get_flags
|
||||||
|
|
||||||
if $backuptool_ab; then
|
if $backuptool_ab; then
|
||||||
# Swap the slot for addon.d-v2
|
# Swap the slot for addon.d-v2
|
||||||
if [ ! -z $SLOT ]; then [ $SLOT = _a ] && SLOT=_b || SLOT=_a; fi
|
if [ ! -z $SLOT ]; then [ $SLOT = _a ] && SLOT=_b || SLOT=_a; fi
|
||||||
fi
|
fi
|
||||||
installation
|
|
||||||
|
find_boot_image
|
||||||
|
|
||||||
|
[ -z $BOOTIMAGE ] && abort "! Unable to detect target image"
|
||||||
|
ui_print "- Target image: $BOOTIMAGE"
|
||||||
|
|
||||||
|
remove_system_su
|
||||||
|
find_manager_apk
|
||||||
|
patch_boot_image
|
||||||
|
|
||||||
|
cd /
|
||||||
|
# Cleanups
|
||||||
$BOOTMODE || recovery_cleanup
|
$BOOTMODE || recovery_cleanup
|
||||||
finalize
|
rm -rf $TMPDIR
|
||||||
|
|
||||||
|
ui_print "- Done"
|
||||||
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#MAGISK
|
#MAGISK
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
#
|
#
|
||||||
# Magisk Flash Script
|
# Magisk Flash Script (updater-script)
|
||||||
# by topjohnwu
|
# by topjohnwu
|
||||||
#
|
#
|
||||||
# This script will detect, construct the environment for Magisk
|
# This script will detect, construct the environment for Magisk
|
||||||
@ -103,43 +103,10 @@ fi
|
|||||||
$BOOTMODE || recovery_actions
|
$BOOTMODE || recovery_actions
|
||||||
|
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
# Boot patching
|
# Boot/DTBO Patching
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
|
|
||||||
eval $BOOTSIGNER -verify < $BOOTIMAGE && BOOTSIGNED=true
|
patch_boot_image
|
||||||
$BOOTSIGNED && ui_print "- Boot image is signed with AVB 1.0"
|
|
||||||
|
|
||||||
SOURCEDMODE=true
|
|
||||||
cd $MAGISKBIN
|
|
||||||
|
|
||||||
$IS64BIT && mv -f magiskinit64 magiskinit || rm -f magiskinit64
|
|
||||||
|
|
||||||
# Source the boot patcher
|
|
||||||
. ./boot_patch.sh "$BOOTIMAGE"
|
|
||||||
|
|
||||||
ui_print "- Flashing new boot image"
|
|
||||||
|
|
||||||
if ! flash_image new-boot.img "$BOOTIMAGE"; then
|
|
||||||
ui_print "- Compressing ramdisk to fit in partition"
|
|
||||||
./magiskboot cpio ramdisk.cpio compress
|
|
||||||
./magiskboot repack "$BOOTIMAGE"
|
|
||||||
flash_image new-boot.img "$BOOTIMAGE" || abort "! Insufficient partition size"
|
|
||||||
fi
|
|
||||||
|
|
||||||
./magiskboot cleanup
|
|
||||||
rm -f new-boot.img
|
|
||||||
|
|
||||||
if [ -f stock_boot* ]; then
|
|
||||||
rm -f /data/stock_boot* 2>/dev/null
|
|
||||||
$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 /
|
cd /
|
||||||
# Cleanups
|
# Cleanups
|
||||||
|
@ -293,6 +293,45 @@ patch_dtbo_image() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
patch_boot_image() {
|
||||||
|
# Common installation script for flash_script.sh (updater-script) and addon.d.sh
|
||||||
|
eval $BOOTSIGNER -verify < $BOOTIMAGE && BOOTSIGNED=true
|
||||||
|
$BOOTSIGNED && ui_print "- Boot image is signed with AVB 1.0"
|
||||||
|
|
||||||
|
SOURCEDMODE=true
|
||||||
|
cd $MAGISKBIN
|
||||||
|
|
||||||
|
$IS64BIT && mv -f magiskinit64 magiskinit 2>/dev/null || rm -f magiskinit64
|
||||||
|
|
||||||
|
# Source the boot patcher
|
||||||
|
. ./boot_patch.sh "$BOOTIMAGE"
|
||||||
|
|
||||||
|
ui_print "- Flashing new boot image"
|
||||||
|
|
||||||
|
if ! flash_image new-boot.img "$BOOTIMAGE"; then
|
||||||
|
ui_print "- Compressing ramdisk to fit in partition"
|
||||||
|
./magiskboot cpio ramdisk.cpio compress
|
||||||
|
./magiskboot repack "$BOOTIMAGE"
|
||||||
|
flash_image new-boot.img "$BOOTIMAGE" || abort "! Insufficient partition size"
|
||||||
|
fi
|
||||||
|
|
||||||
|
./magiskboot cleanup
|
||||||
|
rm -f new-boot.img
|
||||||
|
|
||||||
|
if [ -f stock_boot* ]; then
|
||||||
|
rm -f /data/stock_boot* 2>/dev/null
|
||||||
|
$DATA && mv stock_boot* /data
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Patch DTBO together with boot image
|
||||||
|
$KEEPVERITY || patch_dtbo_image
|
||||||
|
|
||||||
|
if [ -f stock_dtbo* ]; then
|
||||||
|
rm -f /data/stock_dtbo* 2>/dev/null
|
||||||
|
$DATA && mv stock_dtbo* /data
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
sign_chromeos() {
|
sign_chromeos() {
|
||||||
ui_print "- Signing ChromeOS boot image"
|
ui_print "- Signing ChromeOS boot image"
|
||||||
|
|
||||||
@ -360,13 +399,16 @@ check_data() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
find_manager_apk() {
|
find_manager_apk() {
|
||||||
APK=/data/adb/magisk.apk
|
[ -z $APK ] && APK=/data/adb/magisk.apk
|
||||||
[ -f $APK ] || APK=/data/magisk/magisk.apk
|
[ -f $APK ] || APK=/data/magisk/magisk.apk
|
||||||
[ -f $APK ] || APK=/data/app/com.topjohnwu.magisk*/*.apk
|
[ -f $APK ] || APK=/data/app/com.topjohnwu.magisk*/*.apk
|
||||||
if [ ! -f $APK ]; then
|
if [ ! -f $APK ]; then
|
||||||
DBAPK=`magisk --sqlite "SELECT value FROM strings WHERE key='requester'" | cut -d= -f2`
|
DBAPK=`magisk --sqlite "SELECT value FROM strings WHERE key='requester'" 2>/dev/null | cut -d= -f2`
|
||||||
[ -z "$DBAPK" ] || APK=/data/app/$DBAPK*/*.apk
|
[ -z $DBAPK ] && DBAPK=`strings /data/adb/magisk.db | grep 5requester | cut -c11-`
|
||||||
|
[ -z $DBAPK ] || APK=/data/user_de/*/$DBAPK/dyn/*.apk
|
||||||
|
[ -f $APK ] || APK=/data/app/$DBAPK*/*.apk
|
||||||
fi
|
fi
|
||||||
|
[ -f $APK ] || ui_print "! Unable to detect Magisk Manager APK for BootSigner"
|
||||||
}
|
}
|
||||||
|
|
||||||
#################
|
#################
|
||||||
|
Loading…
Reference in New Issue
Block a user