#!/bin/bash

set -e

PACKAGES=(
# pkg1
# pkg2
# pkg3
)
RELEASE_TAG="f43-updates"

for pkg in "${PACKAGES[@]}"; do

    # Get the latest tagged build's NVR for the package.
    echo "Finding latest tagged build in '$RELEASE_TAG'..."
    latest_nvr=$(koji --quiet list-tagged --latest "$RELEASE_TAG" "$pkg" | awk '{print $1}')

    # Get the source URL to build from.
    source_url=$(koji buildinfo "$latest_nvr" | grep '^Source:' | awk '{print $2}')
    echo "Found source URL for $latest_nvr: $source_url"

    if [[ -z "$source_url" ]]; then
        echo "Could not find source URL for $latest_nvr. Skipping."
        continue
    fi
done
