#!/bin/bash
# we have no $REPOCOP_PKG_SRC_NAME yet, so try to guess it from the source rpm string
srcname=
if [ "${REPOCOP_PKG_SOURCEPKG%-$REPOCOP_PKG_RELEASE}" != "$REPOCOP_PKG_SOURCEPKG" ]; then
    srcname=${REPOCOP_PKG_SOURCEPKG%-$REPOCOP_PKG_RELEASE}
    if [ "${srcname%-$REPOCOP_PKG_VERSION}" != "$srcname" ]; then
        srcname=${srcname%-$REPOCOP_PKG_VERSION}
    else
        srcname=${srcname%[-0-9.]*}
    fi
fi
################
STATUS=ok
declare -a MESSAGE
i=0
for file in `grep -s -r -l $srcname-buildroot $REPOCOP_PKG_ROOT/`; do
    if [ ${file%.elc} == "$i" ]; then
        [ "$STATUS" = "fail" ] || MESSAGE[i++]="found paths to buildroot: "
    	STATUS=fail
	MESSAGE[i++]=`grep -s $srcname-buildroot $file`
    fi
done
exec repocop-test-$STATUS "${MESSAGE[@]}"
