#!/bin/bash
########################################################################
# populate_SOURCES
#
# Copy tarfiles and other build paraphernalia into rpmbuild SOURCES area
#
# 2007/08/16 CHG for the Gratia project.
########################################################################

rpmbuild_top=/usr/src/redhat
dCache_dir=./build/dCache

function usage() {
  echo "usage: ${0##*/} -h" 1>&2
  echo "       ${0##*/} [-r <rpmbuild-top>] [tarfiles]" 1>&2
  exit 1
}

while getopts :hr: OPT; do
    case $OPT in
	h)
	    usage
	    ;;
	r)
	    rpmbuild_top="$OPTARG"
	    ;;
	*)
	    usage
    esac
done
shift $[ OPTIND - 1 ]

if [[ -z "$1" ]]; then
  set -- *.tar.bz2
fi

if [[ ! -w "$rpmbuild_top/SOURCES" ]]; then
  echo "$rpmbuild_top/SOURCES not writable" 1>&2
  usage
fi

cp -pv "$dCache_dir/"*.{tar.gz,tar.bz2,egg} "$urCollector_dir/"* "$@" "$rpmbuild_top/SOURCES" 2>/dev/null

exit 0
