From 6ce9225f52159fde3a9d6e3e2d7a28e8ea08c046 Mon Sep 17 00:00:00 2001 From: vvb2060 Date: Sat, 19 Dec 2020 14:12:12 -0800 Subject: [PATCH] Check block dev ro status magisk is shared object, use static busybox instead --- app/src/main/res/raw/manager.sh | 14 ++++++++++---- scripts/util_functions.sh | 27 ++++++++++++++++++--------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/app/src/main/res/raw/manager.sh b/app/src/main/res/raw/manager.sh index cd388c6c6..aa160d58c 100644 --- a/app/src/main/res/raw/manager.sh +++ b/app/src/main/res/raw/manager.sh @@ -30,10 +30,16 @@ direct_install() { rm -f $MAGISKBIN/new-boot.img echo "- Flashing new boot image" flash_image $1/new-boot.img $2 - if [ $? -ne 0 ]; then - echo "! Insufficient partition size" - return 1 - fi + case $? in + 1) + echo "! Insufficient partition size" + return 1 + ;; + 2) + echo "! $2 is read only" + return 2 + ;; + esac rm -rf $1 return 0 } diff --git a/scripts/util_functions.sh b/scripts/util_functions.sh index 2e97325a3..501702804 100644 --- a/scripts/util_functions.sh +++ b/scripts/util_functions.sh @@ -388,8 +388,6 @@ find_boot_image() { } flash_image() { - # Make sure all blocks are writable - $MAGISKBIN/magisk --unlock-blocks 2>/dev/null case "$1" in *.gz) CMD1="$MAGISKBIN/magiskboot decompress '$1' - 2>/dev/null";; *) CMD1="cat '$1'";; @@ -401,16 +399,19 @@ flash_image() { CMD2="cat -" fi if [ -b "$2" ]; then - local img_sz=`stat -c '%s' "$1"` - local blk_sz=`blockdev --getsize64 "$2"` - [ $img_sz -gt $blk_sz ] && return 1 - eval $CMD1 | eval $CMD2 | cat - /dev/zero > "$2" 2>/dev/null + local img_sz=$(stat -c '%s' "$1") + local blk_sz=$(blockdev --getsize64 "$2") + [ "$img_sz" -gt "$blk_sz" ] && return 1 + blockdev --setrw "$2" + local blk_ro=$(blockdev --getro "$2") + [ "$blk_ro" -eq 1 ] && return 2 + eval "$CMD1" | eval "$CMD2" | cat - /dev/zero > "$2" 2>/dev/null elif [ -c "$2" ]; then flash_eraseall "$2" >&2 - eval $CMD1 | eval $CMD2 | nandwrite -p "$2" - >&2 + eval "$CMD1" | eval "$CMD2" | nandwrite -p "$2" - >&2 else ui_print "- Not block or char device, storing image" - eval $CMD1 | eval $CMD2 > "$2" 2>/dev/null + eval "$CMD1" | eval "$CMD2" > "$2" 2>/dev/null fi return 0 } @@ -445,7 +446,15 @@ install_magisk() { # Restore the original boot partition path [ "$BOOTNAND" ] && BOOTIMAGE=$BOOTNAND - flash_image new-boot.img "$BOOTIMAGE" || abort "! Insufficient partition size" + flash_image new-boot.img "$BOOTIMAGE" + case $? in + 1) + abort "! Insufficient partition size" + ;; + 2) + abort "! $BOOTIMAGE is read only" + ;; + esac ./magiskboot cleanup rm -f new-boot.img