mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-29 20:07:39 +00:00
6fd357962f
- change to $TMPDIR in addon.d.sh since recovery addon.d-v1 backup + restore leaves you in /tmp/addon.d which the restore then deletes, which would break $BOOTSIGNER execution with the following: libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 1078 (main), pid 1078 (main) Segmentation fault - also move $BOOTSIGNER execution to after `cd $MAGISKBIN` to ensure it's in a working directory in all cases - addon.d.sh data mount wasn't doing anything since /data has to already be mounted for the script to be running, so move it into /system/addon.d/99-magisk.sh stub script where it might be useful on recoveries that don't mount /data initially Fixes #2013
115 lines
2.1 KiB
Bash
115 lines
2.1 KiB
Bash
##########################################################################################
|
|
#
|
|
# Magisk Survival Script for ROMs with addon.d support
|
|
# by topjohnwu
|
|
#
|
|
# Inspired by 99-flashafterupdate.sh of osm0sis @ xda-developers
|
|
#
|
|
##########################################################################################
|
|
|
|
V1_FUNCS=/tmp/backuptool.functions
|
|
V2_FUNCS=/postinstall/system/bin/backuptool_ab.functions
|
|
|
|
if [ -f $V1_FUNCS ]; then
|
|
. $V1_FUNCS
|
|
backuptool_ab=false
|
|
elif [ -f $V2_FUNCS ]; then
|
|
. $V2_FUNCS
|
|
else
|
|
return 1
|
|
fi
|
|
|
|
initialize() {
|
|
MAGISKBIN=/data/adb/magisk
|
|
|
|
if [ ! -d $MAGISKBIN ]; then
|
|
echo "! Cannot find Magisk binaries!"
|
|
exit 1
|
|
fi
|
|
|
|
# Load utility functions
|
|
. $MAGISKBIN/util_functions.sh
|
|
|
|
if $BOOTMODE; then
|
|
# Override ui_print when booted
|
|
ui_print() { log -t Magisk -- "$1"; }
|
|
else
|
|
OUTFD=
|
|
setup_flashable
|
|
fi
|
|
}
|
|
|
|
main() {
|
|
if ! $backuptool_ab; then
|
|
# Wait for post addon.d-v1 processes to finish
|
|
sleep 5
|
|
fi
|
|
|
|
# Ensure we aren't in /tmp/addon.d anymore (since it's been deleted by addon.d)
|
|
cd $TMPDIR
|
|
|
|
$BOOTMODE || recovery_actions
|
|
|
|
ui_print "************************"
|
|
ui_print "* Magisk v$MAGISK_VER addon.d"
|
|
ui_print "************************"
|
|
|
|
mount_partitions
|
|
check_data
|
|
get_flags
|
|
|
|
if $backuptool_ab; then
|
|
# Swap the slot for addon.d-v2
|
|
if [ ! -z $SLOT ]; then [ $SLOT = _a ] && SLOT=_b || SLOT=_a; fi
|
|
fi
|
|
|
|
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
|
|
rm -rf $TMPDIR
|
|
|
|
ui_print "- Done"
|
|
exit 0
|
|
}
|
|
|
|
case "$1" in
|
|
backup)
|
|
# Stub
|
|
;;
|
|
restore)
|
|
# Stub
|
|
;;
|
|
pre-backup)
|
|
# Stub
|
|
;;
|
|
post-backup)
|
|
# Stub
|
|
;;
|
|
pre-restore)
|
|
# Stub
|
|
;;
|
|
post-restore)
|
|
initialize
|
|
if $backuptool_ab; then
|
|
$BOOTMODE && su=su || su=sh
|
|
exec $su -c "sh $0 addond-v2"
|
|
else
|
|
# Run in background, hack for addon.d-v1
|
|
(main) &
|
|
fi
|
|
;;
|
|
addond-v2)
|
|
initialize
|
|
main
|
|
;;
|
|
esac
|