summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorosm0sis <osm0sis@outlook.com>2020-01-16 00:40:04 -0400
committerosm0sis <osm0sis@outlook.com>2020-01-16 01:00:32 -0400
commit21ee68f5a8c1ea0db9af10e3c23e0c635112bb91 (patch)
treec7c723b67022a2c43f3cf6a588d439d5386c2522 /tools
parentbd279e6cbabc0da33f93dd88b5d344c8ed5be771 (diff)
AK3: clean up and simplify Magisk patch logic
- only repatch when there is an Image* (i.e. don't attempt on ramdisk-only mods) - make sure new ramdisk is already copied before trying to detect Magisk patch state in case it changed - clean up Magisk patch state and exported variables immediately
Diffstat (limited to 'tools')
-rwxr-xr-xtools/ak3-core.sh76
1 files changed, 38 insertions, 38 deletions
diff --git a/tools/ak3-core.sh b/tools/ak3-core.sh
index a986ec8..01e8236 100755
--- a/tools/ak3-core.sh
+++ b/tools/ak3-core.sh
@@ -305,48 +305,49 @@ flash_boot() {
test "$dt" && dt="--dt $dt";
$bin/mkbootimg --kernel $kernel --ramdisk $ramdisk --cmdline "$cmdline" --base $home --pagesize $pagesize --kernel_offset $kerneloff --ramdisk_offset $ramdiskoff --tags_offset "$tagsoff" $dt --output $home/boot-new.img;
else
- if [ ! "$magisk_patched" ]; then
- $bin/magiskboot cpio ramdisk.cpio test;
- magisk_patched=$?;
- test $((magisk_patched & 3)) -eq 1 && $bin/magiskboot cpio ramdisk.cpio "extract .backup/.magisk .magisk";
- fi;
- if [ "$kernel" ]; then
- cp -f $kernel kernel;
- if [ $((magisk_patched & 3)) -eq 1 ]; then
- ui_print " " "Magisk detected! Patching kernel so reflashing Magisk is not necessary...";
- comp=$($bin/magiskboot decompress kernel 2>&1 | grep -v 'raw' | sed -n 's;.*\[\(.*\)\];\1;p');
- ($bin/magiskboot split $kernel || $bin/magiskboot decompress $kernel kernel) 2>/dev/null;
- if [ $? != 0 -a "$comp" ]; then
- echo "Attempting kernel unpack with busybox $comp..." >&2;
- $comp -dc $kernel > kernel;
- fi;
- $bin/magiskboot hexpatch kernel 736B69705F696E697472616D667300 77616E745F696E697472616D667300;
- if [ "$comp" ]; then
- $bin/magiskboot compress=$comp kernel kernel.$comp;
- if [ $? != 0 ]; then
- echo "Attempting kernel repack with busybox $comp..." >&2;
- $comp -9c kernel > kernel.$comp;
- fi;
- mv -f kernel.$comp kernel;
- fi;
- else
- case $kernel in
- *-dtb) rm -f kernel_dtb;;
- esac;
- fi;
- fi;
+ test "$kernel" && cp -f $kernel kernel;
test "$ramdisk" && cp -f $ramdisk ramdisk.cpio;
test "$dt" -a -f extra && cp -f $dt extra;
for i in dtb recovery_dtbo; do
test "$(eval echo \$$i)" -a -f $i && cp -f $(eval echo \$$i) $i;
done;
- if [ $((magisk_patched & 3)) -eq 1 ]; then
- export $(cat .magisk);
- test $((magisk_patched & 8)) -ne 0 && export TWOSTAGEINIT=true;
- for fdt in dtb extra kernel_dtb recovery_dtbo; do
- test -f $fdt && $bin/magiskboot dtb $fdt patch;
- done;
- fi;
+ case $kernel in
+ *Image*)
+ if [ ! "$magisk_patched" ]; then
+ $bin/magiskboot cpio ramdisk.cpio test;
+ magisk_patched=$?;
+ fi;
+ if [ $((magisk_patched & 3)) -eq 1 ]; then
+ ui_print " " "Magisk detected! Patching kernel so reflashing Magisk is not necessary...";
+ comp=$($bin/magiskboot decompress kernel 2>&1 | grep -v 'raw' | sed -n 's;.*\[\(.*\)\];\1;p');
+ ($bin/magiskboot split $kernel || $bin/magiskboot decompress $kernel kernel) 2>/dev/null;
+ if [ $? != 0 -a "$comp" ]; then
+ echo "Attempting kernel unpack with busybox $comp..." >&2;
+ $comp -dc $kernel > kernel;
+ fi;
+ $bin/magiskboot hexpatch kernel 736B69705F696E697472616D667300 77616E745F696E697472616D667300;
+ if [ "$comp" ]; then
+ $bin/magiskboot compress=$comp kernel kernel.$comp;
+ if [ $? != 0 ]; then
+ echo "Attempting kernel repack with busybox $comp..." >&2;
+ $comp -9c kernel > kernel.$comp;
+ fi;
+ mv -f kernel.$comp kernel;
+ fi;
+ test ! -f .magisk && $bin/magiskboot cpio ramdisk.cpio "extract .backup/.magisk .magisk";
+ export $(cat .magisk);
+ test $((magisk_patched & 8)) -ne 0 && export TWOSTAGEINIT=true;
+ for fdt in dtb extra kernel_dtb recovery_dtbo; do
+ test -f $fdt && $bin/magiskboot dtb $fdt patch;
+ done;
+ else
+ case $kernel in
+ *-dtb) rm -f kernel_dtb;;
+ esac;
+ fi;
+ unset magisk_patched KEEPFORCEENCRYPT KEEPVERITY SHA1 TWOSTAGEINIT;
+ ;;
+ esac;
case $ramdisk_compression in
none|cpio) nocompflag="-n";;
esac;
@@ -650,7 +651,6 @@ reset_ak() {
else
rm -rf $patch $home/rdtmp;
fi;
- unset magisk_patched KEEPFORCEENCRYPT KEEPVERITY SHA1 TWOSTAGEINIT;
setup_ak;
}