2017-08-02 02:21:50 +08:00
|
|
|
#MAGISK
|
2016-09-14 10:31:13 +08:00
|
|
|
##########################################################################################
|
|
|
|
#
|
2017-06-03 20:19:01 +08:00
|
|
|
# Magisk Flash Script
|
2016-09-14 10:31:13 +08:00
|
|
|
# by topjohnwu
|
2017-07-25 02:02:19 +08:00
|
|
|
#
|
2017-06-03 20:19:01 +08: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 10:31:13 +08:00
|
|
|
#
|
|
|
|
##########################################################################################
|
|
|
|
|
2017-07-10 00:17:34 +08:00
|
|
|
##########################################################################################
|
|
|
|
# Preparation
|
|
|
|
##########################################################################################
|
|
|
|
|
2017-03-12 18:13:58 +08:00
|
|
|
# Detect whether in boot mode
|
|
|
|
ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true || BOOTMODE=false
|
2017-06-11 01:40:08 +08:00
|
|
|
$BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMODE=true
|
2016-09-14 10:31:13 +08:00
|
|
|
|
2017-03-12 18:13:58 +08:00
|
|
|
# This path should work in any cases
|
|
|
|
TMPDIR=/dev/tmp
|
2016-09-14 10:31:13 +08:00
|
|
|
|
2017-07-10 00:17:34 +08:00
|
|
|
INSTALLER=$TMPDIR/install
|
2017-03-15 19:32:25 +08:00
|
|
|
COMMONDIR=$INSTALLER/common
|
2017-10-31 17:05:24 +08:00
|
|
|
APK=$COMMONDIR/magisk.apk
|
2016-11-29 04:16:01 +08:00
|
|
|
CHROMEDIR=$INSTALLER/chromeos
|
2017-06-11 01:40:08 +08:00
|
|
|
COREDIR=/magisk/.core
|
2016-11-29 04:16:01 +08:00
|
|
|
|
2016-11-13 16:58:43 +08:00
|
|
|
# Default permissions
|
|
|
|
umask 022
|
|
|
|
|
2016-09-14 10:31:13 +08:00
|
|
|
OUTFD=$2
|
|
|
|
ZIP=$3
|
|
|
|
|
2017-09-16 03:48:58 +08:00
|
|
|
if [ ! -f $COMMONDIR/util_functions.sh ]; then
|
2017-06-24 23:38:20 +09:00
|
|
|
echo "! Unable to extract zip file!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-07-10 00:17:34 +08:00
|
|
|
# Load utility fuctions
|
2017-06-19 00:15:44 +08:00
|
|
|
. $COMMONDIR/util_functions.sh
|
|
|
|
|
2017-07-10 00:17:34 +08:00
|
|
|
get_outfd
|
|
|
|
|
|
|
|
##########################################################################################
|
|
|
|
# Detection
|
|
|
|
##########################################################################################
|
|
|
|
|
2017-04-22 07:05:10 +08:00
|
|
|
ui_print "************************"
|
2017-07-31 03:03:52 +08:00
|
|
|
ui_print "* Magisk v$MAGISK_VER Installer"
|
2017-04-22 07:05:10 +08:00
|
|
|
ui_print "************************"
|
2016-09-14 10:31:13 +08:00
|
|
|
|
2017-09-26 20:21:43 +08:00
|
|
|
is_mounted /data || mount /data || is_mounted /cache || mount /cache || abort "! Unable to mount partitions"
|
2017-09-13 04:07:25 +08:00
|
|
|
mount_partitions
|
2017-06-11 01:40:08 +08:00
|
|
|
|
2017-03-12 18:13:58 +08:00
|
|
|
# read override variables
|
|
|
|
getvar KEEPVERITY
|
|
|
|
getvar KEEPFORCEENCRYPT
|
|
|
|
getvar BOOTIMAGE
|
2016-09-14 10:31:13 +08:00
|
|
|
|
2017-07-02 21:36:09 +08:00
|
|
|
# Detect version and architecture
|
|
|
|
api_level_arch_detect
|
2016-10-03 04:34:50 +08:00
|
|
|
|
2017-06-16 04:08:34 +08:00
|
|
|
[ $API -lt 21 ] && abort "! Magisk is only for Lollipop 5.0+ (SDK 21+)"
|
2016-10-30 06:13:59 +08:00
|
|
|
|
2017-07-14 01:01:25 +08:00
|
|
|
# Check if system root is installed and remove
|
|
|
|
remove_system_su
|
|
|
|
|
2016-10-30 06:13:59 +08:00
|
|
|
ui_print "- Device platform: $ARCH"
|
|
|
|
|
|
|
|
BINDIR=$INSTALLER/$ARCH
|
2017-03-12 19:22:15 +08:00
|
|
|
chmod -R 755 $CHROMEDIR $BINDIR
|
2016-10-30 06:13:59 +08:00
|
|
|
|
2016-11-13 16:58:43 +08:00
|
|
|
##########################################################################################
|
|
|
|
# Environment
|
|
|
|
##########################################################################################
|
|
|
|
|
2017-04-22 07:05:10 +08:00
|
|
|
ui_print "- Constructing environment"
|
2017-07-25 02:02:19 +08:00
|
|
|
|
2017-12-16 02:02:17 +08:00
|
|
|
if is_mounted /data; then
|
|
|
|
MAGISKBIN=/data/adb/magisk
|
|
|
|
mkdir -p /data/adb 2>/dev/null
|
|
|
|
chmod 700 /data/adb 2>/dev/null
|
|
|
|
|
|
|
|
# Some legacy migration
|
|
|
|
mv /data/magisk/stock_boot* /data 2>/dev/null
|
2017-12-18 03:08:53 +08:00
|
|
|
[ -L /data/magisk.img ] || mv /data/magisk.img /data/adb/magisk.img
|
2017-12-16 02:02:17 +08:00
|
|
|
else
|
|
|
|
MAGISKBIN=/cache/data_bin
|
|
|
|
fi
|
2017-09-11 15:26:34 +08:00
|
|
|
|
2017-04-22 07:05:10 +08:00
|
|
|
# Copy required files
|
2017-11-06 05:41:03 +08:00
|
|
|
rm -rf $MAGISKBIN/* 2>/dev/null
|
|
|
|
mkdir -p $MAGISKBIN 2>/dev/null
|
2017-09-05 21:44:22 +08:00
|
|
|
cp -af $BINDIR/. $COMMONDIR/. $CHROMEDIR $TMPDIR/bin/busybox $MAGISKBIN
|
2017-04-22 07:05:10 +08:00
|
|
|
chmod -R 755 $MAGISKBIN
|
2017-02-04 18:44:07 +08:00
|
|
|
|
2017-06-19 00:15:44 +08:00
|
|
|
# addon.d
|
|
|
|
if [ -d /system/addon.d ]; then
|
|
|
|
ui_print "- Adding addon.d survival script"
|
|
|
|
mount -o rw,remount /system
|
2017-08-02 02:21:50 +08:00
|
|
|
cp -af $INSTALLER/addon.d/99-magisk.sh /system/addon.d/99-magisk.sh
|
2017-06-19 00:15:44 +08:00
|
|
|
chmod 755 /system/addon.d/99-magisk.sh
|
|
|
|
fi
|
|
|
|
|
2017-09-28 00:54:01 +08:00
|
|
|
$BOOTMODE || recovery_actions
|
2017-04-17 16:36:49 +08:00
|
|
|
|
2017-03-12 18:13:58 +08:00
|
|
|
##########################################################################################
|
2017-09-05 21:44:22 +08:00
|
|
|
# Boot patching
|
2017-03-12 18:13:58 +08:00
|
|
|
##########################################################################################
|
|
|
|
|
2017-11-15 04:41:30 +08:00
|
|
|
[ -z $BOOTIMAGE ] && find_boot_image
|
2017-07-31 03:03:52 +08:00
|
|
|
[ -z $BOOTIMAGE ] && abort "! Unable to detect boot image"
|
2017-10-31 17:05:24 +08:00
|
|
|
ui_print "- Found boot image: $BOOTIMAGE"
|
|
|
|
|
2017-12-21 15:42:03 +08:00
|
|
|
find_dtbo_image
|
|
|
|
if [ ! -z $DTBOIMAGE ]; then
|
|
|
|
ui_print "- Found dtbo image: $DTBOIMAGE"
|
|
|
|
# Disable dtbo patch by default
|
|
|
|
[ -z $KEEPVERITY ] && KEEPVERITY=true
|
|
|
|
fi
|
|
|
|
|
2017-10-31 17:05:24 +08:00
|
|
|
eval $BOOTSIGNER -verify < $BOOTIMAGE && BOOTSIGNED=true
|
|
|
|
$BOOTSIGNED && ui_print "- Signed boot image detected"
|
2017-03-12 18:13:58 +08:00
|
|
|
|
2017-06-03 20:19:01 +08:00
|
|
|
SOURCEDMODE=true
|
|
|
|
cd $MAGISKBIN
|
2017-02-04 18:44:07 +08:00
|
|
|
|
2017-06-03 20:19:01 +08:00
|
|
|
# Source the boot patcher
|
2017-06-11 01:40:08 +08:00
|
|
|
. $COMMONDIR/boot_patch.sh "$BOOTIMAGE"
|
2017-03-12 18:13:58 +08:00
|
|
|
|
2017-11-11 01:33:50 +08:00
|
|
|
flash_boot_image new-boot.img "$BOOTIMAGE"
|
|
|
|
rm -f new-boot.img
|
|
|
|
|
2017-09-11 15:26:34 +08:00
|
|
|
if [ -f stock_boot* ]; then
|
|
|
|
rm -f /data/stock_boot* 2>/dev/null
|
2017-11-11 01:33:50 +08:00
|
|
|
is_mounted /data && mv stock_boot* /data
|
2017-09-11 15:26:34 +08:00
|
|
|
fi
|
2017-03-12 18:13:58 +08:00
|
|
|
|
2017-12-07 04:20:27 +08:00
|
|
|
$KEEPVERITY || patch_dtbo_image
|
2017-11-11 01:33:50 +08:00
|
|
|
|
|
|
|
if [ -f stock_dtbo* ]; then
|
|
|
|
rm -f /data/stock_dtbo* 2>/dev/null
|
|
|
|
is_mounted /data && mv stock_dtbo* /data
|
|
|
|
fi
|
2016-09-14 10:31:13 +08:00
|
|
|
|
2017-01-02 02:00:53 +08:00
|
|
|
cd /
|
2017-09-05 21:44:22 +08:00
|
|
|
# Cleanups
|
|
|
|
$BOOTMODE || recovery_cleanup
|
2017-08-12 23:15:39 +08:00
|
|
|
rm -rf $TMPDIR
|
2017-07-31 03:03:52 +08:00
|
|
|
|
2016-09-14 10:31:13 +08:00
|
|
|
ui_print "- Done"
|
|
|
|
exit 0
|