Magisk/scripts/magisk_uninstaller.sh

156 lines
4.3 KiB
Bash
Raw Normal View History

2018-06-26 22:00:01 +00:00
#MAGISK
2017-06-03 16:03:36 +00:00
##########################################################################################
#
2018-08-09 10:13:07 +00:00
# Magisk Uninstaller
2017-06-03 16:03:36 +00:00
# by topjohnwu
2017-07-24 18:02:19 +00:00
#
2017-06-03 16:03:36 +00:00
##########################################################################################
2018-06-26 22:00:01 +00:00
##########################################################################################
# Preparation
##########################################################################################
# This path should work in any cases
TMPDIR=/dev/tmp
INSTALLER=$TMPDIR/install
CHROMEDIR=$INSTALLER/chromeos
# Default permissions
umask 022
2017-07-09 16:17:34 +00:00
2018-06-26 22:00:01 +00:00
OUTFD=$2
ZIP=$3
2017-02-05 19:22:37 +00:00
2018-06-26 22:00:01 +00:00
if [ ! -f $INSTALLER/util_functions.sh ]; then
echo "! Unable to extract zip file!"
exit 1
fi
2018-06-26 22:00:01 +00:00
# Load utility functions
. $INSTALLER/util_functions.sh
2018-08-29 02:03:12 +00:00
setup_flashable
2017-09-15 19:48:58 +00:00
2018-06-26 22:00:01 +00:00
ui_print "************************"
ui_print " Magisk Uninstaller "
ui_print "************************"
is_mounted /data || mount /data || abort "! Unable to mount partitions"
is_mounted /cache || mount /cache 2>/dev/null
2018-06-26 14:41:03 +00:00
mount_partitions
2018-06-26 22:00:01 +00:00
api_level_arch_detect
ui_print "- Device platform: $ARCH"
MAGISKBIN=$INSTALLER/$ARCH32
mv $CHROMEDIR $MAGISKBIN
chmod -R 755 $MAGISKBIN
check_data
$DATA_DE || abort "! Cannot access /data, please uninstall with Magisk Manager"
$BOOTMODE || recovery_actions
##########################################################################################
# Uninstall
##########################################################################################
2018-06-26 14:41:03 +00:00
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"
2017-09-15 19:48:58 +00:00
cd $MAGISKBIN
2017-02-05 19:22:37 +00:00
2018-06-26 14:41:03 +00:00
CHROMEOS=false
2017-02-05 19:22:37 +00:00
2017-09-06 08:13:23 +00:00
ui_print "- Unpacking boot image"
./magiskboot --unpack "$BOOTIMAGE"
2017-12-11 19:04:55 +00:00
2017-07-18 07:07:39 +00:00
case $? in
1 )
2017-09-06 08:13:23 +00:00
abort "! Unable to unpack boot image"
2017-07-18 07:07:39 +00:00
;;
2018-08-09 10:13:07 +00:00
2 )
2017-12-11 19:04:55 +00:00
ui_print "- ChromeOS boot image detected"
2017-07-18 07:07:39 +00:00
CHROMEOS=true
;;
2018-08-09 10:13:07 +00:00
3 )
2017-09-06 08:13:23 +00:00
ui_print "! Sony ELF32 format detected"
2018-06-26 22:00:01 +00:00
abort "! Please use BootBridge from @AdrianDC"
2017-07-18 07:07:39 +00:00
;;
2018-08-09 10:13:07 +00:00
4 )
2017-09-06 08:13:23 +00:00
ui_print "! Sony ELF64 format detected"
abort "! Stock kernel cannot be patched, please use a custom kernel"
2017-07-18 07:07:39 +00:00
esac
2017-02-05 19:22:37 +00:00
2017-03-12 10:13:58 +00:00
# Detect boot image state
2017-09-15 19:48:58 +00:00
ui_print "- Checking ramdisk status"
./magiskboot --cpio ramdisk.cpio test
2017-03-12 10:13:58 +00:00
case $? in
2017-07-09 16:17:34 +00:00
0 ) # Stock boot
ui_print "- Stock boot image detected"
2017-03-12 10:13:58 +00:00
;;
2018-08-09 10:13:07 +00:00
1 ) # Magisk patched
ui_print "- Magisk patched image detected"
2017-03-12 10:13:58 +00:00
# Find SHA1 of stock boot image
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null`
2018-06-26 22:00:01 +00:00
STOCKBOOT=/data/stock_boot_${SHA1}.img.gz
STOCKDTBO=/data/stock_dtbo.img.gz
if [ -f $STOCKBOOT ]; then
ui_print "- Restoring stock boot image"
2018-08-10 10:59:14 +00:00
flash_image $STOCKBOOT $BOOTIMAGE
if [ -f $STOCKDTBO -a -b "$DTBOIMAGE" ]; then
2018-06-26 22:00:01 +00:00
ui_print "- Restoring stock dtbo image"
2018-08-10 10:59:14 +00:00
flash_image $STOCKDTBO $DTBOIMAGE
2018-06-26 22:00:01 +00:00
fi
else
2017-09-06 08:13:23 +00:00
ui_print "! Boot image backup unavailable"
ui_print "- Restoring ramdisk with internal backup"
./magiskboot --cpio ramdisk.cpio restore
./magiskboot --repack $BOOTIMAGE
2017-09-27 07:26:21 +00:00
# Sign chromeos boot
$CHROMEOS && sign_chromeos
2018-08-10 10:59:14 +00:00
ui_print "- Flashing restored boot image"
flash_image new-boot.img $BOOTIMAGE || abort "! Insufficient partition size"
2017-03-12 10:13:58 +00:00
fi
;;
2018-08-09 10:13:07 +00:00
2 ) # Other patched
ui_print "! Boot image patched by other programs"
2017-09-06 08:13:23 +00:00
abort "! Cannot uninstall"
2017-03-12 10:13:58 +00:00
;;
esac
2017-09-06 08:13:23 +00:00
ui_print "- Removing Magisk files"
2017-09-27 07:26:21 +00:00
rm -rf /cache/*magisk* /cache/unblock /data/*magisk* /data/cache/*magisk* /data/property/*magisk* \
2018-06-26 22:00:01 +00:00
/data/Magisk.apk /data/busybox /data/custom_ramdisk_patch.sh /data/adb/*magisk* 2>/dev/null
2017-02-05 19:22:37 +00:00
2018-06-26 14:41:03 +00:00
if [ -f /system/addon.d/99-magisk.sh ]; then
mount -o rw,remount /system
rm -f /system/addon.d/99-magisk.sh
fi
2018-06-26 22:00:01 +00:00
# Remove persist props (for Android P+ using protobuf)
for prop in `./magisk resetprop -p | grep -E 'persist.*magisk' | grep -oE '^\[[a-zA-Z0-9.@:_-]+\]' | tr -d '[]'`; do
./magisk resetprop -p --delete $prop
done
cd /
if $BOOTMODE; then
ui_print "**********************************************"
ui_print "* Magisk Manager will uninstall itself, and *"
ui_print "* the device will reboot after a few seconds *"
ui_print "**********************************************"
(sleep 8; /system/bin/reboot)&
else
rm -rf /data/user*/*/*magisk* /data/app/*magisk*
recovery_cleanup
ui_print "- Done"
fi
rm -rf $TMPDIR
exit 0