#!/bin/sh 

# check arguments
if [ -z "$*" ]; then
	echo "Usage: `basename $0` name.spec"
	exit 1
fi

SPEC=$1

BUILDROOT=`rpm -E '%{_tmppath}'`/`basename $0`-root

# Remove BUILDROOT
if [ -e $BUILDROOT ]; then
	rm -rf $BUILDROOT
fi

# Output files section
if rpmbuild -bi --buildroot=$BUILDROOT $SPEC >/dev/null 2>&1 ;then
	echo '%files'
	echo '%defattr(-,root,root)'
	cd $BUILDROOT && find . -type f | sed -e 's/^\.//'
	#cd $BUILDROOT && find . -type f | sed -e 's/^\.//' | sed -e 's/\/[^\/]*$/\/\*/' | uniq
fi
