2020-02-09 11:07:49 +00:00
|
|
|
#!/sbin/sh
|
|
|
|
# ADDOND_VERSION=2
|
|
|
|
########################################################
|
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
|
2020-02-09 11:07:49 +00:00
|
|
|
# by topjohnwu and osm0sis
|
2017-07-30 19:03:52 +00:00
|
|
|
#
|
2020-02-09 11:07:49 +00:00
|
|
|
########################################################
|
|
|
|
|
|
|
|
trampoline() {
|
|
|
|
mount /data 2>/dev/null
|
2020-02-13 06:53:10 +00:00
|
|
|
if [ -f $MAGISKBIN/addon.d.sh ]; then
|
|
|
|
exec sh $MAGISKBIN/addon.d.sh "$@"
|
|
|
|
exit $?
|
2020-04-02 16:42:38 +00:00
|
|
|
elif [ "$1" = post-restore ]; then
|
2020-11-30 00:35:34 +00:00
|
|
|
BOOTMODE=false
|
|
|
|
ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true
|
2020-02-13 06:53:10 +00:00
|
|
|
$BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMODE=true
|
|
|
|
|
|
|
|
if ! $BOOTMODE; then
|
|
|
|
# update-binary|updater <RECOVERY_API_VERSION> <OUTFD> <ZIPFILE>
|
|
|
|
OUTFD=$(ps | grep -v 'grep' | grep -oE 'update(.*) 3 [0-9]+' | cut -d" " -f3)
|
|
|
|
[ -z $OUTFD ] && OUTFD=$(ps -Af | grep -v 'grep' | grep -oE 'update(.*) 3 [0-9]+' | cut -d" " -f3)
|
|
|
|
# update_engine_sideload --payload=file://<ZIPFILE> --offset=<OFFSET> --headers=<HEADERS> --status_fd=<OUTFD>
|
|
|
|
[ -z $OUTFD ] && OUTFD=$(ps | grep -v 'grep' | grep -oE 'status_fd=[0-9]+' | cut -d= -f2)
|
|
|
|
[ -z $OUTFD ] && OUTFD=$(ps -Af | grep -v 'grep' | grep -oE 'status_fd=[0-9]+' | cut -d= -f2)
|
|
|
|
fi
|
2020-11-30 00:35:34 +00:00
|
|
|
ui_print() {
|
|
|
|
if $BOOTMODE; then
|
|
|
|
log -t Magisk -- "$1"
|
|
|
|
else
|
|
|
|
echo -e "ui_print $1\nui_print" >> /proc/self/fd/$OUTFD
|
|
|
|
fi
|
|
|
|
}
|
2020-02-09 11:07:49 +00:00
|
|
|
|
2020-03-20 10:44:08 +00:00
|
|
|
ui_print "***********************"
|
|
|
|
ui_print " Magisk addon.d failed"
|
|
|
|
ui_print "***********************"
|
2020-02-09 11:07:49 +00:00
|
|
|
ui_print "! Cannot find Magisk binaries - was data wiped or not decrypted?"
|
|
|
|
ui_print "! Reflash OTA from decrypted recovery or reflash Magisk"
|
|
|
|
fi
|
2020-04-02 16:42:38 +00:00
|
|
|
exit 1
|
2020-02-09 11:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Always use the script in /data
|
2020-02-13 06:53:10 +00:00
|
|
|
MAGISKBIN=/data/adb/magisk
|
|
|
|
[ "$0" = $MAGISKBIN/addon.d.sh ] || trampoline "$@"
|
2017-06-18 16:15:44 +00:00
|
|
|
|
2018-08-03 14:40:49 +00:00
|
|
|
V1_FUNCS=/tmp/backuptool.functions
|
2020-02-13 06:53:10 +00:00
|
|
|
V2_FUNCS=/postinstall/tmp/backuptool.functions
|
2018-08-03 14:40:49 +00:00
|
|
|
|
|
|
|
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() {
|
2017-07-09 16:17:34 +00:00
|
|
|
# Load utility functions
|
2017-06-18 16:15:44 +00:00
|
|
|
. $MAGISKBIN/util_functions.sh
|
2019-08-31 16:28:00 +00:00
|
|
|
|
|
|
|
if $BOOTMODE; then
|
|
|
|
# Override ui_print when booted
|
|
|
|
ui_print() { log -t Magisk -- "$1"; }
|
|
|
|
fi
|
2020-03-09 05:25:06 +00:00
|
|
|
OUTFD=
|
|
|
|
setup_flashable
|
2018-06-21 02:53:49 +00:00
|
|
|
}
|
|
|
|
|
2019-11-02 03:26:08 +00:00
|
|
|
main() {
|
|
|
|
if ! $backuptool_ab; then
|
|
|
|
# Wait for post addon.d-v1 processes to finish
|
|
|
|
sleep 5
|
|
|
|
fi
|
|
|
|
|
2019-11-03 01:50:33 +00:00
|
|
|
# Ensure we aren't in /tmp/addon.d anymore (since it's been deleted by addon.d)
|
2020-08-19 02:04:39 +00:00
|
|
|
mkdir -p $TMPDIR
|
2019-11-03 01:50:33 +00:00
|
|
|
cd $TMPDIR
|
|
|
|
|
2019-11-02 03:26:08 +00:00
|
|
|
$BOOTMODE || recovery_actions
|
|
|
|
|
2020-03-23 08:17:13 +00:00
|
|
|
if echo $MAGISK_VER | grep -q '\.'; then
|
|
|
|
PRETTY_VER=$MAGISK_VER
|
|
|
|
else
|
|
|
|
PRETTY_VER="$MAGISK_VER($MAGISK_VER_CODE)"
|
|
|
|
fi
|
2020-03-09 05:25:06 +00:00
|
|
|
print_title "Magisk $PRETTY_VER addon.d"
|
2017-06-18 16:15:44 +00:00
|
|
|
|
2019-11-02 03:26:08 +00:00
|
|
|
mount_partitions
|
|
|
|
check_data
|
2019-04-06 17:04:17 +00:00
|
|
|
get_flags
|
2019-11-02 03:26:08 +00:00
|
|
|
|
|
|
|
if $backuptool_ab; then
|
|
|
|
# Swap the slot for addon.d-v2
|
2020-11-30 00:35:34 +00:00
|
|
|
if [ ! -z $SLOT ]; then
|
|
|
|
case $SLOT in
|
|
|
|
_a) SLOT=_b;;
|
|
|
|
_b) SLOT=_a;;
|
|
|
|
esac
|
|
|
|
fi
|
2019-11-02 03:26:08 +00:00
|
|
|
fi
|
|
|
|
|
2018-06-21 02:53:49 +00:00
|
|
|
find_boot_image
|
2019-11-02 03:26:08 +00:00
|
|
|
|
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
|
|
|
|
2018-07-19 16:37:38 +00:00
|
|
|
remove_system_su
|
2021-03-21 22:25:56 +00:00
|
|
|
find_magisk_apk
|
2020-01-01 06:02:44 +00:00
|
|
|
install_magisk
|
2017-09-26 12:21:43 +00:00
|
|
|
|
2019-11-02 03:26:08 +00:00
|
|
|
# Cleanups
|
2020-02-13 06:53:10 +00:00
|
|
|
cd /
|
2019-11-02 03:26:08 +00:00
|
|
|
$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)
|
2019-08-31 16:28:00 +00:00
|
|
|
initialize
|
2018-06-21 02:53:49 +00:00
|
|
|
if $backuptool_ab; then
|
2020-11-30 00:35:34 +00:00
|
|
|
su=sh
|
|
|
|
$BOOTMODE && su=su
|
2019-08-31 16:28:00 +00:00
|
|
|
exec $su -c "sh $0 addond-v2"
|
2018-06-21 02:53:49 +00:00
|
|
|
else
|
|
|
|
# Run in background, hack for addon.d-v1
|
2019-08-31 16:28:00 +00:00
|
|
|
(main) &
|
2018-06-21 02:53:49 +00:00
|
|
|
fi
|
2017-06-18 16:15:44 +00:00
|
|
|
;;
|
2018-08-03 14:40:49 +00:00
|
|
|
addond-v2)
|
|
|
|
initialize
|
2019-08-31 16:28:00 +00:00
|
|
|
main
|
2018-08-03 14:40:49 +00:00
|
|
|
;;
|
2017-06-18 16:15:44 +00:00
|
|
|
esac
|