scripts: prepare addon.d for recovery addon.d-v2 support

- naturally there's no `su` in recovery
- major refactor for common actions and simplicity
This commit is contained in:
Chris Renshaw 2019-08-31 13:28:00 -03:00 committed by John Wu
parent dca3fe396f
commit 1283590eeb

View File

@ -33,6 +33,14 @@ initialize() {
# Load utility functions # Load utility functions
. $MAGISKBIN/util_functions.sh . $MAGISKBIN/util_functions.sh
if $BOOTMODE; then
# Override ui_print when booted
ui_print() { log -t Magisk -- "$1"; }
else
OUTFD=
setup_flashable
fi
} }
show_logo() { show_logo() {
@ -85,23 +93,20 @@ finalize() {
exit 0 exit 0
} }
main_v1() { main() {
# Wait for post addon.d processes to finish if ! $backuptool_ab; then
sleep 5 # Wait for post addon.d-v1 processes to finish
recovery_actions sleep 5
fi
$BOOTMODE || recovery_actions
show_logo show_logo
mount_partitions mount_partitions
if $backuptool_ab; then
# Swap the slot for addon.d-v2
if [ ! -z $SLOT ]; then [ $SLOT = _a ] && SLOT=_b || SLOT=_a; fi
fi
installation installation
recovery_cleanup $BOOTMODE || recovery_cleanup
finalize
}
main_v2() {
show_logo
mount_partitions
# Swap the slot
if [ ! -z $SLOT ]; then [ $SLOT = _a ] && SLOT=_b || SLOT=_a; fi
installation
finalize finalize
} }
@ -122,21 +127,17 @@ case "$1" in
# Stub # Stub
;; ;;
post-restore) post-restore)
initialize
if $backuptool_ab; then if $backuptool_ab; then
exec su -c "sh $0 addond-v2" $BOOTMODE && su=su || su=sh
exec $su -c "sh $0 addond-v2"
else else
initialize
OUTFD=
setup_flashable
# Run in background, hack for addon.d-v1 # Run in background, hack for addon.d-v1
(main_v1) & (main) &
fi fi
;; ;;
addond-v2) addond-v2)
initialize initialize
# Override ui_print main
ui_print() { log -t Magisk -- "$1"; }
# addon.d-v2
main_v2
;; ;;
esac esac