2017-08-01 18:21:50 +00:00
|
|
|
#MAGISK
|
2016-09-14 02:31:13 +00:00
|
|
|
##########################################################################################
|
|
|
|
#
|
2019-11-02 03:26:08 +00:00
|
|
|
# Magisk Flash Script (updater-script)
|
2016-09-14 02:31:13 +00:00
|
|
|
# by topjohnwu
|
2017-07-24 18:02:19 +00:00
|
|
|
#
|
2017-06-03 12:19:01 +00:00
|
|
|
# This script will detect, construct the environment for Magisk
|
|
|
|
# It will then call boot_patch.sh to patch the boot image
|
2016-09-14 02:31:13 +00:00
|
|
|
#
|
|
|
|
##########################################################################################
|
|
|
|
|
2017-07-09 16:17:34 +00:00
|
|
|
##########################################################################################
|
|
|
|
# Preparation
|
|
|
|
##########################################################################################
|
|
|
|
|
2017-03-15 11:32:25 +00:00
|
|
|
COMMONDIR=$INSTALLER/common
|
2017-10-31 09:05:24 +00:00
|
|
|
APK=$COMMONDIR/magisk.apk
|
2016-11-28 20:16:01 +00:00
|
|
|
CHROMEDIR=$INSTALLER/chromeos
|
|
|
|
|
2016-11-13 08:58:43 +00:00
|
|
|
# Default permissions
|
|
|
|
umask 022
|
|
|
|
|
2016-09-14 02:31:13 +00:00
|
|
|
OUTFD=$2
|
|
|
|
ZIP=$3
|
|
|
|
|
2017-09-15 19:48:58 +00:00
|
|
|
if [ ! -f $COMMONDIR/util_functions.sh ]; then
|
2017-06-24 14:38:20 +00:00
|
|
|
echo "! Unable to extract zip file!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-07-09 16:17:34 +00:00
|
|
|
# Load utility fuctions
|
2017-06-18 16:15:44 +00:00
|
|
|
. $COMMONDIR/util_functions.sh
|
|
|
|
|
2018-08-29 02:03:12 +00:00
|
|
|
setup_flashable
|
2017-07-09 16:17:34 +00:00
|
|
|
|
|
|
|
##########################################################################################
|
|
|
|
# Detection
|
|
|
|
##########################################################################################
|
|
|
|
|
2017-04-21 23:05:10 +00:00
|
|
|
ui_print "************************"
|
2017-07-30 19:03:52 +00:00
|
|
|
ui_print "* Magisk v$MAGISK_VER Installer"
|
2017-04-21 23:05:10 +00:00
|
|
|
ui_print "************************"
|
2016-09-14 02:31:13 +00:00
|
|
|
|
2019-04-06 17:04:17 +00:00
|
|
|
is_mounted /data || mount /data || is_mounted /cache || mount /cache
|
2017-09-12 20:07:25 +00:00
|
|
|
mount_partitions
|
2018-10-20 21:10:35 +00:00
|
|
|
check_data
|
2018-06-17 17:40:56 +00:00
|
|
|
get_flags
|
2019-04-04 21:13:57 +00:00
|
|
|
find_boot_image
|
|
|
|
|
2018-07-04 15:46:16 +00:00
|
|
|
[ -z $BOOTIMAGE ] && abort "! Unable to detect target image"
|
|
|
|
ui_print "- Target image: $BOOTIMAGE"
|
2018-02-09 19:31:00 +00:00
|
|
|
|
2017-07-02 13:36:09 +00:00
|
|
|
# Detect version and architecture
|
|
|
|
api_level_arch_detect
|
2016-10-02 20:34:50 +00:00
|
|
|
|
2019-10-20 11:13:03 +00:00
|
|
|
[ $API -lt 17 ] && abort "! Magisk is only for Android 4.2 and above"
|
2016-10-29 22:13:59 +00:00
|
|
|
|
|
|
|
ui_print "- Device platform: $ARCH"
|
|
|
|
|
2018-04-22 06:13:27 +00:00
|
|
|
BINDIR=$INSTALLER/$ARCH32
|
2017-03-12 11:22:15 +00:00
|
|
|
chmod -R 755 $CHROMEDIR $BINDIR
|
2016-10-29 22:13:59 +00:00
|
|
|
|
2018-02-09 19:31:00 +00:00
|
|
|
# Check if system root is installed and remove
|
|
|
|
remove_system_su
|
|
|
|
|
2016-11-13 08:58:43 +00:00
|
|
|
##########################################################################################
|
|
|
|
# Environment
|
|
|
|
##########################################################################################
|
|
|
|
|
2017-04-21 23:05:10 +00:00
|
|
|
ui_print "- Constructing environment"
|
2017-07-24 18:02:19 +00:00
|
|
|
|
2017-04-21 23:05:10 +00:00
|
|
|
# Copy required files
|
2017-11-05 21:41:03 +00:00
|
|
|
rm -rf $MAGISKBIN/* 2>/dev/null
|
|
|
|
mkdir -p $MAGISKBIN 2>/dev/null
|
2019-02-24 07:11:11 +00:00
|
|
|
cp -af $BINDIR/. $COMMONDIR/. $CHROMEDIR $BBDIR/busybox $MAGISKBIN
|
2017-04-21 23:05:10 +00:00
|
|
|
chmod -R 755 $MAGISKBIN
|
2017-02-04 10:44:07 +00:00
|
|
|
|
2017-06-18 16:15:44 +00:00
|
|
|
# addon.d
|
|
|
|
if [ -d /system/addon.d ]; then
|
|
|
|
ui_print "- Adding addon.d survival script"
|
|
|
|
mount -o rw,remount /system
|
2018-08-03 14:40:49 +00:00
|
|
|
ADDOND=/system/addon.d/99-magisk.sh
|
2019-04-30 13:37:18 +00:00
|
|
|
cat <<EOF > $ADDOND
|
|
|
|
#!/sbin/sh
|
|
|
|
# ADDOND_VERSION=2
|
|
|
|
|
2019-11-03 01:50:33 +00:00
|
|
|
mount /data 2>/dev/null
|
|
|
|
|
2019-04-30 13:37:18 +00:00
|
|
|
if [ -f /data/adb/magisk/addon.d.sh ]; then
|
|
|
|
exec sh /data/adb/magisk/addon.d.sh "\$@"
|
|
|
|
else
|
2019-04-30 19:35:56 +00:00
|
|
|
OUTFD=\$(ps | grep -v 'grep' | grep -oE 'update(.*)' | cut -d" " -f3)
|
2019-04-30 13:37:18 +00:00
|
|
|
ui_print() { echo -e "ui_print \$1\nui_print" >> /proc/self/fd/\$OUTFD; }
|
|
|
|
|
|
|
|
ui_print "************************"
|
|
|
|
ui_print "* Magisk addon.d failed"
|
|
|
|
ui_print "************************"
|
|
|
|
ui_print "! Cannot find Magisk binaries - was data wiped or not decrypted?"
|
|
|
|
ui_print "! Reflash OTA from decrypted recovery or reflash Magisk"
|
|
|
|
fi
|
|
|
|
EOF
|
2018-08-03 14:40:49 +00:00
|
|
|
chmod 755 $ADDOND
|
2017-06-18 16:15:44 +00:00
|
|
|
fi
|
|
|
|
|
2017-09-27 16:54:01 +00:00
|
|
|
$BOOTMODE || recovery_actions
|
2017-04-17 08:36:49 +00:00
|
|
|
|
2017-03-12 10:13:58 +00:00
|
|
|
##########################################################################################
|
2019-11-02 03:26:08 +00:00
|
|
|
# Boot/DTBO Patching
|
2017-03-12 10:13:58 +00:00
|
|
|
##########################################################################################
|
|
|
|
|
2019-11-02 03:26:08 +00:00
|
|
|
patch_boot_image
|
2016-09-14 02:31:13 +00:00
|
|
|
|
2017-01-01 18:00:53 +00:00
|
|
|
cd /
|
2017-09-05 13:44:22 +00:00
|
|
|
# Cleanups
|
|
|
|
$BOOTMODE || recovery_cleanup
|
2017-08-12 15:15:39 +00:00
|
|
|
rm -rf $TMPDIR
|
2017-07-30 19:03:52 +00:00
|
|
|
|
2016-09-14 02:31:13 +00:00
|
|
|
ui_print "- Done"
|
|
|
|
exit 0
|