So this way, I ended up creating a script on my own.
Lucky enough, installing TWRP to
boot.img isn't hard at all. The install script in TWRP just replaces
ramdisk.cpio with the one
ramdisk-twrp.cpio provided in the ZIP.
The effective part of the script is as following, root is of course required.
ln -s /system/bin/linker64 /sbin/linker
cp <path-to-magiskboot> /sbin/magiskboot
/sbin/magiskboot --unpack <path-to-boot.img>
cat <path-to-[ramdisk-twrp.cpio]> > ramdisk.cpio
/sbin/magiskboot --repack boot.img
cp new-boot.img /sdcard/new-boot.img
Now the TWRP-installed
new-boot.img is located at
To install to a single slot,
dd the boot image out and apply the same process as shown above and
dd the new image back.