Fix installation in custom recoveries

This commit is contained in:
topjohnwu 2018-04-29 14:04:18 +08:00
parent cecc0b932d
commit fc9d4034a9
3 changed files with 38 additions and 39 deletions

View File

@ -84,7 +84,7 @@ chmod -R 755 .
CHROMEOS=false CHROMEOS=false
ui_print "- Unpacking boot image" ui_print "- Unpacking boot image"
./magiskboot --unpack "$BOOTIMAGE" eval $LIB32PFX ./magiskboot --unpack "$BOOTIMAGE"
case $? in case $? in
1 ) 1 )
@ -113,14 +113,14 @@ esac
# Test patch status and do restore, after this section, ramdisk.cpio.orig is guaranteed to exist # Test patch status and do restore, after this section, ramdisk.cpio.orig is guaranteed to exist
ui_print "- Checking ramdisk status" ui_print "- Checking ramdisk status"
MAGISK_PATCHED=false MAGISK_PATCHED=false
./magiskboot --cpio ramdisk.cpio test eval $LIB32PFX ./magiskboot --cpio ramdisk.cpio test
case $? in case $? in
0 ) # Stock boot 0 ) # Stock boot
ui_print "- Stock boot image detected" ui_print "- Stock boot image detected"
ui_print "- Backing up stock boot image" ui_print "- Backing up stock boot image"
SHA1=`./magiskboot --sha1 "$BOOTIMAGE" 2>/dev/null` SHA1=`eval $LIB32PFX ./magiskboot --sha1 "$BOOTIMAGE" 2>/dev/null`
STOCKDUMP=stock_boot_${SHA1}.img.gz STOCKDUMP=stock_boot_${SHA1}.img.gz
./magiskboot --compress "$BOOTIMAGE" $STOCKDUMP eval $LIB32PFX ./magiskboot --compress "$BOOTIMAGE" $STOCKDUMP
cp -af ramdisk.cpio ramdisk.cpio.orig cp -af ramdisk.cpio ramdisk.cpio.orig
;; ;;
1 ) # Magisk patched 1 ) # Magisk patched
@ -140,8 +140,8 @@ esac
if $MAGISK_PATCHED; then if $MAGISK_PATCHED; then
ui_print "- Magisk patched image detected" ui_print "- Magisk patched image detected"
# Find SHA1 of stock boot image # Find SHA1 of stock boot image
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null` [ -z $SHA1 ] && SHA1=`eval $LIB32PFX ./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null`
./magiskboot --cpio ramdisk.cpio restore eval $LIB32PFX ./magiskboot --cpio ramdisk.cpio restore
cp -af ramdisk.cpio ramdisk.cpio.orig cp -af ramdisk.cpio ramdisk.cpio.orig
fi fi
@ -156,9 +156,9 @@ fi
ui_print "- Patching ramdisk" ui_print "- Patching ramdisk"
./magiskboot --cpio ramdisk.cpio \ eval $LIB32PFX ./magiskboot --cpio ramdisk.cpio \
'add 750 init magiskinit' \ \"add 750 init magiskinit\" \
"magisk ramdisk.cpio.orig $HIGHCOMP $KEEPVERITY $KEEPFORCEENCRYPT $SHA1" \"magisk ramdisk.cpio.orig $HIGHCOMP $KEEPVERITY $KEEPFORCEENCRYPT $SHA1\"
rm -f ramdisk.cpio.orig rm -f ramdisk.cpio.orig
@ -167,17 +167,17 @@ rm -f ramdisk.cpio.orig
########################################################################################## ##########################################################################################
if ! $KEEPVERITY && [ -f dtb ]; then if ! $KEEPVERITY && [ -f dtb ]; then
./magiskboot --dtb-patch dtb && ui_print "- Patching fstab in dtb to remove dm-verity" eval $LIB32PFX ./magiskboot --dtb-patch dtb && ui_print "- Patching fstab in dtb to remove dm-verity"
fi fi
if [ -f kernel ]; then if [ -f kernel ]; then
# Remove Samsung RKP in stock kernel # Remove Samsung RKP in stock kernel
./magiskboot --hexpatch kernel \ eval $LIB32PFX ./magiskboot --hexpatch kernel \
49010054011440B93FA00F71E9000054010840B93FA00F7189000054001840B91FA00F7188010054 \ 49010054011440B93FA00F71E9000054010840B93FA00F7189000054001840B91FA00F7188010054 \
A1020054011440B93FA00F7140020054010840B93FA00F71E0010054001840B91FA00F7181010054 A1020054011440B93FA00F7140020054010840B93FA00F71E0010054001840B91FA00F7181010054
# skip_initramfs -> want_initramfs # skip_initramfs -> want_initramfs
./magiskboot --hexpatch kernel \ eval $LIB32PFX ./magiskboot --hexpatch kernel \
736B69705F696E697472616D6673 \ 736B69705F696E697472616D6673 \
77616E745F696E697472616D6673 77616E745F696E697472616D6673
fi fi
@ -187,9 +187,9 @@ fi
########################################################################################## ##########################################################################################
ui_print "- Repacking boot image" ui_print "- Repacking boot image"
./magiskboot --repack "$BOOTIMAGE" || abort "! Unable to repack boot image!" eval $LIB32PFX ./magiskboot --repack "$BOOTIMAGE" || abort "! Unable to repack boot image!"
# Sign chromeos boot # Sign chromeos boot
$CHROMEOS && sign_chromeos $CHROMEOS && sign_chromeos
./magiskboot --cleanup eval $LIB32PFX ./magiskboot --cleanup

View File

@ -45,7 +45,7 @@ cd $MAGISKBIN
ui_print "- Found Boot Image: $BOOTIMAGE" ui_print "- Found Boot Image: $BOOTIMAGE"
ui_print "- Unpacking boot image" ui_print "- Unpacking boot image"
./magiskboot --unpack "$BOOTIMAGE" eval $LIB32PFX ./magiskboot --unpack "$BOOTIMAGE"
CHROMEOS=false CHROMEOS=false
case $? in case $? in
@ -67,7 +67,7 @@ esac
# Detect boot image state # Detect boot image state
ui_print "- Checking ramdisk status" ui_print "- Checking ramdisk status"
./magiskboot --cpio ramdisk.cpio test eval $LIB32PFX ./magiskboot --cpio ramdisk.cpio test
case $? in case $? in
0 ) # Stock boot 0 ) # Stock boot
ui_print "- Stock boot image detected" ui_print "- Stock boot image detected"
@ -76,14 +76,14 @@ case $? in
1|2 ) # Magisk patched 1|2 ) # Magisk patched
ui_print "- Magisk patched image detected" ui_print "- Magisk patched image detected"
# Find SHA1 of stock boot image # Find SHA1 of stock boot image
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null` [ -z $SHA1 ] && SHA1=`eval $LIB32PFX ./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null`
OK=false OK=false
[ ! -z $SHA1 ] && restore_imgs $SHA1 && OK=true [ ! -z $SHA1 ] && restore_imgs $SHA1 && OK=true
if ! $OK; then if ! $OK; then
ui_print "! Boot image backup unavailable" ui_print "! Boot image backup unavailable"
ui_print "- Restoring ramdisk with internal backup" ui_print "- Restoring ramdisk with internal backup"
./magiskboot --cpio ramdisk.cpio restore eval $LIB32PFX ./magiskboot --cpio ramdisk.cpio restore
./magiskboot --repack $BOOTIMAGE eval $LIB32PFX ./magiskboot --repack $BOOTIMAGE
# Sign chromeos boot # Sign chromeos boot
$CHROMEOS && sign_chromeos $CHROMEOS && sign_chromeos
flash_boot_image new-boot.img "$BOOTIMAGE" flash_boot_image new-boot.img "$BOOTIMAGE"

