#!/bin/sh

if test -z "$1"
then
    echo "syntax: $0 PATH-TO-LCITOOL"
    exit 1
fi

LCITOOL=$1

if ! test -x "$LCITOOL"
then
    echo "$LCITOOL is not executable"
    exit 1
fi

HOSTS=$($LCITOOL hosts | grep -v -E '(freebsd|macos)')

for host in $HOSTS
do
    if test "$host" = "centos-stream"
    then
        $LCITOOL dockerfile $host libvirt+minimal,libvirt-glib,libvirt-dbus > ci-$host.Dockerfile
    else
        $LCITOOL dockerfile $host libvirt+dist,libvirt-glib+dist,libvirt-dbus > ci-$host.Dockerfile
    fi

    # These distros versions shipped the cpu_map.xml file in
    # the wrong package, so we need to pull libvirt-daemon
    # to make sure tests pass.
    if test "$host" = "debian-9" ||
       test "$host" = "ubuntu-1804"
    then
        sed -i -e 's/libvirt-dev/libvirt-dev libvirt-daemon/' ci-$host.Dockerfile
    fi
done
