Magisk/scripts/addon.d.sh

136 lines
2.5 KiB
Bash
Raw Normal View History

2017-06-18 18:15:44 +02:00
#!/sbin/sh
##########################################################################################
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
##########################################################################################
. /tmp/backuptool.functions
[ -z $backuptool_ab ] && backuptool_ab=false
2017-06-18 18:15:44 +02:00
initialize() {
# This path should work in any cases
TMPDIR=/dev/tmp
2017-06-18 18:15:44 +02:00
2017-09-26 14:21:43 +02:00
mount /data 2>/dev/null
MAGISKBIN=/data/adb/magisk
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
APK=/data/adb/magisk.apk
2018-08-02 21:43:02 +02:00
[ -f $APK ] || APK=/data/magisk/magisk.apk
[ -f $APK ] || APK=/data/app/com.topjohnwu.magisk*/*.apk
}
show_logo() {
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 "************************"
}
2017-06-18 18:15:44 +02:00
detection() {
find_boot_image
find_dtbo_image
2018-07-04 17:46:16 +02:00
[ -z $BOOTIMAGE ] && abort "! Unable to detect target image"
ui_print "- Target image: $BOOTIMAGE"
[ -z $DTBOIMAGE ] || ui_print "- DTBO image: $DTBOIMAGE"
get_flags
}
2017-06-18 18:15:44 +02:00
installation() {
remove_system_su
[ -f $APK ] && eval $BOOTSIGNER -verify < $BOOTIMAGE && BOOTSIGNED=true
$BOOTSIGNED && ui_print "- Boot image is signed with AVB 1.0"
2017-06-18 18:15:44 +02:00
SOURCEDMODE=true
cd $MAGISKBIN
# Source the boot patcher
. ./boot_patch.sh "$BOOTIMAGE"
2017-06-18 18:15:44 +02:00
2017-11-10 18:33:50 +01:00
flash_boot_image new-boot.img "$BOOTIMAGE"
rm -f new-boot.img
2017-09-26 14:21:43 +02:00
if [ -f stock_boot* ]; then
rm -f /data/stock_boot* 2>/dev/null
$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 18:15:44 +02:00
fi
2017-09-26 14:21:43 +02:00
2017-06-18 18:15:44 +02:00
cd /
}
2017-06-18 18:15:44 +02:00
finalize() {
2017-06-18 18:15:44 +02:00
ui_print "- Done"
exit 0
}
main_v1() {
# Wait for post addon.d processes to finish
sleep 5
recovery_actions
show_logo
mount_partitions
detection
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
detection
installation
finalize
}
2017-06-18 18:15:44 +02:00
case "$1" in
backup)
# Stub
;;
restore)
# Stub
;;
pre-backup)
# Stub
;;
post-backup)
# Stub
;;
pre-restore)
# Stub
;;
post-restore)
initialize
if $backuptool_ab; then
# addon.d-v2
main_v2
else
2018-07-05 11:29:13 +02:00
OUTFD=
get_outfd
# Run in background, hack for addon.d-v1
(main_v1) &
fi
2017-06-18 18:15:44 +02:00
;;
esac