View File

@ -20,7 +20,7 @@ MAGISKBIN=/data/adb/magisk
[ -z $MOUNTPATH ] && MOUNTPATH=/sbin/.core/img [ -z $MOUNTPATH ] && MOUNTPATH=/sbin/.core/img
[ -z $IMG ] && IMG=/data/adb/magisk.img [ -z $IMG ] && IMG=/data/adb/magisk.img
BOOTSIGNER="/system/bin/dalvikvm -Xnodex2oat -Xnoimage-dex2oat -cp \$APK com.topjohnwu.magisk.utils.BootSigner" BOOTSIGNER="eval \$LIBPFX /system/bin/dalvikvm -Xnodex2oat -Xnoimage-dex2oat -cp \$APK com.topjohnwu.magisk.utils.BootSigner"
BOOTSIGNED=false BOOTSIGNED=false
get_outfd() { get_outfd() {
@ -128,15 +128,15 @@ find_boot_image() {
run_migrations() { run_migrations() {
# Update the broken boot backup # Update the broken boot backup
if [ -f /data/stock_boot_.img.gz ]; then if [ -f /data/stock_boot_.img.gz ]; then
$MAGISKBIN/magiskboot --decompress /data/stock_boot_.img.gz /data/stock_boot.img eval $LIB32PFX $MAGISKBIN/magiskboot --decompress /data/stock_boot_.img.gz /data/stock_boot.img
fi fi
# Update our previous backup to new format if exists # Update our previous backup to new format if exists
if [ -f /data/stock_boot.img ]; then if [ -f /data/stock_boot.img ]; then
ui_print "- Migrating boot image backup" ui_print "- Migrating boot image backup"
SHA1=`$MAGISKBIN/magiskboot --sha1 /data/stock_boot.img 2>/dev/null` SHA1=`eval $LIB32PFX $MAGISKBIN/magiskboot --sha1 /data/stock_boot.img 2>/dev/null`
STOCKDUMP=/data/stock_boot_${SHA1}.img STOCKDUMP=/data/stock_boot_${SHA1}.img
mv /data/stock_boot.img $STOCKDUMP mv /data/stock_boot.img $STOCKDUMP
$MAGISKBIN/magiskboot --compress $STOCKDUMP eval $LIB32PFX $MAGISKBIN/magiskboot --compress $STOCKDUMP
fi fi
# Move the stock backups # Move the stock backups
if [ -f /data/magisk/stock_boot* ]; then if [ -f /data/magisk/stock_boot* ]; then
@ -154,7 +154,7 @@ run_migrations() {
flash_boot_image() { flash_boot_image() {
# Make sure all blocks are writable # Make sure all blocks are writable
$MAGISKBIN/magisk --unlock-blocks 2>/dev/null eval $LIB32PFX $MAGISKBIN/magisk --unlock-blocks 2>/dev/null
case "$1" in case "$1" in
*.gz) COMMAND="gzip -d < '$1'";; *.gz) COMMAND="gzip -d < '$1'";;
*) COMMAND="cat '$1'";; *) COMMAND="cat '$1'";;
@ -184,11 +184,11 @@ find_dtbo_image() {
patch_dtbo_image() { patch_dtbo_image() {
if [ ! -z $DTBOIMAGE ]; then if [ ! -z $DTBOIMAGE ]; then
if $MAGISKBIN/magiskboot --dtb-test $DTBOIMAGE; then if eval $LIB32PFX $MAGISKBIN/magiskboot --dtb-test $DTBOIMAGE; then
ui_print "- Backing up stock dtbo image" ui_print "- Backing up stock dtbo image"
$MAGISKBIN/magiskboot --compress $DTBOIMAGE $MAGISKBIN/stock_dtbo.img.gz eval $LIB32PFX $MAGISKBIN/magiskboot --compress $DTBOIMAGE $MAGISKBIN/stock_dtbo.img.gz
ui_print "- Patching fstab in dtbo to remove avb-verity" ui_print "- Patching fstab in dtbo to remove avb-verity"
$MAGISKBIN/magiskboot --dtb-patch $DTBOIMAGE eval $LIB32PFX $MAGISKBIN/magiskboot --dtb-patch $DTBOIMAGE
return 0 return 0
fi fi
fi fi
@ -200,7 +200,7 @@ restore_imgs() {
STOCKDTBO=/data/stock_dtbo.img.gz STOCKDTBO=/data/stock_dtbo.img.gz
# Make sure all blocks are writable # Make sure all blocks are writable
$MAGISKBIN/magisk --unlock-blocks 2>/dev/null eval $LIB32PFX $MAGISKBIN/magisk --unlock-blocks 2>/dev/null
find_dtbo_image find_dtbo_image
if [ ! -z "$DTBOIMAGE" -a -f "$STOCKDTBO" ]; then if [ ! -z "$DTBOIMAGE" -a -f "$STOCKDTBO" ]; then
ui_print "- Restoring stock dtbo image" ui_print "- Restoring stock dtbo image"
@ -220,7 +220,7 @@ sign_chromeos() {
ui_print "- Signing ChromeOS boot image" ui_print "- Signing ChromeOS boot image"
echo > empty echo > empty
./chromeos/futility vbutil_kernel --pack new-boot.img.signed \ eval $LIBPFX ./chromeos/futility vbutil_kernel --pack new-boot.img.signed \
--keyblock ./chromeos/kernel.keyblock --signprivate ./chromeos/kernel_data_key.vbprivk \ --keyblock ./chromeos/kernel.keyblock --signprivate ./chromeos/kernel_data_key.vbprivk \
--version 1 --vmlinuz new-boot.img --config empty --arch arm --bootloader empty --flags 0x1 --version 1 --vmlinuz new-boot.img --config empty --arch arm --bootloader empty --flags 0x1
@ -287,7 +287,6 @@ recovery_actions() {
mount -o bind /dev/urandom /dev/random mount -o bind /dev/urandom /dev/random
# Preserve environment varibles # Preserve environment varibles
OLD_PATH=$PATH OLD_PATH=$PATH
OLD_LD_PATH=$LD_LIBRARY_PATH
if [ ! -d $TMPDIR/bin ]; then if [ ! -d $TMPDIR/bin ]; then
# Add busybox to PATH # Add busybox to PATH
mkdir -p $TMPDIR/bin mkdir -p $TMPDIR/bin
@ -297,13 +296,13 @@ recovery_actions() {
fi fi
# Temporarily block out all custom recovery binaries/libs # Temporarily block out all custom recovery binaries/libs
mv /sbin /sbin_tmp mv /sbin /sbin_tmp
# Add all possible library paths # Set library paths
export LD_LIBRARY_PATH=/system/lib:/system/vendor/lib $IS64BIT && LIBPFX="LD_LIBRARY_PATH=/system/lib64:/system/vendor/lib64" || LIBPFX="LD_LIBRARY_PATH=/system/lib:/system/vendor/lib"
LIB32PFX="LD_LIBRARY_PATH=/system/lib:/system/vendor/lib"
} }
recovery_cleanup() { recovery_cleanup() {
mv /sbin_tmp /sbin 2>/dev/null mv /sbin_tmp /sbin 2>/dev/null
export LD_LIBRARY_PATH=$OLD_LD_PATH
[ -z $OLD_PATH ] || export PATH=$OLD_PATH [ -z $OLD_PATH ] || export PATH=$OLD_PATH
ui_print "- Unmounting partitions" ui_print "- Unmounting partitions"
umount -l /system_root 2>/dev/null umount -l /system_root 2>/dev/null
@ -349,7 +348,7 @@ request_zip_size_check() {
} }
image_size_check() { image_size_check() {
SIZE="`$MAGISKBIN/magisk --imgsize $IMG`" SIZE="`eval $LIB32PFX $MAGISKBIN/magisk --imgsize $IMG`"
curUsedM=`echo "$SIZE" | cut -d" " -f1` curUsedM=`echo "$SIZE" | cut -d" " -f1`
curSizeM=`echo "$SIZE" | cut -d" " -f2` curSizeM=`echo "$SIZE" | cut -d" " -f2`
curFreeM=$((curSizeM - curUsedM)) curFreeM=$((curSizeM - curUsedM))
@ -363,28 +362,28 @@ mount_magisk_img() {
if [ "$reqSizeM" -gt "$curFreeM" ]; then if [ "$reqSizeM" -gt "$curFreeM" ]; then
newSizeM=$(((reqSizeM + curUsedM) / 32 * 32 + 64)) newSizeM=$(((reqSizeM + curUsedM) / 32 * 32 + 64))
ui_print "- Resizing $IMG to ${newSizeM}M" ui_print "- Resizing $IMG to ${newSizeM}M"
$MAGISKBIN/magisk --resizeimg $IMG $newSizeM >&2 eval $LIB32PFX $MAGISKBIN/magisk --resizeimg $IMG $newSizeM >&2
fi fi
else else
newSizeM=$((reqSizeM / 32 * 32 + 64)); newSizeM=$((reqSizeM / 32 * 32 + 64));
ui_print "- Creating $IMG with size ${newSizeM}M" ui_print "- Creating $IMG with size ${newSizeM}M"
$MAGISKBIN/magisk --createimg $IMG $newSizeM >&2 eval $LIB32PFX $MAGISKBIN/magisk --createimg $IMG $newSizeM >&2
fi fi
ui_print "- Mounting $IMG to $MOUNTPATH" ui_print "- Mounting $IMG to $MOUNTPATH"
MAGISKLOOP=`$MAGISKBIN/magisk --mountimg $IMG $MOUNTPATH` MAGISKLOOP=`eval $LIB32PFX $MAGISKBIN/magisk --mountimg $IMG $MOUNTPATH`
is_mounted $MOUNTPATH || abort "! $IMG mount failed..." is_mounted $MOUNTPATH || abort "! $IMG mount failed..."
} }
unmount_magisk_img() { unmount_magisk_img() {
$MAGISKBIN/magisk --umountimg $MOUNTPATH $MAGISKLOOP eval $LIB32PFX $MAGISKBIN/magisk --umountimg $MOUNTPATH $MAGISKLOOP
# Shrink the image if possible # Shrink the image if possible
image_size_check $IMG image_size_check $IMG
newSizeM=$((curUsedM / 32 * 32 + 64)) newSizeM=$((curUsedM / 32 * 32 + 64))
if [ $curSizeM -gt $newSizeM ]; then if [ $curSizeM -gt $newSizeM ]; then
ui_print "- Shrinking $IMG to ${newSizeM}M" ui_print "- Shrinking $IMG to ${newSizeM}M"
$MAGISKBIN/magisk --resizeimg $IMG $newSizeM eval $LIB32PFX $MAGISKBIN/magisk --resizeimg $IMG $newSizeM
fi fi
} }