#!/bin/bash
if [ "$#" -lt 2 ]; then
    echo "Usage: refresh-group <group-name> <repoquery-args>..."
    exit 1
fi
set -e
repodata=`find /var/cache/koschei/repodata/ -path '*/primary-f*' -name repomd.xml | sort -nr | head -n1 | xargs dirname | xargs dirname`
repoid=`grep -o 'primary-[^/]*' <<< "$repodata"`
group=$1
shift
dnf repoquery -q --available --repofrompath "$repoid,$repodata" --disablerepo \* --enablerepo "$repoid" --qf '%{sourcerpm}' "$@" | sed 's|-[^-]*-[^-]*$||' \
    | koschei-admin edit-group "$group" --content-from-file - --append
