2018-06-26 22:00:01 +00:00
|
|
|
#MAGISK
|
2020-03-09 05:25:06 +00:00
|
|
|
############################################
|
2021-01-22 10:28:53 +00:00
|
|
|
# Magisk Uninstaller (updater-script)
|
2020-03-09 05:25:06 +00:00
|
|
|
############################################
|
2017-06-03 16:03:36 +00:00
|
|
|
|
2020-03-20 10:44:08 +00:00
|
|
|
##############
|
2018-06-26 22:00:01 +00:00
|
|
|
# Preparation
|
2020-03-20 10:44:08 +00:00
|
|
|
##############
|
2018-06-26 22:00:01 +00:00
|
|
|
|
|
|
|
# Default permissions
|
|
|
|
umask 022
|
2017-07-09 16:17:34 +00:00
|
|
|
|
2018-06-26 22:00:01 +00:00
|
|
|
OUTFD=$2
|
2021-01-22 10:28:53 +00:00
|
|
|
APK="$3"
|
|
|
|
COMMONDIR=$INSTALLER/assets
|
|
|
|
CHROMEDIR=$INSTALLER/assets/chromeos
|
2017-02-05 19:22:37 +00:00
|
|
|
|
2021-01-22 10:28:53 +00:00
|
|
|
if [ ! -f $COMMONDIR/util_functions.sh ]; then
|
2018-06-26 22:00:01 +00:00
|
|
|
echo "! Unable to extract zip file!"
|
2017-08-01 18:21:50 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-06-26 22:00:01 +00:00
|
|
|
# Load utility functions
|
2021-01-22 10:28:53 +00:00
|
|
|
. $COMMONDIR/util_functions.sh
|
2018-06-26 22:00:01 +00:00
|
|
|
|
2018-08-29 02:03:12 +00:00
|
|
|
setup_flashable
|
2017-09-15 19:48:58 +00:00
|
|
|
|
2021-01-22 10:28:53 +00:00
|
|
|
############
|
|
|
|
# Detection
|
|
|
|
############
|
|
|
|
|
|
|
|
if echo $MAGISK_VER | grep -q '\.'; then
|
|
|
|
PRETTY_VER=$MAGISK_VER
|
|
|
|
else
|
|
|
|
PRETTY_VER="$MAGISK_VER($MAGISK_VER_CODE)"
|
|
|
|
fi
|
|
|
|
print_title "Magisk $PRETTY_VER Uninstaller"
|
2018-06-26 22:00:01 +00:00
|
|
|
|
2021-03-09 11:05:47 +00:00
|
|
|
is_mounted /data || mount /data || abort "! Unable to mount /data, please uninstall with the Magisk app"
|
2021-01-22 10:28:53 +00:00
|
|
|
mount_partitions
|
|
|
|
check_data
|
2021-03-09 11:05:47 +00:00
|
|
|
$DATA_DE || abort "! Cannot access /data, please uninstall with the Magisk app"
|
2021-01-22 10:28:53 +00:00
|
|
|
get_flags
|
|
|
|
find_boot_image
|
|
|
|
|
|
|
|
[ -z $BOOTIMAGE ] && abort "! Unable to detect target image"
|
|
|
|
ui_print "- Target image: $BOOTIMAGE"
|
2018-06-26 14:41:03 +00:00
|
|
|
|
2021-01-22 10:28:53 +00:00
|
|
|
# Detect version and architecture
|
2018-06-26 22:00:01 +00:00
|
|
|
api_level_arch_detect
|
|
|
|
|
2021-05-13 07:21:04 +00:00
|
|
|
ui_print "- Device platform: $ABI"
|
2018-06-26 22:00:01 +00:00
|
|
|
|
2021-05-13 07:21:04 +00:00
|
|
|
BINDIR=$INSTALLER/lib/$ABI
|
2021-01-22 10:28:53 +00:00
|
|
|
cd $BINDIR
|
|
|
|
for file in lib*.so; do mv "$file" "${file:3:${#file}-6}"; done
|
|
|
|
cd /
|
|
|
|
cp -af $CHROMEDIR/. $BINDIR/chromeos
|
2021-05-13 07:21:04 +00:00
|
|
|
chmod -R 755 $BINDIR
|
2018-06-26 22:00:01 +00:00
|
|
|
|
2020-03-20 10:44:08 +00:00
|
|
|
############
|
2018-06-26 22:00:01 +00:00
|
|
|
# Uninstall
|
2020-03-20 10:44:08 +00:00
|
|
|
############
|
2018-06-26 22:00:01 +00:00
|
|
|
|
2021-01-22 10:28:53 +00:00
|
|
|
cd $BINDIR
|
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"
|
2020-03-22 08:02:03 +00: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 23:06:29 +00:00
|
|
|
./magiskboot unpack "$BOOTIMAGE"
|
2017-12-11 19:04:55 +00:00
|
|
|
|
2017-07-18 07:07:39 +00:00
|
|
|
case $? in
|
|
|
|
1 )
|
2019-05-08 23:06:29 +00:00
|
|
|
abort "! Unsupported/Unknown image format"
|
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
|
|
|
|
;;
|
|
|
|
esac
|
2017-02-05 19:22:37 +00:00
|
|
|
|
2020-03-22 08:02:03 +00:00
|
|
|
# Restore the original boot partition path
|
|
|
|
[ "$BOOTNAND" ] && BOOTIMAGE=$BOOTNAND
|
|
|
|
|
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"
|
2019-05-08 23:06:29 +00: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-09 16:17:34 +00:00
|
|
|
0 ) # Stock boot
|
2017-12-21 07:42:03 +00:00
|
|
|
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
|
2017-12-21 07:42:03 +00:00
|
|
|
ui_print "- Magisk patched image detected"
|
2017-03-12 10:13:58 +00:00
|
|
|
# Find SHA1 of stock boot image
|
2021-01-22 10:28:53 +00:00
|
|
|
SHA1=$(./magiskboot cpio ramdisk.cpio sha1 2>/dev/null)
|
2020-01-01 06:02:44 +00:00
|
|
|
BACKUPDIR=/data/magisk_backup_$SHA1
|
|
|
|
if [ -d $BACKUPDIR ]; then
|
2018-06-26 22:00:01 +00:00
|
|
|
ui_print "- Restoring stock boot image"
|
2020-01-01 06:02:44 +00:00
|
|
|
flash_image $BACKUPDIR/boot.img.gz $BOOTIMAGE
|
2020-04-14 04:24:02 +00:00
|
|
|
for name in dtb dtbo dtbs; do
|
2020-01-01 06:02:44 +00:00
|
|
|
[ -f $BACKUPDIR/${name}.img.gz ] || continue
|
2021-01-22 10:28:53 +00:00
|
|
|
IMAGE=$(find_block $name$SLOT)
|
2020-01-01 06:02:44 +00:00
|
|
|
[ -z $IMAGE ] && continue
|
|
|
|
ui_print "- Restoring stock $name image"
|
|
|
|
flash_image $BACKUPDIR/${name}.img.gz $IMAGE
|
|
|
|
done
|
2018-06-26 22:00:01 +00:00
|
|
|
else
|
2017-09-06 08:13:23 +00:00
|
|
|
ui_print "! Boot image backup unavailable"
|
|
|
|
ui_print "- Restoring ramdisk with internal backup"
|
2019-05-08 23:06:29 +00:00
|
|
|
./magiskboot cpio ramdisk.cpio restore
|
2021-01-22 10:28:53 +00:00
|
|
|
if ! ./magiskboot cpio ramdisk.cpio "exists init"; then
|
2019-05-08 23:06:29 +00:00
|
|
|
# A only system-as-root
|
|
|
|
rm -f ramdisk.cpio
|
|
|
|
fi
|
|
|
|
./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"
|
2018-08-11 07:56:12 +00:00
|
|
|
flash_image new-boot.img $BOOTIMAGE || abort "! Insufficient partition size"
|
2017-03-12 10:13:58 +00:00
|
|
|
fi
|
|
|
|
;;
|
2019-05-08 23:06:29 +00:00
|
|
|
2 ) # Unsupported
|
|
|
|
ui_print "! Boot image patched by unsupported programs"
|
2017-09-06 08:13:23 +00:00
|
|
|
abort "! Cannot uninstall"
|
2017-03-12 10:13:58 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2023-02-10 04:36:58 +00:00
|
|
|
if $BOOTMODE; then
|
|
|
|
ui_print "- Removing modules"
|
|
|
|
magisk --remove-modules -n
|
|
|
|
fi
|
|
|
|
|
2017-09-06 08:13:23 +00:00
|
|
|
ui_print "- Removing Magisk files"
|
2020-01-01 06:02:44 +00: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-03 07:20:38 +00: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-05 19:22:37 +00:00
|
|
|
|
2021-01-22 10:28:53 +00:00
|
|
|
ADDOND=/system/addon.d/99-magisk.sh
|
|
|
|
if [ -f $ADDOND ]; then
|
2020-06-18 04:30:50 +00:00
|
|
|
blockdev --setrw /dev/block/mapper/system$SLOT 2>/dev/null
|
|
|
|
mount -o rw,remount /system || mount -o rw,remount /
|
2021-01-22 10:28:53 +00:00
|
|
|
rm -f $ADDOND
|
2018-06-26 14:41:03 +00:00
|
|
|
fi
|
|
|
|
|
2018-06-26 22:00:01 +00:00
|
|
|
cd /
|
|
|
|
|
|
|
|
if $BOOTMODE; then
|
2020-03-22 08:02:03 +00:00
|
|
|
ui_print "********************************************"
|
2021-03-09 11:05:47 +00:00
|
|
|
ui_print " The Magisk app will uninstall itself, and"
|
2020-03-22 08:02:03 +00:00
|
|
|
ui_print " the device will reboot after a few seconds"
|
|
|
|
ui_print "********************************************"
|
2018-06-26 22:00:01 +00:00
|
|
|
(sleep 8; /system/bin/reboot)&
|
|
|
|
else
|
2021-01-22 10:28:53 +00:00
|
|
|
ui_print "********************************************"
|
2021-03-09 11:05:47 +00:00
|
|
|
ui_print " The Magisk app will not be uninstalled"
|
2021-01-22 10:28:53 +00:00
|
|
|
ui_print " Please uninstall it manually after reboot"
|
|
|
|
ui_print "********************************************"
|
2018-06-26 22:00:01 +00:00
|
|
|
recovery_cleanup
|
|
|
|
ui_print "- Done"
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -rf $TMPDIR
|
|
|
|
exit 0
|