#!/usr/bin/env bash
# Check that Cobbler is able to build customized ISOs by the "cobbler buildiso" command

source ${SYSTESTS_PRELUDE} && prepare

set -x -e -o pipefail

# Preparations
cobbler distro add --name fake --arch x86_64 --kernel ${fake_kernel} --initrd ${fake_initramfs}
cobbler profile add --name fake --distro fake
cobbler system add --name testbed --profile fake

# Tmp: Create "/var/cache/cobbler" because it does not exist per default
mkdir -p /var/cache/cobbler/buildiso

# Real test
cobbler buildiso --tempdir="/var/cache/cobbler/buildiso" --iso ${tmp}/autoinst.iso --distro=fake

# Check ISO exists
[ -f ${tmp}/autoinst.iso ]

# Check ISO is bootable
cat >${tmp}/a <<-EOF
BIOS
UEFI
EOF
xorriso -indev ${tmp}/autoinst.iso -report_el_torito 2>/dev/null | awk '/^El Torito boot img[[:space:]]+:[[:space:]]+[0-9]+[[:space:]]+[a-zA-Z]+[[:space:]]+y/{print $7}' >> ${tmp}/b

diff ${tmp}/{a,b}
