2017-06-18 18:15:44 +02:00
|
|
|
#!/sbin/sh
|
|
|
|
##########################################################################################
|
|
|
|
#
|
|
|
|
# Magisk Survival Script for ROMs with addon.d support
|
|
|
|
# by topjohnwu
|
|
|
|
#
|
|
|
|
# Inspired by 99-flashafterupdate.sh of osm0sis @ xda-developers
|
|
|
|
#
|
|
|
|
##########################################################################################
|
|
|
|
|
|
|
|
. /tmp/backuptool.functions
|
|
|
|
|
|
|
|
main() {
|
|
|
|
# Magisk binaries
|
|
|
|
MAGISKBIN=/data/magisk
|
|
|
|
# This script always run in recovery
|
|
|
|
BOOTMODE=false
|
|
|
|
|
2017-07-02 15:36:09 +02:00
|
|
|
if [ ! -d $MAGISKBIN ]; then
|
|
|
|
echo "! Cannot find Magisk binaries!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-06-18 18:15:44 +02:00
|
|
|
# Wait for post addon.d processes to finish
|
|
|
|
sleep 5
|
|
|
|
|
|
|
|
mount -o ro /system 2>/dev/null
|
2017-06-24 16:38:20 +02:00
|
|
|
mount -o ro /vendor 2>/dev/null
|
2017-06-18 18:15:44 +02:00
|
|
|
mount /data 2>/dev/null
|
|
|
|
|
2017-07-09 18:17:34 +02:00
|
|
|
# Load utility functions
|
2017-06-18 18:15:44 +02:00
|
|
|
. $MAGISKBIN/util_functions.sh
|
|
|
|
|
|
|
|
[ -f /system/build.prop ] || abort "! /system could not be mounted!"
|
|
|
|
|
|
|
|
ui_print "************************"
|
|
|
|
ui_print "* MAGISK_VERSION_STUB"
|
|
|
|
ui_print "************************"
|
|
|
|
|
2017-07-02 15:36:09 +02:00
|
|
|
api_level_arch_detect
|
|
|
|
|
2017-07-13 19:01:25 +02:00
|
|
|
# Check if system root is installed and remove
|
|
|
|
remove_system_su
|
|
|
|
|
2017-06-24 16:38:20 +02:00
|
|
|
recovery_actions
|
2017-06-18 18:15:44 +02:00
|
|
|
|
|
|
|
find_boot_image
|
|
|
|
[ -z $BOOTIMAGE ] && abort "! Unable to detect boot image"
|
|
|
|
ui_print "- Found Boot Image: $BOOTIMAGE"
|
|
|
|
|
|
|
|
SOURCEDMODE=true
|
|
|
|
cd $MAGISKBIN
|
|
|
|
|
|
|
|
# Source the boot patcher
|
2017-06-24 16:38:20 +02:00
|
|
|
. $MAGISKBIN/boot_patch.sh "$BOOTIMAGE"
|
2017-06-18 18:15:44 +02:00
|
|
|
|
|
|
|
[ -f stock_boot* ] && rm -f /data/stock_boot* 2>/dev/null
|
|
|
|
|
|
|
|
ui_print "- Flashing new boot image"
|
|
|
|
if [ -L "$BOOTIMAGE" ]; then
|
|
|
|
dd if=new-boot.img of="$BOOTIMAGE" bs=4096
|
|
|
|
else
|
2017-07-09 18:17:34 +02:00
|
|
|
cat new-boot.img /dev/zero | dd of="$BOOTIMAGE" bs=4096 >/dev/null 2>&1
|
2017-06-18 18:15:44 +02:00
|
|
|
fi
|
|
|
|
rm -f new-boot.img
|
|
|
|
|
|
|
|
cd /
|
|
|
|
|
2017-07-02 15:36:09 +02:00
|
|
|
recovery_cleanup
|
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)
|
|
|
|
# Get the FD for ui_print
|
|
|
|
OUTFD=`ps | grep -v grep | grep -oE "update(.*)" | cut -d" " -f3`
|
|
|
|
# Run the main function in a parallel subshell
|
|
|
|
(main) &
|
|
|
|
;;
|
|
|
|
esac
|