Magisk/scripts/addon.d.sh

113 lines
2.0 KiB
Bash
Raw Normal View History

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
initialize() {
2017-09-26 12:21:43 +00:00
mount /data 2>/dev/null
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
if $BOOTMODE; then
# Override ui_print when booted
ui_print() { log -t Magisk -- "$1"; }
else
OUTFD=
setup_flashable
fi
}
main() {
if ! $backuptool_ab; then
# Wait for post addon.d-v1 processes to finish
sleep 5
fi
$BOOTMODE || recovery_actions
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 "************************"
mount_partitions
check_data
2019-04-06 17:04:17 +00:00
get_flags
if $backuptool_ab; then
# Swap the slot for addon.d-v2
if [ ! -z $SLOT ]; then [ $SLOT = _a ] && SLOT=_b || SLOT=_a; fi
fi
find_boot_image
2018-07-04 15:46:16 +00:00
[ -z $BOOTIMAGE ] && abort "! Unable to detect target image"
ui_print "- Target image: $BOOTIMAGE"
2017-06-18 16:15:44 +00:00
remove_system_su
find_manager_apk
patch_boot_image
2017-09-26 12:21:43 +00:00
2017-06-18 16:15:44 +00:00
cd /
# Cleanups
$BOOTMODE || recovery_cleanup
rm -rf $TMPDIR
2017-06-18 16:15:44 +00:00
ui_print "- Done"
exit 0
}
case "$1" in
backup)
# Stub
;;
restore)
# Stub
;;
pre-backup)
# Stub
;;
post-backup)
# Stub
;;
pre-restore)
# Stub
;;
post-restore)
initialize
if $backuptool_ab; then
$BOOTMODE && su=su || su=sh
exec $su -c "sh $0 addond-v2"
else
# Run in background, hack for addon.d-v1
(main) &
fi
2017-06-18 16:15:44 +00:00
;;
2018-08-03 14:40:49 +00:00
addond-v2)
initialize
main
2018-08-03 14:40:49 +00:00
;;
2017-06-18 16:15:44 +00:00
esac