#!/bin/bash

pkg="${1}"
branch="${2:-r10s}"
dist="${3:-el10}"
rhel="${4:-10}"

quickclone(){
	NAME="${1}"
	BRANCH="${2}"
	git clone https://git.rockylinux.org/staging/rpms/${NAME}.git -b ${BRANCH}
}

pullsource(){
	srpmproc fetch --cdn-url https://sources.build.resf.org
	return $?
}

pushd /opt/build/src || exit 1
quickclone ${pkg} ${branch}
pushd ${pkg} || exit 1
pullsource
if [ "$?" -ne 0 ]; then
	echo "There was an issue pulling sources for this package."
fi

rpmbuild -bs SPECS/${pkg}.spec --define "_topdir $PWD" --define "dist .${dist}" --define "rhel ${rhel}" --undefine fedora
popd || exit 1
popd || exit 1
