2017-06-18 18:15:44 +02:00
|
|
|
##########################################################################################
|
2017-07-30 21:03:52 +02:00
|
|
|
#
|
2017-06-18 18:15:44 +02:00
|
|
|
# Magisk Survival Script for ROMs with addon.d support
|
|
|
|
# by topjohnwu
|
2017-07-30 21:03:52 +02:00
|
|
|
#
|
2017-06-18 18:15:44 +02:00
|
|
|
# Inspired by 99-flashafterupdate.sh of osm0sis @ xda-developers
|
2017-07-30 21:03:52 +02:00
|
|
|
#
|
2017-06-18 18:15:44 +02:00
|
|
|
##########################################################################################
|
|
|
|
|
2018-08-03 16:40:49 +02:00
|
|
|
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
|
2017-06-18 18:15:44 +02:00
|
|
|
|
2018-06-21 04:53:49 +02:00
|
|
|
initialize() {
|
|
|
|
MAGISKBIN=/data/adb/magisk
|
2019-11-03 02:50:33 +01:00
|
|
|
|
2017-07-02 15:36:09 +02:00
|
|
|
if [ ! -d $MAGISKBIN ]; then
|
|
|
|
echo "! Cannot find Magisk binaries!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-07-09 18:17:34 +02:00
|
|
|
# Load utility functions
|
2017-06-18 18:15:44 +02:00
|
|
|
. $MAGISKBIN/util_functions.sh
|
2019-08-31 18:28:00 +02:00
|
|
|
|
|
|
|
if $BOOTMODE; then
|
|
|
|
# Override ui_print when booted
|
|
|
|
ui_print() { log -t Magisk -- "$1"; }
|
|
|
|
else
|
|
|
|
OUTFD=
|
|
|
|
setup_flashable
|
|
|
|
fi
|
2018-06-21 04:53:49 +02:00
|
|
|
}
|
|
|
|
|
2019-11-02 04:26:08 +01:00
|
|
|
main() {
|
|
|
|
if ! $backuptool_ab; then
|
|
|
|
# Wait for post addon.d-v1 processes to finish
|
|
|
|
sleep 5
|
|
|
|
fi
|
|
|
|
|
2019-11-03 02:50:33 +01:00
|
|
|
# Ensure we aren't in /tmp/addon.d anymore (since it's been deleted by addon.d)
|
|
|
|
cd $TMPDIR
|
|
|
|
|
2019-11-02 04:26:08 +01:00
|
|
|
$BOOTMODE || recovery_actions
|
|
|
|
|
2017-06-18 18:15:44 +02:00
|
|
|
ui_print "************************"
|
2017-07-30 21:03:52 +02:00
|
|
|
ui_print "* Magisk v$MAGISK_VER addon.d"
|
2017-06-18 18:15:44 +02:00
|
|
|
ui_print "************************"
|
|
|
|
|
2019-11-02 04:26:08 +01:00
|
|
|
mount_partitions
|
|
|
|
check_data
|
2019-04-06 19:04:17 +02:00
|
|
|
get_flags
|
2019-11-02 04:26:08 +01:00
|
|
|
|
|
|
|
if $backuptool_ab; then
|
|
|
|
# Swap the slot for addon.d-v2
|
|
|
|
if [ ! -z $SLOT ]; then [ $SLOT = _a ] && SLOT=_b || SLOT=_a; fi
|
|
|
|
fi
|
|
|
|
|
2018-06-21 04:53:49 +02:00
|
|
|
find_boot_image
|
2019-11-02 04:26:08 +01:00
|
|
|
|
2018-07-04 17:46:16 +02:00
|
|
|
[ -z $BOOTIMAGE ] && abort "! Unable to detect target image"
|
|
|
|
ui_print "- Target image: $BOOTIMAGE"
|
2017-06-18 18:15:44 +02:00
|
|
|
|
2018-07-19 18:37:38 +02:00
|
|
|
remove_system_su
|
2019-11-02 04:26:08 +01:00
|
|
|
find_manager_apk
|
2020-01-01 07:02:44 +01:00
|
|
|
install_magisk
|
2017-09-26 14:21:43 +02:00
|
|
|
|
2019-11-02 04:26:08 +01:00
|
|
|
# Cleanups
|
|
|
|
$BOOTMODE || recovery_cleanup
|
|
|
|
rm -rf $TMPDIR
|
2017-06-18 18:15:44 +02:00
|
|
|
|
|
|
|
ui_print "- Done"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
backup)
|
|
|
|
# Stub
|
|
|
|
;;
|
|
|
|
restore)
|
|
|
|
# Stub
|
|
|
|
;;
|
|
|
|
pre-backup)
|
|
|
|
# Stub
|
|
|
|
;;
|
|
|
|
post-backup)
|
|
|
|
# Stub
|
|
|
|
;;
|
|
|
|
pre-restore)
|
|
|
|
# Stub
|
|
|
|
;;
|
|
|
|
post-restore)
|
2019-08-31 18:28:00 +02:00
|
|
|
initialize
|
2018-06-21 04:53:49 +02:00
|
|
|
if $backuptool_ab; then
|
2019-08-31 18:28:00 +02:00
|
|
|
$BOOTMODE && su=su || su=sh
|
|
|
|
exec $su -c "sh $0 addond-v2"
|
2018-06-21 04:53:49 +02:00
|
|
|
else
|
|
|
|
# Run in background, hack for addon.d-v1
|
2019-08-31 18:28:00 +02:00
|
|
|
(main) &
|
2018-06-21 04:53:49 +02:00
|
|
|
fi
|
2017-06-18 18:15:44 +02:00
|
|
|
;;
|
2018-08-03 16:40:49 +02:00
|
|
|
addond-v2)
|
|
|
|
initialize
|
2019-08-31 18:28:00 +02:00
|
|
|
main
|
2018-08-03 16:40:49 +02:00
|
|
|
;;
|
2017-06-18 18:15:44 +02:00
|
|
|
esac
|