mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-12 05:07:45 +02:00
Add addon.d survival script
This commit is contained in:
100
scripts/addon.d.sh
Normal file
100
scripts/addon.d.sh
Normal file
@ -0,0 +1,100 @@
|
||||
#!/sbin/sh
|
||||
##########################################################################################
|
||||
#
|
||||
# Magisk Survival Script for ROMs with addon.d support
|
||||
# by topjohnwu
|
||||
#
|
||||
# Inspired by 99-flashafterupdate.sh of osm0sis @ xda-developers
|
||||
#
|
||||
##########################################################################################
|
||||
|
||||
. /tmp/backuptool.functions
|
||||
|
||||
main() {
|
||||
# Magisk binaries
|
||||
MAGISKBIN=/data/magisk
|
||||
# This script always run in recovery
|
||||
BOOTMODE=false
|
||||
|
||||
# Wait for post addon.d processes to finish
|
||||
sleep 5
|
||||
|
||||
mount -o ro /system 2>/dev/null
|
||||
mount /data 2>/dev/null
|
||||
|
||||
if [ ! -d $MAGISKBIN ]; then
|
||||
echo "! Cannot find Magisk binaries!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Load all functions
|
||||
. $MAGISKBIN/util_functions.sh
|
||||
|
||||
[ -f /system/build.prop ] || abort "! /system could not be mounted!"
|
||||
|
||||
ui_print "************************"
|
||||
ui_print "* MAGISK_VERSION_STUB"
|
||||
ui_print "************************"
|
||||
|
||||
# Check if system root is installed and remove
|
||||
remove_system_su
|
||||
# Prefer bin in /system
|
||||
export PATH=/system/bin:/system/xbin
|
||||
# Clear out possible lib paths, let the binary find them itself
|
||||
export LD_LIBRARY_PATH=
|
||||
# Temporarily block out all custom recovery binaries/libs
|
||||
mv /sbin /sbin_tmp
|
||||
|
||||
find_boot_image
|
||||
[ -z $BOOTIMAGE ] && abort "! Unable to detect boot image"
|
||||
ui_print "- Found Boot Image: $BOOTIMAGE"
|
||||
|
||||
SOURCEDMODE=true
|
||||
cd $MAGISKBIN
|
||||
|
||||
# Source the boot patcher
|
||||
. $MAGISKBIN/boot_patch.sh $BOOTIMAGE
|
||||
|
||||
[ -f stock_boot* ] && rm -f /data/stock_boot* 2>/dev/null
|
||||
|
||||
ui_print "- Flashing new boot image"
|
||||
if [ -L "$BOOTIMAGE" ]; then
|
||||
dd if=new-boot.img of="$BOOTIMAGE" bs=4096
|
||||
else
|
||||
cat new-boot.img /dev/zero | dd of="$BOOTIMAGE" bs=4096
|
||||
fi
|
||||
rm -f new-boot.img
|
||||
|
||||
cd /
|
||||
|
||||
mv /sbin_tmp /sbin
|
||||
ui_print "- Unmounting partitions"
|
||||
umount -l /system
|
||||
|
||||
ui_print "- Done"
|
||||
exit 0
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
backup)
|
||||
# Stub
|
||||
;;
|
||||
restore)
|
||||
# Stub
|
||||
;;
|
||||
pre-backup)
|
||||
# Stub
|
||||
;;
|
||||
post-backup)
|
||||
# Stub
|
||||
;;
|
||||
pre-restore)
|
||||
# Stub
|
||||
;;
|
||||
post-restore)
|
||||
# Get the FD for ui_print
|
||||
OUTFD=`ps | grep -v grep | grep -oE "update(.*)" | cut -d" " -f3`
|
||||
# Run the main function in a parallel subshell
|
||||
(main) &
|
||||
;;
|
||||
esac
|
Reference in New Issue
Block a user