Overcome some quirks in Android Lollipop

This commit is contained in:
topjohnwu
2017-07-25 03:10:01 +08:00
parent ce87591c62
commit b7986a351c
7 changed files with 56 additions and 27 deletions

View File

@@ -106,7 +106,7 @@ fi
[ -z $KEEPFORCEENCRYPT ] && KEEPFORCEENCRYPT=false
# Detect whether running as root
[ `id -u` -eq 0 ] && ROOT=true || ROOT=false
id | grep "uid=0" >/dev/null 2>&1 && ROOT=true || ROOT=false
# Switch to the location of the script file
[ -z $SOURCEDMODE ] && cd "`dirname_wrap "${BASH_SOURCE:-$0}"`"
@@ -156,12 +156,7 @@ case $? in
1 ) # Magisk patched
ui_print_wrap "- Magisk patched image detected!"
# Find SHA1 of stock boot image
if [ -z $SHA1 ]; then
./magiskboot --cpio-extract ramdisk.cpio init.magisk.rc init.magisk.rc.old
SHA1=`grep_prop "# STOCKSHA1" init.magisk.rc.old`
rm -f init.magisk.rc.old
fi
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio-stocksha1 ramdisk.cpio`
OK=false
./magiskboot --cpio-restore ramdisk.cpio
if [ $? -eq 0 ]; then

View File

@@ -183,6 +183,7 @@ if ! $BOOTMODE; then
$MAGISKBIN/magisk --umountimg /magisk $MAGISKLOOP
rmdir /magisk
recovery_cleanup
rm -rf $TMPDIR
fi
ui_print "- Done"

View File

@@ -101,11 +101,7 @@ case $? in
1 ) # Magisk patched
ui_print_wrap "- Magisk patched image detected!"
# Find SHA1 of stock boot image
if [ -z $SHA1 ]; then
./magiskboot --cpio-extract ramdisk.cpio init.magisk.rc init.magisk.rc.old
SHA1=`grep_prop "# STOCKSHA1" init.magisk.rc.old`
rm -f init.magisk.rc.old
fi
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio-stocksha1 ramdisk.cpio`
[ ! -z $SHA1 ] && STOCKDUMP=/data/stock_boot_${SHA1}.img
if [ -f ${STOCKDUMP}.gz ]; then
ui_print_wrap "- Boot image backup found!"

View File

@@ -1,10 +1,10 @@
##########################################################################################
#
#
# Magisk General Utility Functions
# by topjohnwu
#
#
# Used in flash_script.sh, addon.d.sh, magisk module installers, and uninstaller
#
#
##########################################################################################
MAGISK_VERSION_STUB
@@ -30,7 +30,7 @@ get_outfd() {
ui_print() {
if $BOOTMODE; then
echo "$1"
else
else
echo -n -e "ui_print $1\n" >> /proc/self/fd/$OUTFD
echo -n -e "ui_print\n" >> /proc/self/fd/$OUTFD
fi
@@ -128,10 +128,21 @@ api_level_arch_detect() {
recovery_actions() {
# TWRP bug fix
mount -o bind /dev/urandom /dev/random
# Preserve environment varibles
OLD_PATH=$PATH
OLD_LD_PATH=$LD_LIBRARY_PATH
# Extract busybox from Magisk Manager
if [ -f $INSTALLER/common/magisk.apk ]; then
mkdir -p $TMPDIR/bin
[ $ARCH = "arm" -o $ARCH = "arm64" ] && BBPATH=lib/armeabi-v7a || BBPATH=lib/x86
unzip -p $INSTALLER/common/magisk.apk $BBPATH/libbusybox.so > $TMPDIR/bin/busybox 2>/dev/null
chmod 755 $TMPDIR/bin/busybox
$TMPDIR/bin/busybox --install -s $TMPDIR/bin
export PATH=$PATH:$TMPDIR/bin
fi
# Temporarily block out all custom recovery binaries/libs
mv /sbin /sbin_tmp
# Add all possible library paths
OLD_LD_PATH=$LD_LIBRARY_PATH
$IS64BIT && export LD_LIBRARY_PATH=/system/lib64:/system/vendor/lib64 || export LD_LIBRARY_PATH=/system/lib:/system/vendor/lib
}
@@ -139,6 +150,7 @@ recovery_cleanup() {
mv /sbin_tmp /sbin
# Clear LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$OLD_LD_PATH
export PATH=$OLD_PATH
ui_print "- Unmounting partitions"
umount -l /system
umount -l /vendor 2>/dev/null