#!/bin/bash
# loop builds packages as needed
set -x

LIST="${1}"

if [ -z "${LIST}" ]; then
	echo "No list?"
	exit 2
fi

mockBuild() {
	package="${1}"
	mock -r /opt/build/cfg/riscv.cfg ${package} --nocheck
}

for x in $(cat $LIST) ; do 
	mockBuild "${x}"
	_ret=$?

	if [ "$_ret" -eq 0 ]; then
		cp /var/lib/mock/rl-10-lookahead-riscv64/result/*.rpm /opt/build/repo/
	else
		printf "${x}\n" >> /opt/build/cfg/log/loop-failures.log
	fi
done
