2018-06-27 06:00:01 +08:00
|
|
|
#MAGISK
|
2020-03-08 22:25:06 -07:00
|
|
|
############################################
|
2017-06-04 00:03:36 +08:00
|
|
|
#
|
2018-08-09 18:13:07 +08:00
|
|
|
# Magisk Uninstaller
|
2017-06-04 00:03:36 +08:00
|
|
|
# by topjohnwu
|
2017-07-25 02:02:19 +08:00
|
|
|
#
|
2020-03-08 22:25:06 -07:00
|
|
|
############################################
|
2017-06-04 00:03:36 +08:00
|
|
|
|
2020-03-20 07:44:08 -03:00
|
|
|
##############
|
2018-06-27 06:00:01 +08:00
|
|
|
# Preparation
|
2020-03-20 07:44:08 -03:00
|
|
|
##############
|
2018-06-27 06:00:01 +08:00
|
|
|
|
|
|
|
# This path should work in any cases
|
|
|
|
TMPDIR=/dev/tmp
|
|
|
|
|
|
|
|
INSTALLER=$TMPDIR/install
|
|
|
|
CHROMEDIR=$INSTALLER/chromeos
|
|
|
|
|
|
|
|
# Default permissions
|
|
|
|
umask 022
|
2017-07-10 00:17:34 +08:00
|
|
|
|
2018-06-27 06:00:01 +08:00
|
|
|
OUTFD=$2
|
|
|
|
ZIP=$3
|
2017-02-06 03:22:37 +08:00
|
|
|
|
2018-06-27 06:00:01 +08:00
|
|
|
if [ ! -f $INSTALLER/util_functions.sh ]; then
|
|
|
|
echo "! Unable to extract zip file!"
|
2017-08-02 02:21:50 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-06-27 06:00:01 +08:00
|
|
|
# Load utility functions
|
|
|
|
. $INSTALLER/util_functions.sh
|
|
|
|
|
2018-08-28 22:03:12 -04:00
|
|
|
setup_flashable
|
2017-09-16 03:48:58 +08:00
|
|
|
|
2020-03-08 22:25:06 -07:00
|
|
|
print_title "Magisk Uninstaller"
|
2018-06-27 06:00:01 +08:00
|
|
|
|
2020-06-18 01:30:50 -03:00
|
|
|
is_mounted /data || mount /data || abort "! Unable to mount /data, please uninstall with Magisk Manager"
|
2020-11-02 23:20:38 -08:00
|
|
|
if ! $BOOTMODE; then
|
|
|
|
# Mounting stuffs in recovery (best effort)
|
|
|
|
mount_name metadata /metadata
|
|
|
|
mount_name "cache cac" /cache
|
|
|
|
mount_name persist /persist
|
|
|
|
fi
|
2018-06-26 22:41:03 +08:00
|
|
|
mount_partitions
|
|
|
|
|
2018-06-27 06:00:01 +08: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
|
2020-01-01 14:02:44 +08:00
|
|
|
run_migrations
|
2018-06-27 06:00:01 +08:00
|
|
|
|
2020-03-20 07:44:08 -03:00
|
|
|
############
|
2018-06-27 06:00:01 +08:00
|
|
|
# Uninstall
|
2020-03-20 07:44:08 -03:00
|
|
|
############
|
2018-06-27 06:00:01 +08:00
|
|
|
|
2019-05-08 20:06:29 -03:00
|
|
|
get_flags
|
2018-06-26 22:41:03 +08:00
|
|
|
find_boot_image
|
|
|
|
|
|
|
|
[ -e $BOOTIMAGE ] || abort "! Unable to detect boot image"
|
2019-02-24 02:11:11 -05:00
|
|
|
ui_print "- Found target image: $BOOTIMAGE"
|
2018-06-26 22:41:03 +08:00
|
|
|
[ -z $DTBOIMAGE ] || ui_print "- Found dtbo image: $DTBOIMAGE"
|
|
|
|
|
2017-09-16 03:48:58 +08:00
|
|
|
cd $MAGISKBIN
|
2017-02-06 03:22:37 +08:00
|
|
|
|
2018-06-26 22:41:03 +08:00
|
|
|
CHROMEOS=false
|
2017-02-06 03:22:37 +08:00
|
|
|
|
2017-09-06 16:13:23 +08:00
|
|
|
ui_print "- Unpacking boot image"
|
2020-03-22 05:02:03 -03:00
|
|
|
# Dump image for MTD/NAND character device boot partitions
|
|
|
|
if [ -c $BOOTIMAGE ]; then
|
|
|
|
nanddump -f boot.img $BOOTIMAGE
|
|
|
|
BOOTNAND=$BOOTIMAGE
|
|
|
|
BOOTIMAGE=boot.img
|
|
|
|
fi
|
2019-05-08 20:06:29 -03:00
|
|
|
./magiskboot unpack "$BOOTIMAGE"
|
2017-12-12 03:04:55 +08:00
|
|
|
|
2017-07-18 15:07:39 +08:00
|
|
|
case $? in
|
|
|
|
1 )
|
2019-05-08 20:06:29 -03:00
|
|
|
abort "! Unsupported/Unknown image format"
|
2017-07-18 15:07:39 +08:00
|
|
|
;;
|
2018-08-09 18:13:07 +08:00
|
|
|
2 )
|
2017-12-12 03:04:55 +08:00
|
|
|
ui_print "- ChromeOS boot image detected"
|
2017-07-18 15:07:39 +08:00
|
|
|
CHROMEOS=true
|
|
|
|
;;
|
|
|
|
esac
|
2017-02-06 03:22:37 +08:00
|
|
|
|
2020-03-22 05:02:03 -03:00
|
|
|
# Restore the original boot partition path
|
|
|
|
[ "$BOOTNAND" ] && BOOTIMAGE=$BOOTNAND
|
|
|
|
|
2017-03-12 18:13:58 +08:00
|
|
|
# Detect boot image state
|
2017-09-16 03:48:58 +08:00
|
|
|
ui_print "- Checking ramdisk status"
|
2019-05-08 20:06:29 -03:00
|
|
|
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
|
2017-07-10 00:17:34 +08:00
|
|
|
0 ) # Stock boot
|
2017-12-21 15:42:03 +08:00
|
|
|
ui_print "- Stock boot image detected"
|
2017-03-12 18:13:58 +08:00
|
|
|
;;
|
2018-08-09 18:13:07 +08:00
|
|
|
1 ) # Magisk patched
|
2017-12-21 15:42:03 +08:00
|
|
|
ui_print "- Magisk patched image detected"
|
2017-03-12 18:13:58 +08:00
|
|
|
# Find SHA1 of stock boot image
|
2020-01-01 14:02:44 +08:00
|
|
|
SHA1=`./magiskboot cpio ramdisk.cpio sha1 2>/dev/null`
|
|
|
|
BACKUPDIR=/data/magisk_backup_$SHA1
|
|
|
|
if [ -d $BACKUPDIR ]; then
|
2018-06-27 06:00:01 +08:00
|
|
|
ui_print "- Restoring stock boot image"
|
2020-01-01 14:02:44 +08:00
|
|
|
flash_image $BACKUPDIR/boot.img.gz $BOOTIMAGE
|
2020-04-14 12:24:02 +08:00
|
|
|
for name in dtb dtbo dtbs; do
|
2020-01-01 14:02:44 +08:00
|
|
|
[ -f $BACKUPDIR/${name}.img.gz ] || continue
|
|
|
|
IMAGE=`find_block $name$SLOT`
|
|
|
|
[ -z $IMAGE ] && continue
|
|
|
|
ui_print "- Restoring stock $name image"
|
|
|
|
flash_image $BACKUPDIR/${name}.img.gz $IMAGE
|
|
|
|
done
|
2018-06-27 06:00:01 +08:00
|
|
|
else
|
2017-09-06 16:13:23 +08:00
|
|
|
ui_print "! Boot image backup unavailable"
|
|
|
|
ui_print "- Restoring ramdisk with internal backup"
|
2019-05-08 20:06:29 -03:00
|
|
|
./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
|
2017-09-27 15:26:21 +08:00
|
|
|
# Sign chromeos boot
|
|
|
|
$CHROMEOS && sign_chromeos
|
2018-08-10 18:59:14 +08:00
|
|
|
ui_print "- Flashing restored boot image"
|
2018-08-11 15:56:12 +08:00
|
|
|
flash_image new-boot.img $BOOTIMAGE || abort "! Insufficient partition size"
|
2017-03-12 18:13:58 +08:00
|
|
|
fi
|
|
|
|
;;
|
2019-05-08 20:06:29 -03:00
|
|
|
2 ) # Unsupported
|
|
|
|
ui_print "! Boot image patched by unsupported programs"
|
2017-09-06 16:13:23 +08:00
|
|
|
abort "! Cannot uninstall"
|
2017-03-12 18:13:58 +08:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2017-09-06 16:13:23 +08:00
|
|
|
ui_print "- Removing Magisk files"
|
2020-01-01 14:02:44 +08:00
|
|
|
rm -rf \
|
|
|
|
/cache/*magisk* /cache/unblock /data/*magisk* /data/cache/*magisk* /data/property/*magisk* \
|
|
|
|
/data/Magisk.apk /data/busybox /data/custom_ramdisk_patch.sh /data/adb/*magisk* \
|
2020-11-02 23:20:38 -08:00
|
|
|
/data/adb/post-fs-data.d /data/adb/service.d /data/adb/modules* \
|
|
|
|
/data/unencrypted/magisk /metadata/magisk /persist/magisk /mnt/vendor/persist/magisk
|
2017-02-06 03:22:37 +08:00
|
|
|
|
2018-06-26 22:41:03 +08:00
|
|
|
if [ -f /system/addon.d/99-magisk.sh ]; then
|
2020-06-18 01:30:50 -03:00
|
|
|
blockdev --setrw /dev/block/mapper/system$SLOT 2>/dev/null
|
|
|
|
mount -o rw,remount /system || mount -o rw,remount /
|
2018-06-26 22:41:03 +08:00
|
|
|
rm -f /system/addon.d/99-magisk.sh
|
|
|
|
fi
|
|
|
|
|
2018-06-27 06:00:01 +08:00
|
|
|
cd /
|
|
|
|
|
|
|
|
if $BOOTMODE; then
|
2020-03-22 05:02:03 -03:00
|
|
|
ui_print "********************************************"
|
|
|
|
ui_print " Magisk Manager will uninstall itself, and"
|
|
|
|
ui_print " the device will reboot after a few seconds"
|
|
|
|
ui_print "********************************************"
|
2018-06-27 06:00:01 +08:00
|
|
|
(sleep 8; /system/bin/reboot)&
|
|
|
|
else
|
2020-11-02 23:20:38 -08:00
|
|
|
rm -rf /data/data/*magisk* /data/user*/*/*magisk* /data/app/*magisk* /data/app/*/*magisk*
|
2018-06-27 06:00:01 +08:00
|
|
|
recovery_cleanup
|
|
|
|
ui_print "- Done"
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -rf $TMPDIR
|
|
|
|
exit 0
|