2017-06-03 18:03:36 +02:00
|
|
|
#!/system/bin/sh
|
|
|
|
##########################################################################################
|
|
|
|
#
|
|
|
|
# Magisk Uninstaller
|
|
|
|
# by topjohnwu
|
2017-07-24 20:02:19 +02:00
|
|
|
#
|
2017-06-03 18:03:36 +02:00
|
|
|
# This script can be placed in /cache/magisk_uninstaller.sh
|
|
|
|
# The Magisk main binary will pick up the script, and uninstall itself, following a reboot
|
|
|
|
# This script can also be used in flashable zip with the uninstaller_loader.sh
|
2017-07-24 20:02:19 +02:00
|
|
|
#
|
2017-07-09 18:17:34 +02:00
|
|
|
# This script will try to do restoration with the following:
|
|
|
|
# 1-1. Find and restore the original stock boot image dump (OTA proof)
|
|
|
|
# 1-2. If 1-1 fails, restore ramdisk from the internal backup
|
|
|
|
# (ramdisk fully restored, not OTA friendly)
|
|
|
|
# 1-3. If 1-2 fails, it will remove added files in ramdisk, however modified files
|
2017-07-24 20:02:19 +02:00
|
|
|
# are remained modified, because we have no backups. By doing so, Magisk will
|
2017-07-09 18:17:34 +02:00
|
|
|
# not be started at boot, but this isn't actually 100% cleaned up
|
|
|
|
# 2. Remove all Magisk related files
|
|
|
|
# (The list is LARGE, most likely due to bad decision in early versions
|
|
|
|
# the latest versions has much less bloat to cleanup)
|
2017-06-03 18:03:36 +02:00
|
|
|
#
|
|
|
|
##########################################################################################
|
|
|
|
|
2017-07-09 18:17:34 +02:00
|
|
|
[ -z $BOOTMODE ] && BOOTMODE=false
|
|
|
|
|
2017-12-15 19:02:17 +01:00
|
|
|
[ -d /data/adb/magisk ] && MAGISKBIN=/data/adb/magisk || MAGISKBIN=/data/magisk
|
2017-07-09 18:17:34 +02:00
|
|
|
CHROMEDIR=$MAGISKBIN/chromeos
|
2017-02-05 20:22:37 +01:00
|
|
|
|
2017-08-01 20:21:50 +02:00
|
|
|
if [ ! -f $MAGISKBIN/magiskboot -o ! -f $MAGISKBIN/util_functions.sh ]; then
|
2017-09-06 10:13:23 +02:00
|
|
|
echo "! Cannot find $MAGISKBIN"
|
2017-08-01 20:21:50 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-09-15 21:48:58 +02:00
|
|
|
if $BOOTMODE; then
|
|
|
|
# Load utility functions
|
|
|
|
. $MAGISKBIN/util_functions.sh
|
2018-01-01 09:46:28 +01:00
|
|
|
BOOTMODE=true
|
2017-09-15 21:48:58 +02:00
|
|
|
boot_actions
|
|
|
|
mount_partitions
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd $MAGISKBIN
|
2017-02-05 20:22:37 +01:00
|
|
|
|
2017-07-09 18:17:34 +02:00
|
|
|
[ -z $BOOTIMAGE ] && abort "! Unable to detect boot image"
|
2017-09-06 10:13:23 +02:00
|
|
|
ui_print "- Found Boot Image: $BOOTIMAGE"
|
2017-02-05 20:22:37 +01:00
|
|
|
|
2017-09-06 10:13:23 +02:00
|
|
|
ui_print "- Unpacking boot image"
|
2017-07-09 18:17:34 +02:00
|
|
|
./magiskboot --unpack "$BOOTIMAGE"
|
2017-07-18 09:07:39 +02:00
|
|
|
CHROMEOS=false
|
2017-12-11 20:04:55 +01:00
|
|
|
|
2017-07-18 09:07:39 +02:00
|
|
|
case $? in
|
|
|
|
1 )
|
2017-09-06 10:13:23 +02:00
|
|
|
abort "! Unable to unpack boot image"
|
2017-07-18 09:07:39 +02:00
|
|
|
;;
|
2017-12-11 20:04:55 +01:00
|
|
|
3 )
|
|
|
|
ui_print "- ChromeOS boot image detected"
|
2017-07-18 09:07:39 +02:00
|
|
|
CHROMEOS=true
|
|
|
|
;;
|
2017-12-11 20:04:55 +01:00
|
|
|
4 )
|
2017-09-06 10:13:23 +02:00
|
|
|
ui_print "! Sony ELF32 format detected"
|
|
|
|
abort "! Please use BootBridge from @AdrianDC to flash Magisk"
|
2017-07-18 09:07:39 +02:00
|
|
|
;;
|
2017-12-11 20:04:55 +01:00
|
|
|
5 )
|
2017-09-06 10:13:23 +02:00
|
|
|
ui_print "! Sony ELF64 format detected"
|
|
|
|
abort "! Stock kernel cannot be patched, please use a custom kernel"
|
2017-07-18 09:07:39 +02:00
|
|
|
esac
|
2017-02-05 20:22:37 +01:00
|
|
|
|
2017-03-12 11:13:58 +01:00
|
|
|
# Detect boot image state
|
2017-09-15 21:48:58 +02:00
|
|
|
ui_print "- Checking ramdisk status"
|
2017-12-20 20:36:18 +01:00
|
|
|
./magiskboot --cpio ramdisk.cpio test
|
2017-03-12 11:13:58 +01:00
|
|
|
case $? in
|
2017-07-09 18:17:34 +02:00
|
|
|
0 ) # Stock boot
|
2017-12-21 08:42:03 +01:00
|
|
|
ui_print "- Stock boot image detected"
|
2017-09-06 10:13:23 +02:00
|
|
|
abort "! Magisk is not installed!"
|
2017-03-12 11:13:58 +01:00
|
|
|
;;
|
2018-03-10 08:55:55 +01:00
|
|
|
1|2 ) # Magisk patched
|
2017-12-21 08:42:03 +01:00
|
|
|
ui_print "- Magisk patched image detected"
|
2017-03-12 11:13:58 +01:00
|
|
|
# Find SHA1 of stock boot image
|
2017-12-20 20:36:18 +01:00
|
|
|
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null`
|
2017-11-10 18:33:50 +01:00
|
|
|
OK=false
|
|
|
|
[ ! -z $SHA1 ] && restore_imgs $SHA1 && OK=true
|
|
|
|
if ! $OK; then
|
2017-09-06 10:13:23 +02:00
|
|
|
ui_print "! Boot image backup unavailable"
|
|
|
|
ui_print "- Restoring ramdisk with internal backup"
|
2017-12-20 20:36:18 +01:00
|
|
|
./magiskboot --cpio ramdisk.cpio restore
|
2017-09-27 09:26:21 +02:00
|
|
|
./magiskboot --repack $BOOTIMAGE
|
|
|
|
# Sign chromeos boot
|
|
|
|
$CHROMEOS && sign_chromeos
|
2017-11-10 18:33:50 +01:00
|
|
|
flash_boot_image new-boot.img "$BOOTIMAGE"
|
2017-03-12 11:13:58 +01:00
|
|
|
fi
|
|
|
|
;;
|
2018-03-10 08:55:55 +01:00
|
|
|
3 ) # Other patched
|
2017-12-21 08:42:03 +01:00
|
|
|
ui_print "! Boot image patched by other programs"
|
2017-09-06 10:13:23 +02:00
|
|
|
abort "! Cannot uninstall"
|
2017-03-12 11:13:58 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2017-09-06 10:13:23 +02:00
|
|
|
cd /
|
2017-02-05 20:22:37 +01:00
|
|
|
|
2017-09-06 10:13:23 +02:00
|
|
|
ui_print "- Removing Magisk files"
|
2017-09-27 09:26:21 +02:00
|
|
|
rm -rf /cache/*magisk* /cache/unblock /data/*magisk* /data/cache/*magisk* /data/property/*magisk* \
|
2017-11-10 18:33:50 +01:00
|
|
|
/data/Magisk.apk /data/busybox /data/custom_ramdisk_patch.sh /data/app/com.topjohnwu.magisk* \
|
2017-12-20 20:36:18 +01:00
|
|
|
/data/user*/*/magisk.db /data/user*/*/com.topjohnwu.magisk /data/user*/*/.tmp.magisk.config \
|
|
|
|
/data/adb/*magisk* 2>/dev/null
|
2017-02-05 20:22:37 +01:00
|
|
|
|
2018-02-13 17:57:52 +01:00
|
|
|
$BOOTMODE && /system/bin/reboot
|