set -e

orig_iso=serenelinux_18q4.3.4_beta1.iso
new_files=$PWD/iso
new_iso=$PWD/SereneLinux_18Q4.3.4_Beta1_Fix.iso
mbr_template=isohdpfx.bin

xorriso -as mkisofs \
	-r -J --joliet-long \
	-V 'SereneLinux_18Q4.3.4_Beta1' \
	-o "$new_iso" \
	-isohybrid-mbr "$mbr_template" \
	-partition_offset 16 \
	-c isolinux/boot.cat \
	-b isolinux/isolinux.bin \
	-no-emul-boot -boot-load-size 4 -boot-info-table \
	-eltorito-alt-boot \
	-e 'boot/grub/efi.img' \
	-no-emul-boot \
	-boot-load-size 4672 \
	-isohybrid-gpt-basdat \
	-isohybrid-apm-hfsplus \
	"$new_files"

#↑ Reference: https://wiki.debian.org/RepackBootableISO#What_to_do_if_no_file_.2F.disk.2Fmkisofs_exists

cd `dirname "$new_iso"`
echo -n "Calculating MD5 checksum… "
md5sum `basename "$new_iso"` > "$new_iso".md5
echo 'Done!'
echo -n "Calculating SHA256 checksum… "
sha256sum `basename "$new_iso"` > "$new_iso".sha256
echo 'Done!'

#↓ OUTDATED
#cd iso && mkisofs -o ../patched.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V "SereneLinux_18Q4.3.4_Beta1_Fix" .
