Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy required files to system for addon.d #3037

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 7 additions & 34 deletions scripts/addon.d.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,8 @@
#
########################################################

trampoline() {
mount /data 2>/dev/null
if [ -f $MAGISKBIN/addon.d.sh ]; then
exec sh $MAGISKBIN/addon.d.sh "$@"
exit $?
elif [ "$1" = post-restore ]; then
ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true || BOOTMODE=false
$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
ui_print() { $BOOTMODE && log -t Magisk -- "$1" || 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
exit 1
}

# Always use the script in /data
MAGISKBIN=/data/adb/magisk
[ "$0" = $MAGISKBIN/addon.d.sh ] || trampoline "$@"
ADDOND=$S/addon.d
MAGISKTMP=/tmp/magisk

V1_FUNCS=/tmp/backuptool.functions
V2_FUNCS=/postinstall/tmp/backuptool.functions
Expand All @@ -53,7 +24,8 @@ fi

initialize() {
# Load utility functions
. $MAGISKBIN/util_functions.sh
. $MAGISKTMP/util_functions.sh
MAGISKBIN=$MAGISKTMP

if $BOOTMODE; then
# Override ui_print when booted
Expand Down Expand Up @@ -81,8 +53,8 @@ main() {
fi
print_title "Magisk $PRETTY_VER addon.d"

is_mounted /data || mount /data 2>/dev/null
mount_partitions
check_data
get_flags

if $backuptool_ab; then
Expand Down Expand Up @@ -110,7 +82,8 @@ main() {

case "$1" in
backup)
# Stub
cp -af $ADDOND/magisk $MAGISKTMP
mv $MAGISKTMP/boot_patch.sh.in $MAGISKTMP/boot_patch.sh
;;
restore)
# Stub
Expand Down
10 changes: 7 additions & 3 deletions scripts/flash_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ if [ -d /system/addon.d ]; then
ui_print "- Adding addon.d survival script"
blockdev --setrw /dev/block/mapper/system$SLOT 2>/dev/null
mount -o rw,remount /system
ADDOND=/system/addon.d/99-magisk.sh
cp -af $COMMONDIR/addon.d.sh $ADDOND
chmod 755 $ADDOND
ADDOND=/system/addon.d
rm -rf $ADDOND/99-magisk.sh 2>/dev/null
rm -rf $ADDOND/magisk 2>/dev/null
mkdir -p $ADDOND/magisk
cp -af $MAGISKBIN/. $ADDOND/magisk
mv $ADDOND/magisk/boot_patch.sh $ADDOND/magisk/boot_patch.sh.in
mv $ADDOND/magisk/addon.d.sh $ADDOND/99-magisk.sh
fi

$BOOTMODE || recovery_actions
Expand Down
29 changes: 17 additions & 12 deletions scripts/util_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,25 @@ mount_partitions() {
fi
[ -z $SLOT ] || ui_print "- Current boot slot: $SLOT"

# Mount ro partitions
mount_ro_ensure "system$SLOT app$SLOT" /system
if [ -f /system/init -o -L /system/init ]; then
SYSTEM_ROOT=true
setup_mntpoint /system_root
if ! mount --move /system /system_root; then
umount /system
umount -l /system 2>/dev/null
mount_ro_ensure "system$SLOT app$SLOT" /system_root
if [ -z $S ] || [ $S == "/system" ] || [ $S == "/system/system" ]; then
# Mount ro partitions
mount_ro_ensure "system$SLOT app$SLOT" /system
if [ -f /system/init -o -L /system/init ]; then
SYSTEM_ROOT=true
setup_mntpoint /system_root
if ! mount --move /system /system_root; then
umount /system
umount -l /system 2>/dev/null
mount_ro_ensure "system$SLOT app$SLOT" /system_root
fi
mount -o bind /system_root/system /system
else
grep ' / ' /proc/mounts | grep -qv 'rootfs' || grep -q ' /system_root ' /proc/mounts \
&& SYSTEM_ROOT=true || SYSTEM_ROOT=false
fi
mount -o bind /system_root/system /system
else
grep ' / ' /proc/mounts | grep -qv 'rootfs' || grep -q ' /system_root ' /proc/mounts \
&& SYSTEM_ROOT=true || SYSTEM_ROOT=false
SYSTEM_ROOT=true
mount -o bind $S /system
fi
# /vendor is used only on some older devices for recovery AVBv1 signing so is not critical if fails
[ -L /system/vendor ] && mount_name vendor$SLOT /vendor '-o ro'
Expand Down