diff --git a/scripts/addon.d.sh b/scripts/addon.d.sh index dc01b2d46..3829dd4f2 100644 --- a/scripts/addon.d.sh +++ b/scripts/addon.d.sh @@ -1,11 +1,34 @@ -########################################################################################## +#!/sbin/sh +# ADDOND_VERSION=2 +######################################################## # # Magisk Survival Script for ROMs with addon.d support -# by topjohnwu +# by topjohnwu and osm0sis # -# Inspired by 99-flashafterupdate.sh of osm0sis @ xda-developers -# -########################################################################################## +######################################################## + +trampoline() { + mount /data 2>/dev/null + if [ -f /data/adb/magisk/addon.d.sh ]; then + exec sh /data/adb/magisk/addon.d.sh "$@" + else + OUTFD=$(ps | grep -v 'grep' | grep -oE 'update(.*)' | cut -d" " -f3) + [ "$OUTFD" -eq "$OUTFD" ] 2>/dev/null || OUTFD=$(ps -Af | grep -v 'grep' | grep -oE 'update(.*)' | cut -d" " -f3) + [ "$OUTFD" -eq "$OUTFD" ] 2>/dev/null || OUTFD=$(ps | grep -v 'grep' | grep -oE 'status_fd=(.*)' | cut -d= -f2) + [ "$OUTFD" -eq "$OUTFD" ] 2>/dev/null || OUTFD=$(ps -Af | grep -v 'grep' | grep -oE 'status_fd=(.*)' | cut -d= -f2) + ui_print() { echo -e "ui_print $1\nui_print" >> /proc/self/fd/$OUTFD; } + + ui_print "************************" + ui_print "* Magisk addon.d failed" + ui_print "************************" + ui_print "! Cannot find Magisk binaries - was data wiped or not decrypted?" + ui_print "! Reflash OTA from decrypted recovery or reflash Magisk" + exit 1 + fi +} + +# Always use the script in /data +[ "$0" = /data/adb/magisk/addon.d.sh ] || trampoline V1_FUNCS=/tmp/backuptool.functions V2_FUNCS=/postinstall/system/bin/backuptool_ab.functions diff --git a/scripts/flash_script.sh b/scripts/flash_script.sh index 4aa144070..9fd539f7f 100644 --- a/scripts/flash_script.sh +++ b/scripts/flash_script.sh @@ -80,28 +80,7 @@ if [ -d /system/addon.d ]; then ui_print "- Adding addon.d survival script" mount -o rw,remount /system ADDOND=/system/addon.d/99-magisk.sh - cat <<'EOF' > $ADDOND -#!/sbin/sh -# ADDOND_VERSION=2 - -mount /data 2>/dev/null - -if [ -f /data/adb/magisk/addon.d.sh ]; then - exec sh /data/adb/magisk/addon.d.sh "$@" -else - OUTFD=$(ps | grep -v 'grep' | grep -oE 'update(.*)' | cut -d" " -f3) - [ ! -z $OUTFD -a "$OUTFD" -eq "$OUTFD" ] 2>/dev/null || OUTFD=$(ps -Af | grep -v 'grep' | grep -oE 'update(.*)' | cut -d" " -f3) - [ ! -z $OUTFD -a "$OUTFD" -eq "$OUTFD" ] 2>/dev/null || OUTFD=$(ps | grep -v 'grep' | grep -oE 'status_fd=(.*)' | cut -d= -f2) - [ ! -z $OUTFD -a "$OUTFD" -eq "$OUTFD" ] 2>/dev/null || OUTFD=$(ps -Af | grep -v 'grep' | grep -oE 'status_fd=(.*)' | cut -d= -f2) - ui_print() { echo -e "ui_print $1\nui_print" >> /proc/self/fd/$OUTFD; } - - ui_print "************************" - ui_print "* Magisk addon.d failed" - ui_print "************************" - ui_print "! Cannot find Magisk binaries - was data wiped or not decrypted?" - ui_print "! Reflash OTA from decrypted recovery or reflash Magisk" -fi -EOF + cp -af $COMMONDIR/addon.d.sh $ADDOND chmod 755 $ADDOND fi