From ac28e6e5ca0c39375d9d78cc9711328c1727f1f5 Mon Sep 17 00:00:00 2001 From: osm0sis Date: Wed, 8 May 2019 20:06:29 -0300 Subject: [PATCH] Fix uninstaller missing recent changes - group unsupported formats into the same code (https://github.com/topjohnwu/Magisk/commit/86f778c0aa21f1cc7a358331c102180488b3351b#diff-93690a8d9f50c177ef97416af3be8726) - support A only system-as-root devices (https://github.com/topjohnwu/Magisk/commit/e72c6685edf81706617a3444575c4500b9b8fe6c#diff-93690a8d9f50c177ef97416af3be8726) - remove unnecessary '--' from magiskboot actions (https://github.com/topjohnwu/Magisk/commit/7f08c0694392ede38ebbb6bd835757f2b3c3c477#diff-93690a8d9f50c177ef97416af3be8726) - get_flags need to be before find_boot_image (https://github.com/topjohnwu/Magisk/commit/a4f5d47e72158a559bd4b47e70bf7ba1126b2dbd) closes #1371, closes #1431, closes #1439 --- app/src/main/res/raw/utils.sh | 1 + scripts/magisk_uninstaller.sh | 36 +++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/app/src/main/res/raw/utils.sh b/app/src/main/res/raw/utils.sh index 66d2cafe1..4e2a298a1 100644 --- a/app/src/main/res/raw/utils.sh +++ b/app/src/main/res/raw/utils.sh @@ -55,6 +55,7 @@ restore_imgs() { local STOCKDTBO=/data/stock_dtbo.img.gz [ -f $STOCKBOOT ] || return 1 + get_flags find_boot_image find_dtbo_image diff --git a/scripts/magisk_uninstaller.sh b/scripts/magisk_uninstaller.sh index 8a9fd2410..0fb59b9ff 100644 --- a/scripts/magisk_uninstaller.sh +++ b/scripts/magisk_uninstaller.sh @@ -55,6 +55,7 @@ $BOOTMODE || recovery_actions # Uninstall ########################################################################################## +get_flags find_boot_image find_dtbo_image @@ -67,36 +68,35 @@ cd $MAGISKBIN CHROMEOS=false ui_print "- Unpacking boot image" -./magiskboot --unpack "$BOOTIMAGE" +./magiskboot unpack "$BOOTIMAGE" case $? in 1 ) - abort "! Unable to unpack boot image" + abort "! Unsupported/Unknown image format" ;; 2 ) ui_print "- ChromeOS boot image detected" CHROMEOS=true ;; - 3 ) - ui_print "! Sony ELF32 format detected" - abort "! Please use BootBridge from @AdrianDC" - ;; - 4 ) - ui_print "! Sony ELF64 format detected" - abort "! Stock kernel cannot be patched, please use a custom kernel" esac # Detect boot image state ui_print "- Checking ramdisk status" -./magiskboot --cpio ramdisk.cpio test -case $? in +if [ -e ramdisk.cpio ]; then + ./magiskboot cpio ramdisk.cpio test + STATUS=$? +else + # Stock A only system-as-root + STATUS=0 +fi +case $((STATUS & 3)) in 0 ) # Stock boot ui_print "- Stock boot image detected" ;; 1 ) # Magisk patched ui_print "- Magisk patched image detected" # Find SHA1 of stock boot image - [ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null` + [ -z $SHA1 ] && SHA1=`./magiskboot cpio ramdisk.cpio sha1 2>/dev/null` STOCKBOOT=/data/stock_boot_${SHA1}.img.gz STOCKDTBO=/data/stock_dtbo.img.gz if [ -f $STOCKBOOT ]; then @@ -109,16 +109,20 @@ case $? in else ui_print "! Boot image backup unavailable" ui_print "- Restoring ramdisk with internal backup" - ./magiskboot --cpio ramdisk.cpio restore - ./magiskboot --repack $BOOTIMAGE + ./magiskboot cpio ramdisk.cpio restore + if ! ./magiskboot cpio ramdisk.cpio "exists init.rc"; then + # A only system-as-root + rm -f ramdisk.cpio + fi + ./magiskboot repack $BOOTIMAGE # Sign chromeos boot $CHROMEOS && sign_chromeos ui_print "- Flashing restored boot image" flash_image new-boot.img $BOOTIMAGE || abort "! Insufficient partition size" fi ;; - 2 ) # Other patched - ui_print "! Boot image patched by other programs" + 2 ) # Unsupported + ui_print "! Boot image patched by unsupported programs" abort "! Cannot uninstall" ;; esac