#!/bin/bash
# builds a single file without tests enabled
set -x

PKG="${1}"

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

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

mockBuild "${PKG}" ${@:2}
_ret=$?

if [ "$_ret" -eq 0 ]; then
        cp /var/lib/mock/rl-10-lookahead-riscv64/result/*.rpm /opt/build/repo/
        scp /opt/build/repo/*.riscv64.rpm box:/var/www/html/pub/riscv/bootstrap
        if ls /opt/build/repo/*.rpm | grep -q noarch.rpm; then
                for x in /opt/build/repo/*.noarch.rpm ; do echo "${x}" >> /opt/build/cfg/log/noarches.log ; done
		scp /opt/build/repo/*.noarch.rpm box:/var/www/html/pub/riscv/bootstrap
        fi

        ssh -q box "/bin/bash /home/pulp/bin/cr_bootstrap"

        echo "Cleaning up /opt/build/repo"
        rm -rf /opt/build/repo/*
else
        printf "${1}\n" >> /opt/build/cfg/log/loop-failures.log
fi
