2017-06-18 16:15:44 +00:00
|
|
|
##########################################################################################
|
2017-07-30 19:03:52 +00:00
|
|
|
#
|
2017-06-18 16:15:44 +00:00
|
|
|
# Magisk Survival Script for ROMs with addon.d support
|
|
|
|
# by topjohnwu
|
2017-07-30 19:03:52 +00:00
|
|
|
#
|
2017-06-18 16:15:44 +00:00
|
|
|
# Inspired by 99-flashafterupdate.sh of osm0sis @ xda-developers
|
2017-07-30 19:03:52 +00:00
|
|
|
#
|
2017-06-18 16:15:44 +00:00
|
|
|
##########################################################################################
|
|
|
|
|
2018-08-03 14:40:49 +00: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 16:15:44 +00:00
|
|
|
|
2018-06-21 02:53:49 +00:00
|
|
|
initialize() {
|
|
|
|
# This path should work in any cases
|
|
|
|
TMPDIR=/dev/tmp
|
2017-06-18 16:15:44 +00:00
|
|
|
|
2017-09-26 12:21:43 +00:00
|
|
|
mount /data 2>/dev/null
|
|
|
|
|
2018-06-21 02:53:49 +00:00
|
|
|
MAGISKBIN=/data/adb/magisk
|
2017-07-02 13:36:09 +00:00
|
|
|
if [ ! -d $MAGISKBIN ]; then
|
|
|
|
echo "! Cannot find Magisk binaries!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-07-09 16:17:34 +00:00
|
|
|
# Load utility functions
|
2017-06-18 16:15:44 +00:00
|
|
|
. $MAGISKBIN/util_functions.sh
|
|
|
|
|
2018-06-21 02:53:49 +00:00
|
|
|
APK=/data/adb/magisk.apk
|
2018-08-02 19:43:02 +00:00
|
|
|
[ -f $APK ] || APK=/data/magisk/magisk.apk
|
2018-06-21 02:53:49 +00:00
|
|
|
[ -f $APK ] || APK=/data/app/com.topjohnwu.magisk*/*.apk
|
|
|
|
}
|
|
|
|
|
|
|
|
show_logo() {
|
2017-06-18 16:15:44 +00:00
|
|
|
ui_print "************************"
|
2017-07-30 19:03:52 +00:00
|
|
|
ui_print "* Magisk v$MAGISK_VER addon.d"
|
2017-06-18 16:15:44 +00:00
|
|
|
ui_print "************************"
|
2018-06-21 02:53:49 +00:00
|
|
|
}
|
2017-06-18 16:15:44 +00:00
|
|
|
|
2018-08-03 14:40:49 +00:00
|
|
|
installation() {
|
2018-06-21 02:53:49 +00:00
|
|
|
find_boot_image
|
|
|
|
find_dtbo_image
|
2018-07-04 15:46:16 +00:00
|
|
|
[ -z $BOOTIMAGE ] && abort "! Unable to detect target image"
|
|
|
|
ui_print "- Target image: $BOOTIMAGE"
|
|
|
|
[ -z $DTBOIMAGE ] || ui_print "- DTBO image: $DTBOIMAGE"
|
2018-06-21 02:53:49 +00:00
|
|
|
get_flags
|
2017-06-18 16:15:44 +00:00
|
|
|
|
2018-07-19 16:37:38 +00:00
|
|
|
remove_system_su
|
|
|
|
|
2018-06-19 21:16:43 +00:00
|
|
|
[ -f $APK ] && eval $BOOTSIGNER -verify < $BOOTIMAGE && BOOTSIGNED=true
|
2018-06-19 14:05:44 +00:00
|
|
|
$BOOTSIGNED && ui_print "- Boot image is signed with AVB 1.0"
|
|
|
|
|
2017-06-18 16:15:44 +00:00
|
|
|
SOURCEDMODE=true
|
|
|
|
cd $MAGISKBIN
|
|
|
|
|
|
|
|
# Source the boot patcher
|
2018-06-21 02:53:49 +00:00
|
|
|
. ./boot_patch.sh "$BOOTIMAGE"
|
2017-06-18 16:15:44 +00:00
|
|
|
|
2018-08-10 10:59:14 +00:00
|
|
|
ui_print "- Flashing new boot image"
|
2018-08-11 07:56:12 +00:00
|
|
|
flash_image new-boot.img "$BOOTIMAGE" || abort "! Insufficient partition size"
|
2017-11-10 17:33:50 +00:00
|
|
|
rm -f new-boot.img
|
|
|
|
|
2017-09-26 12:21:43 +00:00
|
|
|
if [ -f stock_boot* ]; then
|
|
|
|
rm -f /data/stock_boot* 2>/dev/null
|
2018-06-21 02:53:49 +00:00
|
|
|
$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
|
2017-06-18 16:15:44 +00:00
|
|
|
fi
|
2017-09-26 12:21:43 +00:00
|
|
|
|
2017-06-18 16:15:44 +00:00
|
|
|
cd /
|
2018-06-21 02:53:49 +00:00
|
|
|
}
|
2017-06-18 16:15:44 +00:00
|
|
|
|
2018-06-21 02:53:49 +00:00
|
|
|
finalize() {
|
2017-06-18 16:15:44 +00:00
|
|
|
ui_print "- Done"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2018-06-21 02:53:49 +00:00
|
|
|
main_v1() {
|
|
|
|
# Wait for post addon.d processes to finish
|
|
|
|
sleep 5
|
|
|
|
recovery_actions
|
|
|
|
show_logo
|
|
|
|
mount_partitions
|
|
|
|
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
|
|
|
|
installation
|
|
|
|
finalize
|
|
|
|
}
|
|
|
|
|
2017-06-18 16:15:44 +00:00
|
|
|
case "$1" in
|
|
|
|
backup)
|
|
|
|
# Stub
|
|
|
|
;;
|
|
|
|
restore)
|
|
|
|
# Stub
|
|
|
|
;;
|
|
|
|
pre-backup)
|
|
|
|
# Stub
|
|
|
|
;;
|
|
|
|
post-backup)
|
|
|
|
# Stub
|
|
|
|
;;
|
|
|
|
pre-restore)
|
|
|
|
# Stub
|
|
|
|
;;
|
|
|
|
post-restore)
|
2018-06-21 02:53:49 +00:00
|
|
|
if $backuptool_ab; then
|
2018-08-03 14:40:49 +00:00
|
|
|
exec su -c "sh $0 addond-v2"
|
2018-06-21 02:53:49 +00:00
|
|
|
else
|
2018-08-03 14:40:49 +00:00
|
|
|
initialize
|
2018-07-05 09:29:13 +00:00
|
|
|
OUTFD=
|
2018-06-21 02:53:49 +00:00
|
|
|
get_outfd
|
|
|
|
# Run in background, hack for addon.d-v1
|
|
|
|
(main_v1) &
|
|
|
|
fi
|
2017-06-18 16:15:44 +00:00
|
|
|
;;
|
2018-08-03 14:40:49 +00:00
|
|
|
addond-v2)
|
|
|
|
initialize
|
|
|
|
# Override ui_print
|
|
|
|
ui_print() {
|
|
|
|
log -t Magisk -- "$1"
|
|
|
|
}
|
|
|
|
# addon.d-v2
|
|
|
|
main_v2
|
|
|
|
;;
|
2017-06-18 16:15:44 +00:00
|
|
|
esac
|