[Magisk] IzaacJ:
Did some changes to update_binary with your info as guidance, and just need a second opinion since I'm NOT used to shell scripting :P

#!/sbin/sh
##########################################################################################
#
# Magisk v4
# by topjohnwu
#
# This zip will patch your boot image with Magisk support
#
##########################################################################################

# Flashable update-binary preparation - Code left out

# Functions
find_boot_image() {
if [ -z "$BOOTIMAGE" ]; then
for PARTITION in kern-a KERN-A android_boot ANDROID_BOOT kernel KERNEL boot BOOT lnx LNX; do
BOOTIMAGE=$(readlink /dev/block/by-name/$PARTITION || readlink /dev/block/platform/*/by-name/$PARTITION || readlink /dev/block/platform/*/*/by-name/$PARTITION)
if [ ! -z "$BOOTIMAGE" ]; then break; fi
done
fi
}

custom_boot_image() {
dd if=/dev/block/mmcblk0 of=/cache/boot.img count=16777216 skip=30932992
CUSTBOOTIMAGE="/cache/boot.img"
}
# Some functions - Code left out
# Main - Code left out

# Get the boot image
find_boot_image
if [ -z "$BOOTIMAGE" ]; then
custom_boot_image
if [ -z "$CUSTBOOTIMAGE" ]; then
ui_print "! Unable to detect boot image"
exit 1
fi
fi
# Code left out
# Detection all done, start installing - Code left out
# Environment - Code left out

##########################################################################################
# Boot image patch
##########################################################################################

if [ -z "$BOOTIMAGE" ]; then
ui_print "- Found Custom Boot Image: $CUSTBOOTIMAGE"
else
ui_print "- Found Boot Image: $BOOTIMAGE"
fi
# Code left out
if [ -z "$BOOTIMAGE" ]; then
ORIGBOOT="$CUSTBOOTIMAGE"
else
ORIGBOOT=/boottmp/boot.img
fi

# Dumping boot image - Skipped if CUSTBOOTIMAGE, since it's already an image
if [ -z "$CUSTBOOTIMAGE" ]; then
ui_print "- Dumping boot image"
dd if=$BOOTIMAGE of=$ORIGBOOT
fi

# Unpacking boot image - Code left out

# Backups
if [ -d ".backup" ]; then
ui_print "- Reverting ramdisk backup"
cp -af .backup/* .
rm -rf magisk init.magisk.rc sbin/magic_mask.sh 2>/dev/null
else
if [ -d "magisk" ]; then
if [ -f "/data/stock_boot.img" ]; then
ui_print "- Reverting boot image backup"
if [ -z "$BOOTIMAGE" ]; then
dd if=/dev/zero of=$CUSTBOOTIMAGE bs=4096
if (is_mounted /data); then
dd if=/data/stock_boot.img of=/dev/block/mmcblk0 count=16777216 skip=30932992 bs=4096
else
dd if=/cache/stock_boot.img of=/dev/block/mmcblk0 count=16777216 skip=30932992 bs=4096
fi
else
dd if=/dev/zero of=$BOOTIMAGE bs=4096
if (is_mounted /data); then
dd if=/data/stock_boot.img of=$BOOTIMAGE bs=4096
else
dd if=/data/stock_boot.img of=$BOOTIMAGE bs=4096
fi
fi
else
ui_print "! No backups found"
ui_print "! Installer will still proceed, but might cause issues"
ui_print "! If possible, please restore to stock boot then flash Magisk again"
fi
else
ui_print "- Creating backups"
mkdir .backup
cp -af init.rc *fstab* verity_key sepolicy .backup 2>/dev/null
if (is_mounted /data); then
cp $ORIGBOOT /data/stock_boot.img
else
cp $ORIGBOOT /cache/stock_boot.img
fi
fi
fi

# Patch ramdisk - Code left out

ui_print "- Repacking boot image"
repack_boot

# Size checks - Code left out

ui_print "- Flashing new boot image"
if [ -z "$BOOTIMAGE" ]; then
dd if=/dev/zero of=/dev/block/mmcblk0 bs=4096 count=16777216 skip=30932992
dd if=$NEWBOOT of=/dev/block/mmcblk0 bs=4096 count=16777216 skip=30932992
else
dd if=/dev/zero of=$BOOTIMAGE bs=4096
dd if=$NEWBOOT of=$BOOTIMAGE bs=4096
fi

Left out code that I haven't touched. Does this look okey? :)