#! /bin/sh

PROJECT=${PWD##*/}

for PACKAGE in * ; do
    osc results $PACKAGE |
	while read DISTRO ARCH STATUS ; do
	    if test "${STATUS%: *}" = "failed" ; then
		cd $PACKAGE
		osc log $DISTRO $ARCH | if grep\
		    '\(Wrote: /usr/src/packages/SRPMS/\|did not create a logfile\|Unable to connect to xend\|Terminated.*perl -e .*syscall\|Error: VM name.*already exists\|Error: Device .* could not be connected\|Hotplug scripts not working\|Backend device not found\)' ; then
			echo "Triggering $DISTRO $ARCH to rebuild"
			osc rebuildpac $PROJECT $PACKAGE $DISTRO $ARCH
		    fi
		cd ..
	    fi
	done
done
