2017-06-19 00:15:44 +08:00
|
|
|
#!/sbin/sh
|
|
|
|
##########################################################################################
|
2017-07-31 03:03:52 +08:00
|
|
|
#
|
2017-06-19 00:15:44 +08:00
|
|
|
# Magisk Survival Script for ROMs with addon.d support
|
|
|
|
# by topjohnwu
|
2017-07-31 03:03:52 +08:00
|
|
|
#
|
2017-06-19 00:15:44 +08:00
|
|
|
# Inspired by 99-flashafterupdate.sh of osm0sis @ xda-developers
|
2017-07-31 03:03:52 +08:00
|
|
|
#
|
2017-06-19 00:15:44 +08:00
|
|
|
##########################################################################################
|
|
|
|
|
|
|
|
. /tmp/backuptool.functions
|
|
|
|
|
|
|
|
main() {
|
|
|
|
# Magisk binaries
|
2017-12-16 02:02:17 +08:00
|
|
|
MAGISKBIN=/data/adb/magisk
|
2017-09-26 20:21:43 +08:00
|
|
|
# This script always runs in recovery
|
2017-06-19 00:15:44 +08:00
|
|
|
BOOTMODE=false
|
|
|
|
|
2017-09-26 20:21:43 +08:00
|
|
|
mount /data 2>/dev/null
|
|
|
|
|
2017-07-02 21:36:09 +08:00
|
|
|
if [ ! -d $MAGISKBIN ]; then
|
|
|
|
echo "! Cannot find Magisk binaries!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-06-19 00:15:44 +08:00
|
|
|
# Wait for post addon.d processes to finish
|
|
|
|
sleep 5
|
|
|
|
|
2017-07-10 00:17:34 +08:00
|
|
|
# Load utility functions
|
2017-06-19 00:15:44 +08:00
|
|
|
. $MAGISKBIN/util_functions.sh
|
|
|
|
|
|
|
|
ui_print "************************"
|
2017-07-31 03:03:52 +08:00
|
|
|
ui_print "* Magisk v$MAGISK_VER addon.d"
|
2017-06-19 00:15:44 +08:00
|
|
|
ui_print "************************"
|
|
|
|
|
2017-09-26 20:21:43 +08:00
|
|
|
mount_partitions
|
2017-07-02 21:36:09 +08:00
|
|
|
|
2017-09-26 20:21:43 +08:00
|
|
|
api_level_arch_detect
|
2017-07-14 01:01:25 +08:00
|
|
|
|
2017-06-24 23:38:20 +09:00
|
|
|
recovery_actions
|
2017-06-19 00:15:44 +08:00
|
|
|
|
2017-09-26 20:21:43 +08:00
|
|
|
remove_system_su
|
|
|
|
|
2017-06-19 00:15:44 +08:00
|
|
|
find_boot_image
|
|
|
|
[ -z $BOOTIMAGE ] && abort "! Unable to detect boot image"
|
2017-11-11 01:33:50 +08:00
|
|
|
ui_print "- Found boot image: $BOOTIMAGE"
|
2017-06-19 00:15:44 +08:00
|
|
|
|
|
|
|
SOURCEDMODE=true
|
|
|
|
cd $MAGISKBIN
|
|
|
|
|
|
|
|
# Source the boot patcher
|
2017-06-24 23:38:20 +09:00
|
|
|
. $MAGISKBIN/boot_patch.sh "$BOOTIMAGE"
|
2017-06-19 00:15:44 +08:00
|
|
|
|
2017-11-11 01:33:50 +08:00
|
|
|
flash_boot_image new-boot.img "$BOOTIMAGE"
|
|
|
|
rm -f new-boot.img
|
|
|
|
|
2017-09-26 20:21:43 +08:00
|
|
|
if [ -f stock_boot* ]; then
|
|
|
|
rm -f /data/stock_boot* 2>/dev/null
|
2017-12-16 02:02:17 +08:00
|
|
|
mv stock_boot* /data
|
2017-06-19 00:15:44 +08:00
|
|
|
fi
|
2017-09-26 20:21:43 +08:00
|
|
|
|
2017-11-11 01:33:50 +08:00
|
|
|
patch_dtbo_image
|
|
|
|
|
|
|
|
if [ -f stock_dtbo* ]; then
|
|
|
|
rm -f /data/stock_dtbo* 2>/dev/null
|
2017-12-16 02:02:17 +08:00
|
|
|
mv stock_dtbo* /data
|
2017-11-11 01:33:50 +08:00
|
|
|
fi
|
2017-06-19 00:15:44 +08:00
|
|
|
|
|
|
|
cd /
|
2017-07-02 21:36:09 +08:00
|
|
|
recovery_cleanup
|
2017-06-19 00:15:44 +08:00
|
|
|
|
|
|
|
ui_print "- Done"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
backup)
|
|
|
|
# Stub
|
|
|
|
;;
|
|
|
|
restore)
|
|
|
|
# Stub
|
|
|
|
;;
|
|
|
|
pre-backup)
|
|
|
|
# Stub
|
|
|
|
;;
|
|
|
|
post-backup)
|
|
|
|
# Stub
|
|
|
|
;;
|
|
|
|
pre-restore)
|
|
|
|
# Stub
|
|
|
|
;;
|
|
|
|
post-restore)
|
|
|
|
# Get the FD for ui_print
|
|
|
|
OUTFD=`ps | grep -v grep | grep -oE "update(.*)" | cut -d" " -f3`
|
2017-07-31 03:03:52 +08:00
|
|
|
# Run the main function in a parallel subshell
|
2017-06-19 00:15:44 +08:00
|
|
|
(main) &
|
|
|
|
;;
|
|
|
|
esac
|