Magisk/uninstaller/META-INF/com/google/android/update-binary

155 lines
4.0 KiB
Plaintext
Raw Normal View History

2016-10-03 22:16:49 +02:00
#!/sbin/sh
##########################################################################################
#
# Magisk Uninstaller
# by topjohnwu
#
# This zip will remove all Magisk related files and revert boot image
#
##########################################################################################
INSTALLER=/tmp/uninstall
2016-11-14 21:46:01 +01:00
# Default permissions
umask 022
2016-10-03 22:16:49 +02:00
##########################################################################################
# Flashable update-binary preparation
##########################################################################################
OUTFD=$2
ZIP=$3
readlink /proc/$$/fd/$OUTFD 2>/dev/null | grep /tmp >/dev/null
if [ "$?" -eq "0" ]; then
OUTFD=0
for FD in `ls /proc/$$/fd`; do
readlink /proc/$$/fd/$FD 2>/dev/null | grep pipe >/dev/null
if [ "$?" -eq "0" ]; then
ps | grep " 3 $FD " | grep -v grep >/dev/null
if [ "$?" -eq "0" ]; then
OUTFD=$FD
break
fi
fi
done
fi
mkdir -p $INSTALLER
cd $INSTALLER
unzip -o "$ZIP"
##########################################################################################
# Functions
##########################################################################################
ui_print() {
echo -n -e "ui_print $1\n" >> /proc/self/fd/$OUTFD
echo -n -e "ui_print\n" >> /proc/self/fd/$OUTFD
}
getvar() {
local VARNAME=$1
local VALUE=$(eval echo \$"$VARNAME");
for FILE in /data/.magisk /cache/.magisk /system/.magisk; do
if [ -z "$VALUE" ]; then
LINE=$(cat $FILE 2>/dev/null | grep "$VARNAME=")
if [ ! -z "$LINE" ]; then
VALUE=${LINE#*=}
fi
fi
done
eval $VARNAME=\$VALUE
}
is_mounted() {
if [ ! -z "$2" ]; then
cat /proc/mounts | grep $1 | grep $2, >/dev/null
else
cat /proc/mounts | grep $1 >/dev/null
fi
return $?
}
grep_prop() {
REGEX="s/^$1=//p"
shift
FILES=$@
if [ -z "$FILES" ]; then
FILES='/system/build.prop'
fi
cat $FILES 2>/dev/null | sed -n $REGEX | head -n 1
}
##########################################################################################
# Main
##########################################################################################
ui_print "*****************************"
ui_print " Magisk Uninstaller "
ui_print "*****************************"
if [ ! -d "$INSTALLER/arm" ]; then
ui_print "! Failed: Unable to extract zip file!"
exit 1
fi
ui_print "- Mounting /system(ro), /cache, /data"
mount -o ro /system 2>/dev/null
mount /cache 2>/dev/null
mount /data 2>/dev/null
if [ ! -f '/system/build.prop' ]; then
ui_print "! Failed: /system could not be mounted!"
exit 1
fi
API=$(grep_prop ro.build.version.sdk)
ABI=$(grep_prop ro.product.cpu.abi | cut -c-3)
ABI2=$(grep_prop ro.product.cpu.abi2 | cut -c-3)
ABILONG=$(grep_prop ro.product.cpu.abi)
ARCH=arm
2016-11-14 21:46:01 +01:00
IS64BIT=false
2016-10-03 22:16:49 +02:00
if [ "$ABI" = "x86" ]; then ARCH=x86; fi;
if [ "$ABI2" = "x86" ]; then ARCH=x86; fi;
2016-11-14 21:46:01 +01:00
if [ "$ABILONG" = "arm64-v8a" ]; then ARCH=arm64; IS64BIT=true; fi;
if [ "$ABILONG" = "x86_64" ]; then ARCH=x64; IS64BIT=true; fi;
2016-10-03 22:16:49 +02:00
ui_print "- Device platform: $ARCH"
2017-02-05 20:22:37 +01:00
CHROMEDIR=$INSTALLER/chromeos
2016-11-14 21:46:01 +01:00
BINDIR=$INSTALLER/$ARCH
2016-10-03 22:16:49 +02:00
2017-02-05 20:22:37 +01:00
# Copy the binaries to /data/magisk
mkdir -p /data/magisk 2>/dev/null
cp -af $BINDIR/* $CHROMEDIR /data/magisk
2016-10-03 22:16:49 +02:00
##########################################################################################
# Detection all done, start installing
##########################################################################################
2016-12-08 10:24:27 +01:00
ui_print "- Found Boot Image: $BOOTIMAGE"
2016-10-03 22:16:49 +02:00
if (is_mounted /data); then
2017-02-05 20:22:37 +01:00
ui_print "- Running uninstaller scripts"
sh $INSTALLER/common/magisk_uninstaller.sh
if [ $? -ne 0 ]; then
ui_print "! Magisk is not installed or an error occurred"
exit 1
fi
2016-10-03 22:16:49 +02:00
else
2016-12-08 10:24:27 +01:00
ui_print "! Data unavailable"
2017-02-05 20:22:37 +01:00
ui_print "! Placing uninstall script to /cache"
ui_print "! The device might reboot multiple times"
2017-02-05 20:22:37 +01:00
cp -af $INSTALLER/common/magisk_uninstaller.sh /cache/magisk_uninstaller.sh
umount /system
ui_print "- Rebooting....."
2017-02-05 20:22:37 +01:00
sleep 5
reboot
2016-10-03 22:16:49 +02:00
fi
umount /system
ui_print "- Done"
exit 0