From c8216f9bc53d50b25918a08e7664e0be1b28cdd6 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 26 Jun 2018 22:41:03 +0800 Subject: [PATCH] Fix uninstaller --- scripts/flash_script.sh | 9 +-------- scripts/magisk_uninstaller.sh | 20 +++++++++++++++----- scripts/uninstaller_loader.sh | 12 +++++++----- scripts/util_functions.sh | 11 +++++++++++ 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/scripts/flash_script.sh b/scripts/flash_script.sh index f3ddc6b76..da802fcf6 100644 --- a/scripts/flash_script.sh +++ b/scripts/flash_script.sh @@ -76,14 +76,7 @@ remove_system_su ui_print "- Constructing environment" -DATA=false -DATA_DE=false -if grep ' /data ' /proc/mounts | grep -vq 'tmpfs'; then - # Test if data is writable - touch /data/.rw && rm /data/.rw && DATA=true - # Test if DE storage is writable - $DATA && [ -d /data/adb ] && touch /data/adb/.rw && rm /data/adb/.rw && DATA_DE=true -fi +check_data if $DATA; then MAGISKBIN=/data/magisk diff --git a/scripts/magisk_uninstaller.sh b/scripts/magisk_uninstaller.sh index 31d357a30..5a0b4947a 100644 --- a/scripts/magisk_uninstaller.sh +++ b/scripts/magisk_uninstaller.sh @@ -36,17 +36,23 @@ if $BOOTMODE; then . $MAGISKBIN/util_functions.sh BOOTMODE=true boot_actions - mount_partitions fi +mount_partitions + +find_boot_image +find_dtbo_image + +[ -e $BOOTIMAGE ] || abort "! Unable to detect boot image" +ui_print "- Found boot/ramdisk image: $BOOTIMAGE" +[ -z $DTBOIMAGE ] || ui_print "- Found dtbo image: $DTBOIMAGE" + cd $MAGISKBIN -[ -z $BOOTIMAGE ] && abort "! Unable to detect boot image" -ui_print "- Found Boot Image: $BOOTIMAGE" +CHROMEOS=false ui_print "- Unpacking boot image" ./magiskboot --unpack "$BOOTIMAGE" -CHROMEOS=false case $? in 1 ) @@ -71,7 +77,6 @@ ui_print "- Checking ramdisk status" case $? in 0 ) # Stock boot ui_print "- Stock boot image detected" - abort "! Magisk is not installed!" ;; 1|2 ) # Magisk patched ui_print "- Magisk patched image detected" @@ -103,4 +108,9 @@ rm -rf /cache/*magisk* /cache/unblock /data/*magisk* /data/cache/*magisk* /data /data/user*/*/magisk.db /data/user*/*/com.topjohnwu.magisk /data/user*/*/.tmp.magisk.config \ /data/adb/*magisk* 2>/dev/null +if [ -f /system/addon.d/99-magisk.sh ]; then + mount -o rw,remount /system + rm -f /system/addon.d/99-magisk.sh +fi + $BOOTMODE && /system/bin/reboot diff --git a/scripts/uninstaller_loader.sh b/scripts/uninstaller_loader.sh index 1f44744fb..1031bb2f6 100644 --- a/scripts/uninstaller_loader.sh +++ b/scripts/uninstaller_loader.sh @@ -12,11 +12,12 @@ # Preparation ########################################################################################## -BOOTMODE=false # This path should work in any cases TMPDIR=/dev/tmp INSTALLER=$TMPDIR/install +CHROMEDIR=$INSTALLER/chromeos + # Default permissions umask 022 @@ -30,6 +31,7 @@ fi # Load utility functions . $INSTALLER/util_functions.sh + get_outfd ########################################################################################## @@ -42,23 +44,23 @@ ui_print "************************" is_mounted /data || mount /data || abort "! Unable to mount partitions" is_mounted /cache || mount /cache 2>/dev/null -mount_partitions api_level_arch_detect ui_print "- Device platform: $ARCH" -CHROMEDIR=$INSTALLER/chromeos BINDIR=$INSTALLER/$ARCH32 +chmod -R 755 $CHROMEDIR $BINDIR ########################################################################################## # Detection all done, start installing ########################################################################################## -if is_mounted /data; then +check_data + +if $DATA_DE; then recovery_actions # Save our stock boot image dump before removing it mv $MAGISKBIN/stock_boot* /data 2>/dev/null - # Copy the binaries to /data/magisk, in case they do not exist rm -rf $MAGISKBIN 2>/dev/null mkdir -p $MAGISKBIN cp -af $BINDIR/. $CHROMEDIR $TMPDIR/bin/busybox $INSTALLER/util_functions.sh $MAGISKBIN diff --git a/scripts/util_functions.sh b/scripts/util_functions.sh index d0d739572..ac6d2db2a 100644 --- a/scripts/util_functions.sh +++ b/scripts/util_functions.sh @@ -295,6 +295,17 @@ api_level_arch_detect() { if [ "$ABILONG" = "x86_64" ]; then ARCH=x64; ARCH32=x86; IS64BIT=true; fi; } +check_data() { + DATA=false + DATA_DE=false + if grep ' /data ' /proc/mounts | grep -vq 'tmpfs'; then + # Test if data is writable + touch /data/.rw && rm /data/.rw && DATA=true + # Test if DE storage is writable + $DATA && [ -d /data/adb ] && touch /data/adb/.rw && rm /data/adb/.rw && DATA_DE=true + fi +} + setup_bb() { if [ -x /sbin/.core/busybox/busybox ]; then # Make sure this path is in the front