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