#!/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
    filename=`echo $file | sed -e "s,$REPOCOP_PKG_ROOT,,g"`
    case $file in
	*.elc|*.pyc|*.pyo|*/environment.pickle) : exclude them ;;
	*)
        [ "$STATUS" = "fail" ] || MESSAGE[i++]="found paths to buildroot: "
    	STATUS=fail
	MESSAGE[i++]="$filename: "`grep -s $srcname-buildroot $file | sed -e "s,$REPOCOP_PKG_ROOT,,g"`
	;;
    esac
done
exec repocop-test-$STATUS "${MESSAGE[@]}"
