From 835ece54696f7a908af34fb1c04d26db6739eae2 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 18 Jun 2018 01:40:56 +0800 Subject: [PATCH] Update default flag logic, fix S9/S9+ DTB patches --- app | 2 +- scripts/boot_patch.sh | 56 +++++++++++++++------------------------ scripts/flash_script.sh | 14 +++------- scripts/util_functions.sh | 26 ++++++++++++++++++ 4 files changed, 52 insertions(+), 46 deletions(-) diff --git a/app b/app index e6c1dd532..77430a282 160000 --- a/app +++ b/app @@ -1 +1 @@ -Subproject commit e6c1dd532d2910285d503f271183839446495360 +Subproject commit 77430a282f8a2dbea79e8ddc0df8f463dbb70767 diff --git a/scripts/boot_patch.sh b/scripts/boot_patch.sh index 699ddf1a0..107a777ae 100644 --- a/scripts/boot_patch.sh +++ b/scripts/boot_patch.sh @@ -4,18 +4,25 @@ # Magisk Boot Image Patcher # by topjohnwu # +# Usage: sh boot_patch.sh +# +# The following additional flags can be set in environment variables: +# KEEPVERITY, KEEPFORCEENCRYPT, HIGHCOMP +# # This script should be placed in a directory with the following files: # -# File name type Description +# File name Type Description # -# boot_patch.sh script A script to patch boot. Expect path to boot image as parameter. -# (this file) The script will use binaries and files in its same directory -# to complete the patching process -# monogisk binary The monolithic binary to replace /init -# magiskboot binary A tool to unpack boot image, decompress ramdisk, extract ramdisk -# , and patch the ramdisk for Magisk support -# chromeos folder This folder should store all the utilities and keys to sign -# (optional) a chromeos device, used in the tablet Pixel C +# boot_patch.sh script A script to patch boot. Expect path to boot image as parameter. +# (this file) The script will use binaries and files in its same directory +# to complete the patching process +# util_functions.sh script A script which hosts all functions requires for this script +# to work properly +# magiskinit binary The binary to replace /init, which has the magisk binary embedded +# magiskboot binary A tool to unpack boot image, decompress ramdisk, extract ramdisk, +# and patch the ramdisk for Magisk support +# chromeos folder This folder should store all the utilities and keys to sign +# (optional) a chromeos device. Used for Pixel C # # If the script is not running as root, then the input boot image should be a stock image # or have a backup included in ramdisk internally, since we cannot access the stock boot @@ -27,51 +34,32 @@ ########################################################################################## # Pure bash dirname implementation -dirname_wrap() { +getdir() { case "$1" in - */*) - dir=${1%/*} - [ -z $dir ] && echo "/" || echo $dir - ;; - *) - echo "." - ;; + */*) dir=${1%/*}; [ -z $dir ] && echo "/" || echo $dir ;; + *) echo "." ;; esac } -# Pure bash basename implementation -basename_wrap() { - echo ${1##*/} -} - ########################################################################################## # Initialization ########################################################################################## if [ -z $SOURCEDMODE ]; then # Switch to the location of the script file - cd "`dirname_wrap "${BASH_SOURCE:-$0}"`" + cd "`getdir "${BASH_SOURCE:-$0}"`" # Load utility functions . ./util_functions.sh fi BOOTIMAGE="$1" - [ -e "$BOOTIMAGE" ] || abort "$BOOTIMAGE does not exist!" -# Presets +# Flags [ -z $KEEPVERITY ] && KEEPVERITY=false +[ -z $KEEPFORCEENCRYPT ] && KEEPFORCEENCRYPT=false [ -z $HIGHCOMP ] && HIGHCOMP=false -if [ -z $KEEPFORCEENCRYPT ]; then - if [ "`getprop ro.crypto.state`" = "encrypted" ]; then - KEEPFORCEENCRYPT=true - ui_print "- Encrypted data detected, keep forceencrypt" - else - KEEPFORCEENCRYPT=false - fi -fi - chmod -R 755 . # Extract magisk if doesn't exist diff --git a/scripts/flash_script.sh b/scripts/flash_script.sh index f7c355ccc..6e56e1408 100644 --- a/scripts/flash_script.sh +++ b/scripts/flash_script.sh @@ -51,24 +51,16 @@ mount_partitions find_boot_image find_dtbo_image -# read override variables -getvar KEEPVERITY -getvar KEEPFORCEENCRYPT -getvar BOOTIMAGE +get_flags [ -z $BOOTIMAGE ] && abort "! Unable to detect boot image" ui_print "- Found boot/ramdisk image: $BOOTIMAGE" - -if [ ! -z $DTBOIMAGE ]; then - ui_print "- Found dtbo image: $DTBOIMAGE" - # Disable dtbo patch by default - [ -z $KEEPVERITY ] && KEEPVERITY=true -fi +[ -z $DTBOIMAGE ] || ui_print "- Found dtbo image: $DTBOIMAGE" # Detect version and architecture api_level_arch_detect -[ $API -lt 21 ] && abort "! Magisk is only for Lollipop 5.0+ (SDK 21+)" +[ $API -lt 21 ] && abort "! Magisk is only for Android higher than Lollipop (5.0+) (SDK 21+)" ui_print "- Device platform: $ARCH" diff --git a/scripts/util_functions.sh b/scripts/util_functions.sh index e049ff04c..de7749943 100644 --- a/scripts/util_functions.sh +++ b/scripts/util_functions.sh @@ -82,6 +82,32 @@ mount_partitions() { fi } +get_flags() { + # override variables + getvar KEEPVERITY + getvar KEEPFORCEENCRYPT + HIGHCOMP=false + if [ -z $KEEPVERITY ]; then + KEEPVERITY=false + hardware=`grep_cmdline androidboot.hardware` + for hw in taimen walleye; do + if [ "$hw" = "$hardware" ]; then + KEEPVERITY=true + ui_print "- Device on whitelist, keep avb-verity" + break + fi + done + fi + if [ -z $KEEPFORCEENCRYPT ]; then + if [ "`getprop ro.crypto.state`" = "encrypted" ]; then + KEEPFORCEENCRYPT=true + ui_print "- Encrypted data detected, keep forceencrypt" + else + KEEPFORCEENCRYPT=false + fi + fi +} + grep_cmdline() { REGEX="s/^$1=//p" sed -E 's/ +/\n/g' /proc/cmdline | sed -n "$REGEX" 2>/dev/null