mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-06 00:55:39 +00:00
Fix boot image backup overwrites when upgrade
This commit is contained in:
parent
54a0e52e05
commit
8f7f1ff7dd
@ -156,6 +156,8 @@ unpack_boot() {
|
|||||||
cd $UNPACKDIR
|
cd $UNPACKDIR
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/bootimgtools --extract $1
|
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/bootimgtools --extract $1
|
||||||
|
|
||||||
|
[ ! -f $UNPACKDIR/ramdisk.gz ] && return 1
|
||||||
|
|
||||||
cd $RAMDISK
|
cd $RAMDISK
|
||||||
gunzip -c < $UNPACKDIR/ramdisk.gz | cpio -i
|
gunzip -c < $UNPACKDIR/ramdisk.gz | cpio -i
|
||||||
}
|
}
|
||||||
@ -164,7 +166,7 @@ repack_boot() {
|
|||||||
cd $RAMDISK
|
cd $RAMDISK
|
||||||
find . | cpio -o -H newc 2>/dev/null | gzip -9 > $UNPACKDIR/ramdisk.gz
|
find . | cpio -o -H newc 2>/dev/null | gzip -9 > $UNPACKDIR/ramdisk.gz
|
||||||
cd $UNPACKDIR
|
cd $UNPACKDIR
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/bootimgtools --repack $ORIGBOOT
|
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/bootimgtools --repack $BOOTIMAGE
|
||||||
if [ -f chromeos ]; then
|
if [ -f chromeos ]; then
|
||||||
echo " " > config
|
echo " " > config
|
||||||
echo " " > bootloader
|
echo " " > bootloader
|
||||||
@ -280,7 +282,7 @@ if (is_mounted /data); then
|
|||||||
/data/magisk/busybox --install -s /data/busybox
|
/data/magisk/busybox --install -s /data/busybox
|
||||||
ln -s /data/magisk/busybox /data/busybox/busybox
|
ln -s /data/magisk/busybox /data/busybox/busybox
|
||||||
# Prevent issues
|
# Prevent issues
|
||||||
rm -f /data/busybox/su /data/busybox/sh
|
rm -f /data/busybox/su /data/busybox/sh /data/busybox/reboot
|
||||||
chcon -hR "u:object_r:system_file:s0" /data/magisk /data/busybox
|
chcon -hR "u:object_r:system_file:s0" /data/magisk /data/busybox
|
||||||
chmod -R 755 /data/magisk /data/busybox
|
chmod -R 755 /data/magisk /data/busybox
|
||||||
PATH=/data/busybox:$PATH
|
PATH=/data/busybox:$PATH
|
||||||
@ -301,10 +303,10 @@ if (is_mounted /data); then
|
|||||||
IMG=/data/magisk.img
|
IMG=/data/magisk.img
|
||||||
else
|
else
|
||||||
IMG=/cache/magisk.img
|
IMG=/cache/magisk.img
|
||||||
ui_print "- Data unavalible, use cache workaround"
|
ui_print "- Data unavailable, use cache workaround"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$IMG" ]; then
|
if [ -f $IMG ]; then
|
||||||
ui_print "- $IMG detected!"
|
ui_print "- $IMG detected!"
|
||||||
else
|
else
|
||||||
ui_print "- Creating $IMG"
|
ui_print "- Creating $IMG"
|
||||||
@ -313,7 +315,7 @@ fi
|
|||||||
|
|
||||||
mount_image $IMG /magisk
|
mount_image $IMG /magisk
|
||||||
if (! is_mounted /magisk); then
|
if (! is_mounted /magisk); then
|
||||||
ui_print "! Image mount failed... abort"
|
ui_print "! Image mount failed..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
MAGISKLOOP=$LOOPDEVICE
|
MAGISKLOOP=$LOOPDEVICE
|
||||||
@ -330,58 +332,61 @@ ui_print "- Found Boot Image: $BOOTIMAGE"
|
|||||||
rm -rf $TMPDIR/boottmp 2>/dev/null
|
rm -rf $TMPDIR/boottmp 2>/dev/null
|
||||||
mkdir -p $TMPDIR/boottmp
|
mkdir -p $TMPDIR/boottmp
|
||||||
|
|
||||||
ORIGBOOT=$BOOTIMAGE
|
|
||||||
|
|
||||||
ui_print "- Unpacking boot image"
|
ui_print "- Unpacking boot image"
|
||||||
unpack_boot $ORIGBOOT
|
unpack_boot $BOOTIMAGE
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
ui_print "! Unable to unpack boot image"
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
# Restore ramdisk
|
# Restore ramdisk
|
||||||
|
ORIGBOOT=
|
||||||
SUPERSU=false
|
SUPERSU=false
|
||||||
|
[ -f sbin/launch_daemonsu.sh ] && SUPERSU=true
|
||||||
if (! $NORESTORE); then
|
if (! $NORESTORE); then
|
||||||
if [ -d ".backup" ]; then
|
if [ -d ".backup" ]; then
|
||||||
# This implies Magisk is already installed, but no SuperSU
|
# This implies Magisk is already installed, and ramdisk backup exists
|
||||||
ui_print "- Restoring ramdisk with ramdisk backup"
|
ui_print "- Restoring ramdisk with ramdisk backup"
|
||||||
cp -af .backup/. .
|
cp -af .backup/. .
|
||||||
rm -rf magisk init.magisk.rc sbin/magic_mask.sh 2>/dev/null
|
rm -rf magisk init.magisk.rc sbin/magic_mask.sh 2>/dev/null
|
||||||
else
|
ORIGBOOT=false
|
||||||
[ -f "sbin/launch_daemonsu.sh" ] && SUPERSU=true
|
elif [ -d "magisk" ]; then
|
||||||
if ($SUPERSU); then
|
|
||||||
ui_print "- SuperSU patched boot detected!"
|
|
||||||
ui_print "- Adding auto patch script for SuperSU"
|
|
||||||
cp -af $INSTALLER/common/custom_ramdisk_patch.sh /data/custom_ramdisk_patch.sh
|
|
||||||
fi
|
|
||||||
if [ -d "magisk" ]; then
|
|
||||||
# If Magisk is installed and not SuperSU and no ramdisk backups,
|
|
||||||
# we restore previous stock boot image backups
|
|
||||||
if (! $SUPERSU); then
|
|
||||||
cp -af /data/stock_boot_*.gz /data/stock_boot.img.gz 2>/dev/null
|
cp -af /data/stock_boot_*.gz /data/stock_boot.img.gz 2>/dev/null
|
||||||
gzip -d /data/stock_boot.img.gz 2>/dev/null
|
gzip -d /data/stock_boot.img.gz 2>/dev/null
|
||||||
if [ -f "/data/stock_boot.img" ]; then
|
[ -f /data/stock_boot.img ] && ORIGBOOT=/data/stock_boot.img
|
||||||
|
# If Magisk is installed and no SuperSU and no ramdisk backups,
|
||||||
|
# we restore previous stock boot image backups
|
||||||
|
if (! $SUPERSU) && [ ! -z $ORIGBOOT ]; then
|
||||||
ui_print "- Restoring boot image with backup"
|
ui_print "- Restoring boot image with backup"
|
||||||
$ORIGBOOT=/data/stock_boot.img
|
|
||||||
unpack_boot $ORIGBOOT
|
unpack_boot $ORIGBOOT
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
# Removing possible modifications
|
# Removing possible modifications
|
||||||
rm -rf magisk init.magisk.rc sbin/magic_mask.sh 2>/dev/null
|
rm -rf magisk init.magisk.rc sbin/magic_mask.sh 2>/dev/null
|
||||||
rm -rf init.xposed.rc sbin/mount_xposed.sh 2>/dev/null
|
rm -rf init.xposed.rc sbin/mount_xposed.sh 2>/dev/null
|
||||||
fi
|
ORIGBOOT=false
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if (! $SUPERSU); then
|
if ($SUPERSU); then
|
||||||
|
ui_print "- SuperSU patched boot detected!"
|
||||||
|
ui_print "- Adding auto patch script for SuperSU"
|
||||||
|
cp -af $INSTALLER/common/custom_ramdisk_patch.sh /data/custom_ramdisk_patch.sh
|
||||||
|
else
|
||||||
# SuperSU already backup stock boot, no need to do again
|
# SuperSU already backup stock boot, no need to do again
|
||||||
ui_print "- Creating backups"
|
ui_print "- Creating ramdisk backup"
|
||||||
mkdir .backup 2>/dev/null
|
mkdir .backup 2>/dev/null
|
||||||
cp -af *fstab* verity_key sepolicy .backup 2>/dev/null
|
cp -af *fstab* verity_key sepolicy .backup 2>/dev/null
|
||||||
|
if [ -z $ORIGBOOT ]; then
|
||||||
|
ui_print "- Creating boot image backup"
|
||||||
if (is_mounted /data); then
|
if (is_mounted /data); then
|
||||||
[ "$ORIGBOOT" != "/data/stock_boot.img" ] && dd if=$ORIGBOOT of=/data/stock_boot.img
|
dd if=$BOOTIMAGE of=/data/stock_boot.img
|
||||||
else
|
else
|
||||||
dd if=$ORIGBOOT of=/cache/stock_boot.img
|
dd if=$BOOTIMAGE of=/cache/stock_boot.img
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# SuperSU already have root, no need to install root
|
# SuperSU already have root, no need to install root
|
||||||
ROOT=
|
ROOT=false
|
||||||
if [ ! -d /magisk/phh ]; then
|
if [ ! -d /magisk/phh ]; then
|
||||||
ui_print "- Installing phh's SuperUser"
|
ui_print "- Installing phh's SuperUser"
|
||||||
ROOT=true
|
ROOT=true
|
||||||
@ -390,7 +395,7 @@ if (! $SUPERSU); then
|
|||||||
ROOT=true
|
ROOT=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -z $ROOT ]; then
|
if ($ROOT); then
|
||||||
mkdir -p /magisk/phh/bin 2>/dev/null
|
mkdir -p /magisk/phh/bin 2>/dev/null
|
||||||
mkdir -p /magisk/phh/su.d 2>/dev/null
|
mkdir -p /magisk/phh/su.d 2>/dev/null
|
||||||
cp -af $INSTALLER/common/phh/. /magisk/phh
|
cp -af $INSTALLER/common/phh/. /magisk/phh
|
||||||
@ -404,7 +409,7 @@ ui_print "- Patching ramdisk"
|
|||||||
|
|
||||||
# Add magisk entrypoint
|
# Add magisk entrypoint
|
||||||
for INIT in init*.rc; do
|
for INIT in init*.rc; do
|
||||||
if [ $(grep -c "import /init.environ.rc" $INIT) -ne "0" ] && [ `grep -c "import /init.magisk.rc" $INIT` -eq "0" ]; then
|
if [ `grep -c "import /init.environ.rc" $INIT` -ne "0" ] && [ `grep -c "import /init.magisk.rc" $INIT` -eq "0" ]; then
|
||||||
cp $INIT .backup
|
cp $INIT .backup
|
||||||
sed -i "/import \/init\.environ\.rc/iimport /init.magisk.rc" $INIT
|
sed -i "/import \/init\.environ\.rc/iimport /init.magisk.rc" $INIT
|
||||||
break
|
break
|
||||||
@ -460,7 +465,7 @@ fi
|
|||||||
chmod 644 $NEWBOOT
|
chmod 644 $NEWBOOT
|
||||||
|
|
||||||
ui_print "- Flashing new boot image"
|
ui_print "- Flashing new boot image"
|
||||||
[ ! -L "$BOOTIMAGE" ] && dd if=/dev/zero of=$BOOTIMAGE bs=4096 2>/dev/null
|
[ ! -L $BOOTIMAGE ] && dd if=/dev/zero of=$BOOTIMAGE bs=4096 2>/dev/null
|
||||||
dd if=$NEWBOOT of=$BOOTIMAGE bs=4096
|
dd if=$NEWBOOT of=$BOOTIMAGE bs=4096
|
||||||
|
|
||||||
if (! $BOOTMODE); then
|
if (! $BOOTMODE); then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user